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_Update_loop_ccm(void *args
);
197 static int EVP_Digest_loop(void *args
);
198 #ifndef OPENSSL_NO_RSA
199 static int RSA_sign_loop(void *args
);
200 static int RSA_verify_loop(void *args
);
202 #ifndef OPENSSL_NO_DSA
203 static int DSA_sign_loop(void *args
);
204 static int DSA_verify_loop(void *args
);
206 #ifndef OPENSSL_NO_EC
207 static int ECDSA_sign_loop(void *args
);
208 static int ECDSA_verify_loop(void *args
);
210 static int run_benchmark(int async_jobs
, int (*loop_function
) (void *),
211 loopargs_t
* loopargs
);
213 static double Time_F(int s
);
214 static void print_message(const char *s
, long num
, int length
);
215 static void pkey_print_message(const char *str
, const char *str2
,
216 long num
, int bits
, int sec
);
217 static void print_result(int alg
, int run_no
, int count
, double time_used
);
219 static int do_multi(int multi
);
222 static const char *names
[ALGOR_NUM
] = {
223 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
224 "des cbc", "des ede3", "idea cbc", "seed cbc",
225 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
226 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
227 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
228 "evp", "sha256", "sha512", "whirlpool",
229 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
232 static double results
[ALGOR_NUM
][SIZE_NUM
];
234 static const int lengths
[SIZE_NUM
] = {
235 16, 64, 256, 1024, 8 * 1024, 16 * 1024
238 #ifndef OPENSSL_NO_RSA
239 static double rsa_results
[RSA_NUM
][2];
241 #ifndef OPENSSL_NO_DSA
242 static double dsa_results
[DSA_NUM
][2];
244 #ifndef OPENSSL_NO_EC
245 static double ecdsa_results
[EC_NUM
][2];
246 static double ecdh_results
[EC_NUM
][1];
250 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
251 # define SIGRETTYPE void
253 # define SIGRETTYPE int
256 static SIGRETTYPE
sig_done(int sig
);
257 static SIGRETTYPE
sig_done(int sig
)
259 signal(SIGALRM
, sig_done
);
269 # if !defined(SIGALRM)
272 static unsigned int lapse
;
273 static volatile unsigned int schlock
;
274 static void alarm_win32(unsigned int secs
)
279 # define alarm alarm_win32
281 static DWORD WINAPI
sleepy(VOID
* arg
)
289 static double Time_F(int s
)
296 thr
= CreateThread(NULL
, 4096, sleepy
, NULL
, 0, NULL
);
298 DWORD err
= GetLastError();
299 BIO_printf(bio_err
, "unable to CreateThread (%lu)", err
);
303 Sleep(0); /* scheduler spinlock */
304 ret
= app_tminterval(s
, usertime
);
306 ret
= app_tminterval(s
, usertime
);
308 TerminateThread(thr
, 0);
316 static double Time_F(int s
)
318 double ret
= app_tminterval(s
, usertime
);
325 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
);
327 static int found(const char *name
, const OPT_PAIR
*pairs
, int *result
)
329 for (; pairs
->name
; pairs
++)
330 if (strcmp(name
, pairs
->name
) == 0) {
331 *result
= pairs
->retval
;
337 typedef enum OPTION_choice
{
338 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
339 OPT_ELAPSED
, OPT_EVP
, OPT_DECRYPT
, OPT_ENGINE
, OPT_MULTI
,
340 OPT_MR
, OPT_MB
, OPT_MISALIGN
, OPT_ASYNCJOBS
, OPT_R_ENUM
343 const OPTIONS speed_options
[] = {
344 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] ciphers...\n"},
345 {OPT_HELP_STR
, 1, '-', "Valid options are:\n"},
346 {"help", OPT_HELP
, '-', "Display this summary"},
347 {"evp", OPT_EVP
, 's', "Use specified EVP cipher"},
348 {"decrypt", OPT_DECRYPT
, '-',
349 "Time decryption instead of encryption (only EVP)"},
350 {"mr", OPT_MR
, '-', "Produce machine readable output"},
352 "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"},
353 {"misalign", OPT_MISALIGN
, 'n', "Amount to mis-align buffers"},
354 {"elapsed", OPT_ELAPSED
, '-',
355 "Measure time in real time instead of CPU user time"},
357 {"multi", OPT_MULTI
, 'p', "Run benchmarks in parallel"},
359 #ifndef OPENSSL_NO_ASYNC
360 {"async_jobs", OPT_ASYNCJOBS
, 'p',
361 "Enable async mode and start pnum jobs"},
364 #ifndef OPENSSL_NO_ENGINE
365 {"engine", OPT_ENGINE
, 's', "Use engine, possibly a hardware device"},
380 #define D_CBC_IDEA 10
381 #define D_CBC_SEED 11
385 #define D_CBC_CAST 15
386 #define D_CBC_128_AES 16
387 #define D_CBC_192_AES 17
388 #define D_CBC_256_AES 18
389 #define D_CBC_128_CML 19
390 #define D_CBC_192_CML 20
391 #define D_CBC_256_CML 21
395 #define D_WHIRLPOOL 25
396 #define D_IGE_128_AES 26
397 #define D_IGE_192_AES 27
398 #define D_IGE_256_AES 28
400 static OPT_PAIR doit_choices
[] = {
401 #ifndef OPENSSL_NO_MD2
404 #ifndef OPENSSL_NO_MDC2
407 #ifndef OPENSSL_NO_MD4
410 #ifndef OPENSSL_NO_MD5
415 {"sha256", D_SHA256
},
416 {"sha512", D_SHA512
},
417 #ifndef OPENSSL_NO_WHIRLPOOL
418 {"whirlpool", D_WHIRLPOOL
},
420 #ifndef OPENSSL_NO_RMD160
421 {"ripemd", D_RMD160
},
422 {"rmd160", D_RMD160
},
423 {"ripemd160", D_RMD160
},
425 #ifndef OPENSSL_NO_RC4
428 #ifndef OPENSSL_NO_DES
429 {"des-cbc", D_CBC_DES
},
430 {"des-ede3", D_EDE3_DES
},
432 {"aes-128-cbc", D_CBC_128_AES
},
433 {"aes-192-cbc", D_CBC_192_AES
},
434 {"aes-256-cbc", D_CBC_256_AES
},
435 {"aes-128-ige", D_IGE_128_AES
},
436 {"aes-192-ige", D_IGE_192_AES
},
437 {"aes-256-ige", D_IGE_256_AES
},
438 #ifndef OPENSSL_NO_RC2
439 {"rc2-cbc", D_CBC_RC2
},
442 #ifndef OPENSSL_NO_RC5
443 {"rc5-cbc", D_CBC_RC5
},
446 #ifndef OPENSSL_NO_IDEA
447 {"idea-cbc", D_CBC_IDEA
},
448 {"idea", D_CBC_IDEA
},
450 #ifndef OPENSSL_NO_SEED
451 {"seed-cbc", D_CBC_SEED
},
452 {"seed", D_CBC_SEED
},
454 #ifndef OPENSSL_NO_BF
455 {"bf-cbc", D_CBC_BF
},
456 {"blowfish", D_CBC_BF
},
459 #ifndef OPENSSL_NO_CAST
460 {"cast-cbc", D_CBC_CAST
},
461 {"cast", D_CBC_CAST
},
462 {"cast5", D_CBC_CAST
},
468 #ifndef OPENSSL_NO_DSA
470 # define R_DSA_1024 1
471 # define R_DSA_2048 2
472 static OPT_PAIR dsa_choices
[] = {
473 {"dsa512", R_DSA_512
},
474 {"dsa1024", R_DSA_1024
},
475 {"dsa2048", R_DSA_2048
},
486 #define R_RSA_15360 6
487 static OPT_PAIR rsa_choices
[] = {
488 {"rsa512", R_RSA_512
},
489 {"rsa1024", R_RSA_1024
},
490 {"rsa2048", R_RSA_2048
},
491 {"rsa3072", R_RSA_3072
},
492 {"rsa4096", R_RSA_4096
},
493 {"rsa7680", R_RSA_7680
},
494 {"rsa15360", R_RSA_15360
},
514 #define R_EC_X25519 16
515 #ifndef OPENSSL_NO_EC
516 static OPT_PAIR ecdsa_choices
[] = {
517 {"ecdsap160", R_EC_P160
},
518 {"ecdsap192", R_EC_P192
},
519 {"ecdsap224", R_EC_P224
},
520 {"ecdsap256", R_EC_P256
},
521 {"ecdsap384", R_EC_P384
},
522 {"ecdsap521", R_EC_P521
},
523 {"ecdsak163", R_EC_K163
},
524 {"ecdsak233", R_EC_K233
},
525 {"ecdsak283", R_EC_K283
},
526 {"ecdsak409", R_EC_K409
},
527 {"ecdsak571", R_EC_K571
},
528 {"ecdsab163", R_EC_B163
},
529 {"ecdsab233", R_EC_B233
},
530 {"ecdsab283", R_EC_B283
},
531 {"ecdsab409", R_EC_B409
},
532 {"ecdsab571", R_EC_B571
},
536 static OPT_PAIR ecdh_choices
[] = {
537 {"ecdhp160", R_EC_P160
},
538 {"ecdhp192", R_EC_P192
},
539 {"ecdhp224", R_EC_P224
},
540 {"ecdhp256", R_EC_P256
},
541 {"ecdhp384", R_EC_P384
},
542 {"ecdhp521", R_EC_P521
},
543 {"ecdhk163", R_EC_K163
},
544 {"ecdhk233", R_EC_K233
},
545 {"ecdhk283", R_EC_K283
},
546 {"ecdhk409", R_EC_K409
},
547 {"ecdhk571", R_EC_K571
},
548 {"ecdhb163", R_EC_B163
},
549 {"ecdhb233", R_EC_B233
},
550 {"ecdhb283", R_EC_B283
},
551 {"ecdhb409", R_EC_B409
},
552 {"ecdhb571", R_EC_B571
},
553 {"ecdhx25519", R_EC_X25519
},
559 # define COND(d) (count < (d))
560 # define COUNT(d) (d)
562 # define COND(unused_cond) (run && count<0x7fffffff)
563 # define COUNT(d) (count)
568 /* Nb of iterations to do per algorithm and key-size */
569 static long c
[ALGOR_NUM
][SIZE_NUM
];
571 #ifndef OPENSSL_NO_MD2
572 static int EVP_Digest_MD2_loop(void *args
)
574 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
575 unsigned char *buf
= tempargs
->buf
;
576 unsigned char md2
[MD2_DIGEST_LENGTH
];
579 for (count
= 0; COND(c
[D_MD2
][testnum
]); count
++) {
580 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md2
, NULL
, EVP_md2(),
588 #ifndef OPENSSL_NO_MDC2
589 static int EVP_Digest_MDC2_loop(void *args
)
591 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
592 unsigned char *buf
= tempargs
->buf
;
593 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
596 for (count
= 0; COND(c
[D_MDC2
][testnum
]); count
++) {
597 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], mdc2
, NULL
, EVP_mdc2(),
605 #ifndef OPENSSL_NO_MD4
606 static int EVP_Digest_MD4_loop(void *args
)
608 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
609 unsigned char *buf
= tempargs
->buf
;
610 unsigned char md4
[MD4_DIGEST_LENGTH
];
613 for (count
= 0; COND(c
[D_MD4
][testnum
]); count
++) {
614 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md4
, NULL
, EVP_md4(),
622 #ifndef OPENSSL_NO_MD5
623 static int MD5_loop(void *args
)
625 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
626 unsigned char *buf
= tempargs
->buf
;
627 unsigned char md5
[MD5_DIGEST_LENGTH
];
629 for (count
= 0; COND(c
[D_MD5
][testnum
]); count
++)
630 MD5(buf
, lengths
[testnum
], md5
);
634 static int HMAC_loop(void *args
)
636 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
637 unsigned char *buf
= tempargs
->buf
;
638 HMAC_CTX
*hctx
= tempargs
->hctx
;
639 unsigned char hmac
[MD5_DIGEST_LENGTH
];
642 for (count
= 0; COND(c
[D_HMAC
][testnum
]); count
++) {
643 HMAC_Init_ex(hctx
, NULL
, 0, NULL
, NULL
);
644 HMAC_Update(hctx
, buf
, lengths
[testnum
]);
645 HMAC_Final(hctx
, hmac
, NULL
);
651 static int SHA1_loop(void *args
)
653 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
654 unsigned char *buf
= tempargs
->buf
;
655 unsigned char sha
[SHA_DIGEST_LENGTH
];
657 for (count
= 0; COND(c
[D_SHA1
][testnum
]); count
++)
658 SHA1(buf
, lengths
[testnum
], sha
);
662 static int SHA256_loop(void *args
)
664 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
665 unsigned char *buf
= tempargs
->buf
;
666 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
668 for (count
= 0; COND(c
[D_SHA256
][testnum
]); count
++)
669 SHA256(buf
, lengths
[testnum
], sha256
);
673 static int SHA512_loop(void *args
)
675 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
676 unsigned char *buf
= tempargs
->buf
;
677 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
679 for (count
= 0; COND(c
[D_SHA512
][testnum
]); count
++)
680 SHA512(buf
, lengths
[testnum
], sha512
);
684 #ifndef OPENSSL_NO_WHIRLPOOL
685 static int WHIRLPOOL_loop(void *args
)
687 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
688 unsigned char *buf
= tempargs
->buf
;
689 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
691 for (count
= 0; COND(c
[D_WHIRLPOOL
][testnum
]); count
++)
692 WHIRLPOOL(buf
, lengths
[testnum
], whirlpool
);
697 #ifndef OPENSSL_NO_RMD160
698 static int EVP_Digest_RMD160_loop(void *args
)
700 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
701 unsigned char *buf
= tempargs
->buf
;
702 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
704 for (count
= 0; COND(c
[D_RMD160
][testnum
]); count
++) {
705 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], &(rmd160
[0]),
706 NULL
, EVP_ripemd160(), NULL
))
713 #ifndef OPENSSL_NO_RC4
714 static RC4_KEY rc4_ks
;
715 static int RC4_loop(void *args
)
717 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
718 unsigned char *buf
= tempargs
->buf
;
720 for (count
= 0; COND(c
[D_RC4
][testnum
]); count
++)
721 RC4(&rc4_ks
, (size_t)lengths
[testnum
], buf
, buf
);
726 #ifndef OPENSSL_NO_DES
727 static unsigned char DES_iv
[8];
728 static DES_key_schedule sch
;
729 static DES_key_schedule sch2
;
730 static DES_key_schedule sch3
;
731 static int DES_ncbc_encrypt_loop(void *args
)
733 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
734 unsigned char *buf
= tempargs
->buf
;
736 for (count
= 0; COND(c
[D_CBC_DES
][testnum
]); count
++)
737 DES_ncbc_encrypt(buf
, buf
, lengths
[testnum
], &sch
,
738 &DES_iv
, DES_ENCRYPT
);
742 static int DES_ede3_cbc_encrypt_loop(void *args
)
744 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
745 unsigned char *buf
= tempargs
->buf
;
747 for (count
= 0; COND(c
[D_EDE3_DES
][testnum
]); count
++)
748 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[testnum
],
749 &sch
, &sch2
, &sch3
, &DES_iv
, DES_ENCRYPT
);
754 #define MAX_BLOCK_SIZE 128
756 static unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
757 static AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
758 static int AES_cbc_128_encrypt_loop(void *args
)
760 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
761 unsigned char *buf
= tempargs
->buf
;
763 for (count
= 0; COND(c
[D_CBC_128_AES
][testnum
]); count
++)
764 AES_cbc_encrypt(buf
, buf
,
765 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
769 static int AES_cbc_192_encrypt_loop(void *args
)
771 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
772 unsigned char *buf
= tempargs
->buf
;
774 for (count
= 0; COND(c
[D_CBC_192_AES
][testnum
]); count
++)
775 AES_cbc_encrypt(buf
, buf
,
776 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
780 static int AES_cbc_256_encrypt_loop(void *args
)
782 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
783 unsigned char *buf
= tempargs
->buf
;
785 for (count
= 0; COND(c
[D_CBC_256_AES
][testnum
]); count
++)
786 AES_cbc_encrypt(buf
, buf
,
787 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
791 static int AES_ige_128_encrypt_loop(void *args
)
793 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
794 unsigned char *buf
= tempargs
->buf
;
795 unsigned char *buf2
= tempargs
->buf2
;
797 for (count
= 0; COND(c
[D_IGE_128_AES
][testnum
]); count
++)
798 AES_ige_encrypt(buf
, buf2
,
799 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
803 static int AES_ige_192_encrypt_loop(void *args
)
805 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
806 unsigned char *buf
= tempargs
->buf
;
807 unsigned char *buf2
= tempargs
->buf2
;
809 for (count
= 0; COND(c
[D_IGE_192_AES
][testnum
]); count
++)
810 AES_ige_encrypt(buf
, buf2
,
811 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
815 static int AES_ige_256_encrypt_loop(void *args
)
817 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
818 unsigned char *buf
= tempargs
->buf
;
819 unsigned char *buf2
= tempargs
->buf2
;
821 for (count
= 0; COND(c
[D_IGE_256_AES
][testnum
]); count
++)
822 AES_ige_encrypt(buf
, buf2
,
823 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
827 static int CRYPTO_gcm128_aad_loop(void *args
)
829 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
830 unsigned char *buf
= tempargs
->buf
;
831 GCM128_CONTEXT
*gcm_ctx
= tempargs
->gcm_ctx
;
833 for (count
= 0; COND(c
[D_GHASH
][testnum
]); count
++)
834 CRYPTO_gcm128_aad(gcm_ctx
, buf
, lengths
[testnum
]);
838 static long save_count
= 0;
839 static int decrypt
= 0;
840 static int EVP_Update_loop(void *args
)
842 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
843 unsigned char *buf
= tempargs
->buf
;
844 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
847 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
850 for (count
= 0; COND(nb_iter
); count
++)
851 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
853 for (count
= 0; COND(nb_iter
); count
++)
854 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
856 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
858 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
862 * CCM does not support streaming. For the purpose of performance measurement,
863 * each message is encrypted using the same (key,iv)-pair. Do not use this
864 * code in your application.
866 static int EVP_Update_loop_ccm(void *args
)
868 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
869 unsigned char *buf
= tempargs
->buf
;
870 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
872 unsigned char tag
[12];
874 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
877 for (count
= 0; COND(nb_iter
); count
++) {
878 EVP_DecryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
879 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_TAG
, sizeof(tag
), tag
);
880 EVP_DecryptUpdate(ctx
, NULL
, &outl
, NULL
, lengths
[testnum
]);
881 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
882 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
885 for (count
= 0; COND(nb_iter
); count
++) {
886 EVP_EncryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
887 EVP_EncryptUpdate(ctx
, NULL
, &outl
, NULL
, lengths
[testnum
]);
888 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
889 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
895 static const EVP_MD
*evp_md
= NULL
;
896 static int EVP_Digest_loop(void *args
)
898 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
899 unsigned char *buf
= tempargs
->buf
;
900 unsigned char md
[EVP_MAX_MD_SIZE
];
903 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
906 for (count
= 0; COND(nb_iter
); count
++) {
907 if (!EVP_Digest(buf
, lengths
[testnum
], md
, NULL
, evp_md
, NULL
))
913 #ifndef OPENSSL_NO_RSA
914 static long rsa_c
[RSA_NUM
][2]; /* # RSA iteration test */
916 static int RSA_sign_loop(void *args
)
918 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
919 unsigned char *buf
= tempargs
->buf
;
920 unsigned char *buf2
= tempargs
->buf2
;
921 unsigned int *rsa_num
= &tempargs
->siglen
;
922 RSA
**rsa_key
= tempargs
->rsa_key
;
924 for (count
= 0; COND(rsa_c
[testnum
][0]); count
++) {
925 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
927 BIO_printf(bio_err
, "RSA sign failure\n");
928 ERR_print_errors(bio_err
);
936 static int RSA_verify_loop(void *args
)
938 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
939 unsigned char *buf
= tempargs
->buf
;
940 unsigned char *buf2
= tempargs
->buf2
;
941 unsigned int rsa_num
= tempargs
->siglen
;
942 RSA
**rsa_key
= tempargs
->rsa_key
;
944 for (count
= 0; COND(rsa_c
[testnum
][1]); count
++) {
946 RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
948 BIO_printf(bio_err
, "RSA verify failure\n");
949 ERR_print_errors(bio_err
);
958 #ifndef OPENSSL_NO_DSA
959 static long dsa_c
[DSA_NUM
][2];
960 static int DSA_sign_loop(void *args
)
962 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
963 unsigned char *buf
= tempargs
->buf
;
964 unsigned char *buf2
= tempargs
->buf2
;
965 DSA
**dsa_key
= tempargs
->dsa_key
;
966 unsigned int *siglen
= &tempargs
->siglen
;
968 for (count
= 0; COND(dsa_c
[testnum
][0]); count
++) {
969 ret
= DSA_sign(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
971 BIO_printf(bio_err
, "DSA sign failure\n");
972 ERR_print_errors(bio_err
);
980 static int DSA_verify_loop(void *args
)
982 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
983 unsigned char *buf
= tempargs
->buf
;
984 unsigned char *buf2
= tempargs
->buf2
;
985 DSA
**dsa_key
= tempargs
->dsa_key
;
986 unsigned int siglen
= tempargs
->siglen
;
988 for (count
= 0; COND(dsa_c
[testnum
][1]); count
++) {
989 ret
= DSA_verify(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
991 BIO_printf(bio_err
, "DSA verify failure\n");
992 ERR_print_errors(bio_err
);
1001 #ifndef OPENSSL_NO_EC
1002 static long ecdsa_c
[EC_NUM
][2];
1003 static int ECDSA_sign_loop(void *args
)
1005 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1006 unsigned char *buf
= tempargs
->buf
;
1007 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1008 unsigned char *ecdsasig
= tempargs
->buf2
;
1009 unsigned int *ecdsasiglen
= &tempargs
->siglen
;
1011 for (count
= 0; COND(ecdsa_c
[testnum
][0]); count
++) {
1012 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1014 BIO_printf(bio_err
, "ECDSA sign failure\n");
1015 ERR_print_errors(bio_err
);
1023 static int ECDSA_verify_loop(void *args
)
1025 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1026 unsigned char *buf
= tempargs
->buf
;
1027 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1028 unsigned char *ecdsasig
= tempargs
->buf2
;
1029 unsigned int ecdsasiglen
= tempargs
->siglen
;
1031 for (count
= 0; COND(ecdsa_c
[testnum
][1]); count
++) {
1032 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1034 BIO_printf(bio_err
, "ECDSA verify failure\n");
1035 ERR_print_errors(bio_err
);
1043 /* ******************************************************************** */
1044 static long ecdh_c
[EC_NUM
][1];
1046 static int ECDH_EVP_derive_key_loop(void *args
)
1048 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1049 EVP_PKEY_CTX
*ctx
= tempargs
->ecdh_ctx
[testnum
];
1050 unsigned char *derived_secret
= tempargs
->secret_a
;
1052 size_t *outlen
= &(tempargs
->outlen
[testnum
]);
1054 for (count
= 0; COND(ecdh_c
[testnum
][0]); count
++)
1055 EVP_PKEY_derive(ctx
, derived_secret
, outlen
);
1060 #endif /* OPENSSL_NO_EC */
1062 static int run_benchmark(int async_jobs
,
1063 int (*loop_function
) (void *), loopargs_t
* loopargs
)
1065 int job_op_count
= 0;
1066 int total_op_count
= 0;
1067 int num_inprogress
= 0;
1068 int error
= 0, i
= 0, ret
= 0;
1069 OSSL_ASYNC_FD job_fd
= 0;
1070 size_t num_job_fds
= 0;
1074 if (async_jobs
== 0) {
1075 return loop_function((void *)&loopargs
);
1078 for (i
= 0; i
< async_jobs
&& !error
; i
++) {
1079 loopargs_t
*looparg_item
= loopargs
+ i
;
1081 /* Copy pointer content (looparg_t item address) into async context */
1082 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
, loopargs
[i
].wait_ctx
,
1083 &job_op_count
, loop_function
,
1084 (void *)&looparg_item
, sizeof(looparg_item
));
1090 if (job_op_count
== -1) {
1093 total_op_count
+= job_op_count
;
1098 BIO_printf(bio_err
, "Failure in the job\n");
1099 ERR_print_errors(bio_err
);
1105 while (num_inprogress
> 0) {
1106 #if defined(OPENSSL_SYS_WINDOWS)
1108 #elif defined(OPENSSL_SYS_UNIX)
1109 int select_result
= 0;
1110 OSSL_ASYNC_FD max_fd
= 0;
1113 FD_ZERO(&waitfdset
);
1115 for (i
= 0; i
< async_jobs
&& num_inprogress
> 0; i
++) {
1116 if (loopargs
[i
].inprogress_job
== NULL
)
1119 if (!ASYNC_WAIT_CTX_get_all_fds
1120 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1121 || num_job_fds
> 1) {
1122 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1123 ERR_print_errors(bio_err
);
1127 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1129 FD_SET(job_fd
, &waitfdset
);
1130 if (job_fd
> max_fd
)
1134 if (max_fd
>= (OSSL_ASYNC_FD
)FD_SETSIZE
) {
1136 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1137 "Decrease the value of async_jobs\n",
1138 max_fd
, FD_SETSIZE
);
1139 ERR_print_errors(bio_err
);
1144 select_result
= select(max_fd
+ 1, &waitfdset
, NULL
, NULL
, NULL
);
1145 if (select_result
== -1 && errno
== EINTR
)
1148 if (select_result
== -1) {
1149 BIO_printf(bio_err
, "Failure in the select\n");
1150 ERR_print_errors(bio_err
);
1155 if (select_result
== 0)
1159 for (i
= 0; i
< async_jobs
; i
++) {
1160 if (loopargs
[i
].inprogress_job
== NULL
)
1163 if (!ASYNC_WAIT_CTX_get_all_fds
1164 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1165 || num_job_fds
> 1) {
1166 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1167 ERR_print_errors(bio_err
);
1171 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1174 #if defined(OPENSSL_SYS_UNIX)
1175 if (num_job_fds
== 1 && !FD_ISSET(job_fd
, &waitfdset
))
1177 #elif defined(OPENSSL_SYS_WINDOWS)
1178 if (num_job_fds
== 1
1179 && !PeekNamedPipe(job_fd
, NULL
, 0, NULL
, &avail
, NULL
)
1184 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
,
1185 loopargs
[i
].wait_ctx
, &job_op_count
,
1186 loop_function
, (void *)(loopargs
+ i
),
1187 sizeof(loopargs_t
));
1192 if (job_op_count
== -1) {
1195 total_op_count
+= job_op_count
;
1198 loopargs
[i
].inprogress_job
= NULL
;
1203 loopargs
[i
].inprogress_job
= NULL
;
1204 BIO_printf(bio_err
, "Failure in the job\n");
1205 ERR_print_errors(bio_err
);
1212 return error
? -1 : total_op_count
;
1215 int speed_main(int argc
, char **argv
)
1218 int (*loopfunc
)(void *args
);
1219 loopargs_t
*loopargs
= NULL
;
1221 int loopargs_len
= 0;
1223 const char *engine_id
= NULL
;
1224 const EVP_CIPHER
*evp_cipher
= NULL
;
1227 int multiblock
= 0, pr_header
= 0;
1228 int doit
[ALGOR_NUM
] = { 0 };
1229 int ret
= 1, i
, k
, misalign
= 0;
1234 unsigned int async_jobs
= 0;
1235 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1236 || !defined(OPENSSL_NO_EC)
1240 /* What follows are the buffers and key material. */
1241 #ifndef OPENSSL_NO_RC5
1244 #ifndef OPENSSL_NO_RC2
1247 #ifndef OPENSSL_NO_IDEA
1248 IDEA_KEY_SCHEDULE idea_ks
;
1250 #ifndef OPENSSL_NO_SEED
1251 SEED_KEY_SCHEDULE seed_ks
;
1253 #ifndef OPENSSL_NO_BF
1256 #ifndef OPENSSL_NO_CAST
1259 static const unsigned char key16
[16] = {
1260 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1261 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1263 static const unsigned char key24
[24] = {
1264 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1265 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1266 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1268 static const unsigned char key32
[32] = {
1269 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1270 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1271 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1272 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1274 #ifndef OPENSSL_NO_CAMELLIA
1275 static const unsigned char ckey24
[24] = {
1276 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1277 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1278 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1280 static const unsigned char ckey32
[32] = {
1281 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1282 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1283 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1284 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1286 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
1288 #ifndef OPENSSL_NO_DES
1289 static DES_cblock key
= {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1292 static DES_cblock key2
= {
1293 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1295 static DES_cblock key3
= {
1296 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1299 #ifndef OPENSSL_NO_RSA
1300 static const unsigned int rsa_bits
[RSA_NUM
] = {
1301 512, 1024, 2048, 3072, 4096, 7680, 15360
1303 static const unsigned char *rsa_data
[RSA_NUM
] = {
1304 test512
, test1024
, test2048
, test3072
, test4096
, test7680
, test15360
1306 static const int rsa_data_length
[RSA_NUM
] = {
1307 sizeof(test512
), sizeof(test1024
),
1308 sizeof(test2048
), sizeof(test3072
),
1309 sizeof(test4096
), sizeof(test7680
),
1312 int rsa_doit
[RSA_NUM
] = { 0 };
1314 #ifndef OPENSSL_NO_DSA
1315 static const unsigned int dsa_bits
[DSA_NUM
] = { 512, 1024, 2048 };
1316 int dsa_doit
[DSA_NUM
] = { 0 };
1318 #ifndef OPENSSL_NO_EC
1320 * We only test over the following curves as they are representative, To
1321 * add tests over more curves, simply add the curve NID and curve name to
1322 * the following arrays and increase the EC_NUM value accordingly.
1324 static const unsigned int test_curves
[EC_NUM
] = {
1326 NID_secp160r1
, NID_X9_62_prime192v1
, NID_secp224r1
,
1327 NID_X9_62_prime256v1
, NID_secp384r1
, NID_secp521r1
,
1329 NID_sect163k1
, NID_sect233k1
, NID_sect283k1
,
1330 NID_sect409k1
, NID_sect571k1
, NID_sect163r2
,
1331 NID_sect233r1
, NID_sect283r1
, NID_sect409r1
,
1336 static const char *test_curves_names
[EC_NUM
] = {
1338 "secp160r1", "nistp192", "nistp224",
1339 "nistp256", "nistp384", "nistp521",
1341 "nistk163", "nistk233", "nistk283",
1342 "nistk409", "nistk571", "nistb163",
1343 "nistb233", "nistb283", "nistb409",
1348 static const int test_curves_bits
[EC_NUM
] = {
1354 571, 253 /* X25519 */
1357 int ecdsa_doit
[EC_NUM
] = { 0 };
1358 int ecdh_doit
[EC_NUM
] = { 0 };
1359 #endif /* ndef OPENSSL_NO_EC */
1361 prog
= opt_init(argc
, argv
, speed_options
);
1362 while ((o
= opt_next()) != OPT_EOF
) {
1367 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
1370 opt_help(speed_options
);
1378 evp_cipher
= EVP_get_cipherbyname(opt_arg());
1379 if (evp_cipher
== NULL
)
1380 evp_md
= EVP_get_digestbyname(opt_arg());
1381 if (evp_cipher
== NULL
&& evp_md
== NULL
) {
1383 "%s: %s is an unknown cipher or digest\n",
1394 * In a forked execution, an engine might need to be
1395 * initialised by each child process, not by the parent.
1396 * So store the name here and run setup_engine() later on.
1398 engine_id
= opt_arg();
1402 multi
= atoi(opt_arg());
1406 #ifndef OPENSSL_NO_ASYNC
1407 async_jobs
= atoi(opt_arg());
1408 if (!ASYNC_is_capable()) {
1410 "%s: async_jobs specified but async not supported\n",
1414 if (async_jobs
> 99999) {
1416 "%s: too many async_jobs\n",
1423 if (!opt_int(opt_arg(), &misalign
))
1425 if (misalign
> MISALIGN
) {
1427 "%s: Maximum offset is %d\n", prog
, MISALIGN
);
1436 #ifdef OPENSSL_NO_MULTIBLOCK
1438 "%s: -mb specified but multi-block support is disabled\n",
1449 argc
= opt_num_rest();
1452 /* Remaining arguments are algorithms. */
1453 for (; *argv
; argv
++) {
1454 if (found(*argv
, doit_choices
, &i
)) {
1458 #ifndef OPENSSL_NO_DES
1459 if (strcmp(*argv
, "des") == 0) {
1460 doit
[D_CBC_DES
] = doit
[D_EDE3_DES
] = 1;
1464 if (strcmp(*argv
, "sha") == 0) {
1465 doit
[D_SHA1
] = doit
[D_SHA256
] = doit
[D_SHA512
] = 1;
1468 #ifndef OPENSSL_NO_RSA
1469 if (strcmp(*argv
, "openssl") == 0)
1471 if (strcmp(*argv
, "rsa") == 0) {
1472 rsa_doit
[R_RSA_512
] = rsa_doit
[R_RSA_1024
] =
1473 rsa_doit
[R_RSA_2048
] = rsa_doit
[R_RSA_3072
] =
1474 rsa_doit
[R_RSA_4096
] = rsa_doit
[R_RSA_7680
] =
1475 rsa_doit
[R_RSA_15360
] = 1;
1478 if (found(*argv
, rsa_choices
, &i
)) {
1483 #ifndef OPENSSL_NO_DSA
1484 if (strcmp(*argv
, "dsa") == 0) {
1485 dsa_doit
[R_DSA_512
] = dsa_doit
[R_DSA_1024
] =
1486 dsa_doit
[R_DSA_2048
] = 1;
1489 if (found(*argv
, dsa_choices
, &i
)) {
1494 if (strcmp(*argv
, "aes") == 0) {
1495 doit
[D_CBC_128_AES
] = doit
[D_CBC_192_AES
] = doit
[D_CBC_256_AES
] = 1;
1498 #ifndef OPENSSL_NO_CAMELLIA
1499 if (strcmp(*argv
, "camellia") == 0) {
1500 doit
[D_CBC_128_CML
] = doit
[D_CBC_192_CML
] = doit
[D_CBC_256_CML
] = 1;
1504 #ifndef OPENSSL_NO_EC
1505 if (strcmp(*argv
, "ecdsa") == 0) {
1506 for (i
= 0; i
< EC_NUM
; i
++)
1510 if (found(*argv
, ecdsa_choices
, &i
)) {
1514 if (strcmp(*argv
, "ecdh") == 0) {
1515 for (i
= 0; i
< EC_NUM
; i
++)
1519 if (found(*argv
, ecdh_choices
, &i
)) {
1524 BIO_printf(bio_err
, "%s: Unknown algorithm %s\n", prog
, *argv
);
1528 /* Initialize the job pool if async mode is enabled */
1529 if (async_jobs
> 0) {
1530 async_init
= ASYNC_init_thread(async_jobs
, async_jobs
);
1532 BIO_printf(bio_err
, "Error creating the ASYNC job pool\n");
1537 loopargs_len
= (async_jobs
== 0 ? 1 : async_jobs
);
1539 app_malloc(loopargs_len
* sizeof(loopargs_t
), "array of loopargs");
1540 memset(loopargs
, 0, loopargs_len
* sizeof(loopargs_t
));
1542 for (i
= 0; i
< loopargs_len
; i
++) {
1543 if (async_jobs
> 0) {
1544 loopargs
[i
].wait_ctx
= ASYNC_WAIT_CTX_new();
1545 if (loopargs
[i
].wait_ctx
== NULL
) {
1546 BIO_printf(bio_err
, "Error creating the ASYNC_WAIT_CTX\n");
1551 loopargs
[i
].buf_malloc
=
1552 app_malloc((int)BUFSIZE
+ MAX_MISALIGNMENT
+ 1, "input buffer");
1553 loopargs
[i
].buf2_malloc
=
1554 app_malloc((int)BUFSIZE
+ MAX_MISALIGNMENT
+ 1, "input buffer");
1555 /* Align the start of buffers on a 64 byte boundary */
1556 loopargs
[i
].buf
= loopargs
[i
].buf_malloc
+ misalign
;
1557 loopargs
[i
].buf2
= loopargs
[i
].buf2_malloc
+ misalign
;
1558 #ifndef OPENSSL_NO_EC
1559 loopargs
[i
].secret_a
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret a");
1560 loopargs
[i
].secret_b
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret b");
1565 if (multi
&& do_multi(multi
))
1569 /* Initialize the engine after the fork */
1570 e
= setup_engine(engine_id
, 0);
1572 /* No parameters; turn on everything. */
1573 if ((argc
== 0) && !doit
[D_EVP
]) {
1574 for (i
= 0; i
< ALGOR_NUM
; i
++)
1577 #ifndef OPENSSL_NO_RSA
1578 for (i
= 0; i
< RSA_NUM
; i
++)
1581 #ifndef OPENSSL_NO_DSA
1582 for (i
= 0; i
< DSA_NUM
; i
++)
1585 #ifndef OPENSSL_NO_EC
1586 for (i
= 0; i
< EC_NUM
; i
++)
1588 for (i
= 0; i
< EC_NUM
; i
++)
1592 for (i
= 0; i
< ALGOR_NUM
; i
++)
1596 if (usertime
== 0 && !mr
)
1598 "You have chosen to measure elapsed time "
1599 "instead of user CPU time.\n");
1601 #ifndef OPENSSL_NO_RSA
1602 for (i
= 0; i
< loopargs_len
; i
++) {
1603 for (k
= 0; k
< RSA_NUM
; k
++) {
1604 const unsigned char *p
;
1607 loopargs
[i
].rsa_key
[k
] =
1608 d2i_RSAPrivateKey(NULL
, &p
, rsa_data_length
[k
]);
1609 if (loopargs
[i
].rsa_key
[k
] == NULL
) {
1611 "internal error loading RSA key number %d\n", k
);
1617 #ifndef OPENSSL_NO_DSA
1618 for (i
= 0; i
< loopargs_len
; i
++) {
1619 loopargs
[i
].dsa_key
[0] = get_dsa(512);
1620 loopargs
[i
].dsa_key
[1] = get_dsa(1024);
1621 loopargs
[i
].dsa_key
[2] = get_dsa(2048);
1624 #ifndef OPENSSL_NO_DES
1625 DES_set_key_unchecked(&key
, &sch
);
1626 DES_set_key_unchecked(&key2
, &sch2
);
1627 DES_set_key_unchecked(&key3
, &sch3
);
1629 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
1630 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
1631 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
1632 #ifndef OPENSSL_NO_CAMELLIA
1633 Camellia_set_key(key16
, 128, &camellia_ks1
);
1634 Camellia_set_key(ckey24
, 192, &camellia_ks2
);
1635 Camellia_set_key(ckey32
, 256, &camellia_ks3
);
1637 #ifndef OPENSSL_NO_IDEA
1638 IDEA_set_encrypt_key(key16
, &idea_ks
);
1640 #ifndef OPENSSL_NO_SEED
1641 SEED_set_key(key16
, &seed_ks
);
1643 #ifndef OPENSSL_NO_RC4
1644 RC4_set_key(&rc4_ks
, 16, key16
);
1646 #ifndef OPENSSL_NO_RC2
1647 RC2_set_key(&rc2_ks
, 16, key16
, 128);
1649 #ifndef OPENSSL_NO_RC5
1650 RC5_32_set_key(&rc5_ks
, 16, key16
, 12);
1652 #ifndef OPENSSL_NO_BF
1653 BF_set_key(&bf_ks
, 16, key16
);
1655 #ifndef OPENSSL_NO_CAST
1656 CAST_set_key(&cast_ks
, 16, key16
);
1659 # ifndef OPENSSL_NO_DES
1660 BIO_printf(bio_err
, "First we calculate the approximate speed ...\n");
1666 for (it
= count
; it
; it
--)
1667 DES_ecb_encrypt((DES_cblock
*)loopargs
[0].buf
,
1668 (DES_cblock
*)loopargs
[0].buf
, &sch
, DES_ENCRYPT
);
1672 c
[D_MD2
][0] = count
/ 10;
1673 c
[D_MDC2
][0] = count
/ 10;
1674 c
[D_MD4
][0] = count
;
1675 c
[D_MD5
][0] = count
;
1676 c
[D_HMAC
][0] = count
;
1677 c
[D_SHA1
][0] = count
;
1678 c
[D_RMD160
][0] = count
;
1679 c
[D_RC4
][0] = count
* 5;
1680 c
[D_CBC_DES
][0] = count
;
1681 c
[D_EDE3_DES
][0] = count
/ 3;
1682 c
[D_CBC_IDEA
][0] = count
;
1683 c
[D_CBC_SEED
][0] = count
;
1684 c
[D_CBC_RC2
][0] = count
;
1685 c
[D_CBC_RC5
][0] = count
;
1686 c
[D_CBC_BF
][0] = count
;
1687 c
[D_CBC_CAST
][0] = count
;
1688 c
[D_CBC_128_AES
][0] = count
;
1689 c
[D_CBC_192_AES
][0] = count
;
1690 c
[D_CBC_256_AES
][0] = count
;
1691 c
[D_CBC_128_CML
][0] = count
;
1692 c
[D_CBC_192_CML
][0] = count
;
1693 c
[D_CBC_256_CML
][0] = count
;
1694 c
[D_SHA256
][0] = count
;
1695 c
[D_SHA512
][0] = count
;
1696 c
[D_WHIRLPOOL
][0] = count
;
1697 c
[D_IGE_128_AES
][0] = count
;
1698 c
[D_IGE_192_AES
][0] = count
;
1699 c
[D_IGE_256_AES
][0] = count
;
1700 c
[D_GHASH
][0] = count
;
1702 for (i
= 1; i
< SIZE_NUM
; i
++) {
1705 l0
= (long)lengths
[0];
1706 l1
= (long)lengths
[i
];
1708 c
[D_MD2
][i
] = c
[D_MD2
][0] * 4 * l0
/ l1
;
1709 c
[D_MDC2
][i
] = c
[D_MDC2
][0] * 4 * l0
/ l1
;
1710 c
[D_MD4
][i
] = c
[D_MD4
][0] * 4 * l0
/ l1
;
1711 c
[D_MD5
][i
] = c
[D_MD5
][0] * 4 * l0
/ l1
;
1712 c
[D_HMAC
][i
] = c
[D_HMAC
][0] * 4 * l0
/ l1
;
1713 c
[D_SHA1
][i
] = c
[D_SHA1
][0] * 4 * l0
/ l1
;
1714 c
[D_RMD160
][i
] = c
[D_RMD160
][0] * 4 * l0
/ l1
;
1715 c
[D_SHA256
][i
] = c
[D_SHA256
][0] * 4 * l0
/ l1
;
1716 c
[D_SHA512
][i
] = c
[D_SHA512
][0] * 4 * l0
/ l1
;
1717 c
[D_WHIRLPOOL
][i
] = c
[D_WHIRLPOOL
][0] * 4 * l0
/ l1
;
1718 c
[D_GHASH
][i
] = c
[D_GHASH
][0] * 4 * l0
/ l1
;
1720 l0
= (long)lengths
[i
- 1];
1722 c
[D_RC4
][i
] = c
[D_RC4
][i
- 1] * l0
/ l1
;
1723 c
[D_CBC_DES
][i
] = c
[D_CBC_DES
][i
- 1] * l0
/ l1
;
1724 c
[D_EDE3_DES
][i
] = c
[D_EDE3_DES
][i
- 1] * l0
/ l1
;
1725 c
[D_CBC_IDEA
][i
] = c
[D_CBC_IDEA
][i
- 1] * l0
/ l1
;
1726 c
[D_CBC_SEED
][i
] = c
[D_CBC_SEED
][i
- 1] * l0
/ l1
;
1727 c
[D_CBC_RC2
][i
] = c
[D_CBC_RC2
][i
- 1] * l0
/ l1
;
1728 c
[D_CBC_RC5
][i
] = c
[D_CBC_RC5
][i
- 1] * l0
/ l1
;
1729 c
[D_CBC_BF
][i
] = c
[D_CBC_BF
][i
- 1] * l0
/ l1
;
1730 c
[D_CBC_CAST
][i
] = c
[D_CBC_CAST
][i
- 1] * l0
/ l1
;
1731 c
[D_CBC_128_AES
][i
] = c
[D_CBC_128_AES
][i
- 1] * l0
/ l1
;
1732 c
[D_CBC_192_AES
][i
] = c
[D_CBC_192_AES
][i
- 1] * l0
/ l1
;
1733 c
[D_CBC_256_AES
][i
] = c
[D_CBC_256_AES
][i
- 1] * l0
/ l1
;
1734 c
[D_CBC_128_CML
][i
] = c
[D_CBC_128_CML
][i
- 1] * l0
/ l1
;
1735 c
[D_CBC_192_CML
][i
] = c
[D_CBC_192_CML
][i
- 1] * l0
/ l1
;
1736 c
[D_CBC_256_CML
][i
] = c
[D_CBC_256_CML
][i
- 1] * l0
/ l1
;
1737 c
[D_IGE_128_AES
][i
] = c
[D_IGE_128_AES
][i
- 1] * l0
/ l1
;
1738 c
[D_IGE_192_AES
][i
] = c
[D_IGE_192_AES
][i
- 1] * l0
/ l1
;
1739 c
[D_IGE_256_AES
][i
] = c
[D_IGE_256_AES
][i
- 1] * l0
/ l1
;
1742 # ifndef OPENSSL_NO_RSA
1743 rsa_c
[R_RSA_512
][0] = count
/ 2000;
1744 rsa_c
[R_RSA_512
][1] = count
/ 400;
1745 for (i
= 1; i
< RSA_NUM
; i
++) {
1746 rsa_c
[i
][0] = rsa_c
[i
- 1][0] / 8;
1747 rsa_c
[i
][1] = rsa_c
[i
- 1][1] / 4;
1748 if (rsa_doit
[i
] <= 1 && rsa_c
[i
][0] == 0)
1751 if (rsa_c
[i
][0] == 0) {
1752 rsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
1759 # ifndef OPENSSL_NO_DSA
1760 dsa_c
[R_DSA_512
][0] = count
/ 1000;
1761 dsa_c
[R_DSA_512
][1] = count
/ 1000 / 2;
1762 for (i
= 1; i
< DSA_NUM
; i
++) {
1763 dsa_c
[i
][0] = dsa_c
[i
- 1][0] / 4;
1764 dsa_c
[i
][1] = dsa_c
[i
- 1][1] / 4;
1765 if (dsa_doit
[i
] <= 1 && dsa_c
[i
][0] == 0)
1768 if (dsa_c
[i
][0] == 0) {
1769 dsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
1776 # ifndef OPENSSL_NO_EC
1777 ecdsa_c
[R_EC_P160
][0] = count
/ 1000;
1778 ecdsa_c
[R_EC_P160
][1] = count
/ 1000 / 2;
1779 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1780 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1781 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1782 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1785 if (ecdsa_c
[i
][0] == 0) {
1791 ecdsa_c
[R_EC_K163
][0] = count
/ 1000;
1792 ecdsa_c
[R_EC_K163
][1] = count
/ 1000 / 2;
1793 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1794 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1795 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1796 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1799 if (ecdsa_c
[i
][0] == 0) {
1805 ecdsa_c
[R_EC_B163
][0] = count
/ 1000;
1806 ecdsa_c
[R_EC_B163
][1] = count
/ 1000 / 2;
1807 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1808 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1809 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1810 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
1813 if (ecdsa_c
[i
][0] == 0) {
1820 ecdh_c
[R_EC_P160
][0] = count
/ 1000;
1821 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1822 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1823 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1826 if (ecdh_c
[i
][0] == 0) {
1831 ecdh_c
[R_EC_K163
][0] = count
/ 1000;
1832 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1833 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1834 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1837 if (ecdh_c
[i
][0] == 0) {
1842 ecdh_c
[R_EC_B163
][0] = count
/ 1000;
1843 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1844 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1845 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
1848 if (ecdh_c
[i
][0] == 0) {
1856 /* not worth fixing */
1857 # error "You cannot disable DES on systems without SIGALRM."
1858 # endif /* OPENSSL_NO_DES */
1861 signal(SIGALRM
, sig_done
);
1863 #endif /* SIGALRM */
1865 #ifndef OPENSSL_NO_MD2
1867 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1868 print_message(names
[D_MD2
], c
[D_MD2
][testnum
], lengths
[testnum
]);
1870 count
= run_benchmark(async_jobs
, EVP_Digest_MD2_loop
, loopargs
);
1872 print_result(D_MD2
, testnum
, count
, d
);
1876 #ifndef OPENSSL_NO_MDC2
1878 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1879 print_message(names
[D_MDC2
], c
[D_MDC2
][testnum
], lengths
[testnum
]);
1881 count
= run_benchmark(async_jobs
, EVP_Digest_MDC2_loop
, loopargs
);
1883 print_result(D_MDC2
, testnum
, count
, d
);
1888 #ifndef OPENSSL_NO_MD4
1890 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1891 print_message(names
[D_MD4
], c
[D_MD4
][testnum
], lengths
[testnum
]);
1893 count
= run_benchmark(async_jobs
, EVP_Digest_MD4_loop
, loopargs
);
1895 print_result(D_MD4
, testnum
, count
, d
);
1900 #ifndef OPENSSL_NO_MD5
1902 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1903 print_message(names
[D_MD5
], c
[D_MD5
][testnum
], lengths
[testnum
]);
1905 count
= run_benchmark(async_jobs
, MD5_loop
, loopargs
);
1907 print_result(D_MD5
, testnum
, count
, d
);
1912 static const char hmac_key
[] = "This is a key...";
1913 int len
= strlen(hmac_key
);
1915 for (i
= 0; i
< loopargs_len
; i
++) {
1916 loopargs
[i
].hctx
= HMAC_CTX_new();
1917 if (loopargs
[i
].hctx
== NULL
) {
1918 BIO_printf(bio_err
, "HMAC malloc failure, exiting...");
1922 HMAC_Init_ex(loopargs
[i
].hctx
, hmac_key
, len
, EVP_md5(), NULL
);
1924 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1925 print_message(names
[D_HMAC
], c
[D_HMAC
][testnum
], lengths
[testnum
]);
1927 count
= run_benchmark(async_jobs
, HMAC_loop
, loopargs
);
1929 print_result(D_HMAC
, testnum
, count
, d
);
1931 for (i
= 0; i
< loopargs_len
; i
++) {
1932 HMAC_CTX_free(loopargs
[i
].hctx
);
1937 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1938 print_message(names
[D_SHA1
], c
[D_SHA1
][testnum
], lengths
[testnum
]);
1940 count
= run_benchmark(async_jobs
, SHA1_loop
, loopargs
);
1942 print_result(D_SHA1
, testnum
, count
, d
);
1945 if (doit
[D_SHA256
]) {
1946 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1947 print_message(names
[D_SHA256
], c
[D_SHA256
][testnum
],
1950 count
= run_benchmark(async_jobs
, SHA256_loop
, loopargs
);
1952 print_result(D_SHA256
, testnum
, count
, d
);
1955 if (doit
[D_SHA512
]) {
1956 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1957 print_message(names
[D_SHA512
], c
[D_SHA512
][testnum
],
1960 count
= run_benchmark(async_jobs
, SHA512_loop
, loopargs
);
1962 print_result(D_SHA512
, testnum
, count
, d
);
1965 #ifndef OPENSSL_NO_WHIRLPOOL
1966 if (doit
[D_WHIRLPOOL
]) {
1967 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1968 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][testnum
],
1971 count
= run_benchmark(async_jobs
, WHIRLPOOL_loop
, loopargs
);
1973 print_result(D_WHIRLPOOL
, testnum
, count
, d
);
1978 #ifndef OPENSSL_NO_RMD160
1979 if (doit
[D_RMD160
]) {
1980 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1981 print_message(names
[D_RMD160
], c
[D_RMD160
][testnum
],
1984 count
= run_benchmark(async_jobs
, EVP_Digest_RMD160_loop
, loopargs
);
1986 print_result(D_RMD160
, testnum
, count
, d
);
1990 #ifndef OPENSSL_NO_RC4
1992 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
1993 print_message(names
[D_RC4
], c
[D_RC4
][testnum
], lengths
[testnum
]);
1995 count
= run_benchmark(async_jobs
, RC4_loop
, loopargs
);
1997 print_result(D_RC4
, testnum
, count
, d
);
2001 #ifndef OPENSSL_NO_DES
2002 if (doit
[D_CBC_DES
]) {
2003 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2004 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][testnum
],
2007 count
= run_benchmark(async_jobs
, DES_ncbc_encrypt_loop
, loopargs
);
2009 print_result(D_CBC_DES
, testnum
, count
, d
);
2013 if (doit
[D_EDE3_DES
]) {
2014 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2015 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][testnum
],
2019 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
],
2032 run_benchmark(async_jobs
, AES_cbc_128_encrypt_loop
, loopargs
);
2034 print_result(D_CBC_128_AES
, testnum
, count
, d
);
2037 if (doit
[D_CBC_192_AES
]) {
2038 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2039 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][testnum
],
2043 run_benchmark(async_jobs
, AES_cbc_192_encrypt_loop
, loopargs
);
2045 print_result(D_CBC_192_AES
, testnum
, count
, d
);
2048 if (doit
[D_CBC_256_AES
]) {
2049 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2050 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][testnum
],
2054 run_benchmark(async_jobs
, AES_cbc_256_encrypt_loop
, loopargs
);
2056 print_result(D_CBC_256_AES
, testnum
, count
, d
);
2060 if (doit
[D_IGE_128_AES
]) {
2061 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2062 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][testnum
],
2066 run_benchmark(async_jobs
, AES_ige_128_encrypt_loop
, loopargs
);
2068 print_result(D_IGE_128_AES
, testnum
, count
, d
);
2071 if (doit
[D_IGE_192_AES
]) {
2072 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2073 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][testnum
],
2077 run_benchmark(async_jobs
, AES_ige_192_encrypt_loop
, loopargs
);
2079 print_result(D_IGE_192_AES
, testnum
, count
, d
);
2082 if (doit
[D_IGE_256_AES
]) {
2083 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2084 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][testnum
],
2088 run_benchmark(async_jobs
, AES_ige_256_encrypt_loop
, loopargs
);
2090 print_result(D_IGE_256_AES
, testnum
, count
, d
);
2093 if (doit
[D_GHASH
]) {
2094 for (i
= 0; i
< loopargs_len
; i
++) {
2095 loopargs
[i
].gcm_ctx
=
2096 CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
2097 CRYPTO_gcm128_setiv(loopargs
[i
].gcm_ctx
,
2098 (unsigned char *)"0123456789ab", 12);
2101 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2102 print_message(names
[D_GHASH
], c
[D_GHASH
][testnum
],
2105 count
= run_benchmark(async_jobs
, CRYPTO_gcm128_aad_loop
, loopargs
);
2107 print_result(D_GHASH
, testnum
, count
, d
);
2109 for (i
= 0; i
< loopargs_len
; i
++)
2110 CRYPTO_gcm128_release(loopargs
[i
].gcm_ctx
);
2112 #ifndef OPENSSL_NO_CAMELLIA
2113 if (doit
[D_CBC_128_CML
]) {
2114 if (async_jobs
> 0) {
2115 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2116 names
[D_CBC_128_CML
]);
2117 doit
[D_CBC_128_CML
] = 0;
2119 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2120 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][testnum
],
2123 for (count
= 0, run
= 1; COND(c
[D_CBC_128_CML
][testnum
]); count
++)
2124 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2125 (size_t)lengths
[testnum
], &camellia_ks1
,
2126 iv
, CAMELLIA_ENCRYPT
);
2128 print_result(D_CBC_128_CML
, testnum
, count
, d
);
2131 if (doit
[D_CBC_192_CML
]) {
2132 if (async_jobs
> 0) {
2133 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2134 names
[D_CBC_192_CML
]);
2135 doit
[D_CBC_192_CML
] = 0;
2137 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2138 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][testnum
],
2140 if (async_jobs
> 0) {
2141 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2145 for (count
= 0, run
= 1; COND(c
[D_CBC_192_CML
][testnum
]); count
++)
2146 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2147 (size_t)lengths
[testnum
], &camellia_ks2
,
2148 iv
, CAMELLIA_ENCRYPT
);
2150 print_result(D_CBC_192_CML
, testnum
, count
, d
);
2153 if (doit
[D_CBC_256_CML
]) {
2154 if (async_jobs
> 0) {
2155 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2156 names
[D_CBC_256_CML
]);
2157 doit
[D_CBC_256_CML
] = 0;
2159 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2160 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][testnum
],
2163 for (count
= 0, run
= 1; COND(c
[D_CBC_256_CML
][testnum
]); count
++)
2164 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2165 (size_t)lengths
[testnum
], &camellia_ks3
,
2166 iv
, CAMELLIA_ENCRYPT
);
2168 print_result(D_CBC_256_CML
, testnum
, count
, d
);
2172 #ifndef OPENSSL_NO_IDEA
2173 if (doit
[D_CBC_IDEA
]) {
2174 if (async_jobs
> 0) {
2175 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2177 doit
[D_CBC_IDEA
] = 0;
2179 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2180 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][testnum
],
2183 for (count
= 0, run
= 1; COND(c
[D_CBC_IDEA
][testnum
]); count
++)
2184 IDEA_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2185 (size_t)lengths
[testnum
], &idea_ks
,
2188 print_result(D_CBC_IDEA
, testnum
, count
, d
);
2192 #ifndef OPENSSL_NO_SEED
2193 if (doit
[D_CBC_SEED
]) {
2194 if (async_jobs
> 0) {
2195 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2197 doit
[D_CBC_SEED
] = 0;
2199 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2200 print_message(names
[D_CBC_SEED
], c
[D_CBC_SEED
][testnum
],
2203 for (count
= 0, run
= 1; COND(c
[D_CBC_SEED
][testnum
]); count
++)
2204 SEED_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2205 (size_t)lengths
[testnum
], &seed_ks
, iv
, 1);
2207 print_result(D_CBC_SEED
, testnum
, count
, d
);
2211 #ifndef OPENSSL_NO_RC2
2212 if (doit
[D_CBC_RC2
]) {
2213 if (async_jobs
> 0) {
2214 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2216 doit
[D_CBC_RC2
] = 0;
2218 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2219 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][testnum
],
2221 if (async_jobs
> 0) {
2222 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2226 for (count
= 0, run
= 1; COND(c
[D_CBC_RC2
][testnum
]); count
++)
2227 RC2_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2228 (size_t)lengths
[testnum
], &rc2_ks
,
2231 print_result(D_CBC_RC2
, testnum
, count
, d
);
2235 #ifndef OPENSSL_NO_RC5
2236 if (doit
[D_CBC_RC5
]) {
2237 if (async_jobs
> 0) {
2238 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2240 doit
[D_CBC_RC5
] = 0;
2242 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2243 print_message(names
[D_CBC_RC5
], c
[D_CBC_RC5
][testnum
],
2245 if (async_jobs
> 0) {
2246 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2250 for (count
= 0, run
= 1; COND(c
[D_CBC_RC5
][testnum
]); count
++)
2251 RC5_32_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2252 (size_t)lengths
[testnum
], &rc5_ks
,
2255 print_result(D_CBC_RC5
, testnum
, count
, d
);
2259 #ifndef OPENSSL_NO_BF
2260 if (doit
[D_CBC_BF
]) {
2261 if (async_jobs
> 0) {
2262 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2266 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2267 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][testnum
],
2270 for (count
= 0, run
= 1; COND(c
[D_CBC_BF
][testnum
]); count
++)
2271 BF_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2272 (size_t)lengths
[testnum
], &bf_ks
,
2275 print_result(D_CBC_BF
, testnum
, count
, d
);
2279 #ifndef OPENSSL_NO_CAST
2280 if (doit
[D_CBC_CAST
]) {
2281 if (async_jobs
> 0) {
2282 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2284 doit
[D_CBC_CAST
] = 0;
2286 for (testnum
= 0; testnum
< SIZE_NUM
&& async_init
== 0; testnum
++) {
2287 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][testnum
],
2290 for (count
= 0, run
= 1; COND(c
[D_CBC_CAST
][testnum
]); count
++)
2291 CAST_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2292 (size_t)lengths
[testnum
], &cast_ks
,
2295 print_result(D_CBC_CAST
, testnum
, count
, d
);
2301 if (multiblock
&& evp_cipher
) {
2303 (EVP_CIPHER_flags(evp_cipher
) &
2304 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
2305 BIO_printf(bio_err
, "%s is not multi-block capable\n",
2306 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
2309 if (async_jobs
> 0) {
2310 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2313 multiblock_speed(evp_cipher
);
2317 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2320 names
[D_EVP
] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
2322 * -O3 -fschedule-insns messes up an optimization here!
2323 * names[D_EVP] somehow becomes NULL
2325 print_message(names
[D_EVP
], save_count
, lengths
[testnum
]);
2327 for (k
= 0; k
< loopargs_len
; k
++) {
2328 loopargs
[k
].ctx
= EVP_CIPHER_CTX_new();
2330 EVP_DecryptInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
,
2333 EVP_EncryptInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
,
2335 EVP_CIPHER_CTX_set_padding(loopargs
[k
].ctx
, 0);
2337 switch (EVP_CIPHER_mode(evp_cipher
)) {
2338 case EVP_CIPH_CCM_MODE
:
2339 loopfunc
= EVP_Update_loop_ccm
;
2342 loopfunc
= EVP_Update_loop
;
2346 count
= run_benchmark(async_jobs
, loopfunc
, loopargs
);
2348 for (k
= 0; k
< loopargs_len
; k
++) {
2349 EVP_CIPHER_CTX_free(loopargs
[k
].ctx
);
2353 names
[D_EVP
] = OBJ_nid2ln(EVP_MD_type(evp_md
));
2354 print_message(names
[D_EVP
], save_count
, lengths
[testnum
]);
2356 count
= run_benchmark(async_jobs
, EVP_Digest_loop
, loopargs
);
2359 print_result(D_EVP
, testnum
, count
, d
);
2363 for (i
= 0; i
< loopargs_len
; i
++)
2364 RAND_bytes(loopargs
[i
].buf
, 36);
2366 #ifndef OPENSSL_NO_RSA
2367 for (testnum
= 0; testnum
< RSA_NUM
; testnum
++) {
2369 if (!rsa_doit
[testnum
])
2371 for (i
= 0; i
< loopargs_len
; i
++) {
2372 st
= RSA_sign(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2373 &loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2379 "RSA sign failure. No RSA sign will be done.\n");
2380 ERR_print_errors(bio_err
);
2383 pkey_print_message("private", "rsa",
2384 rsa_c
[testnum
][0], rsa_bits
[testnum
],
2386 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2388 count
= run_benchmark(async_jobs
, RSA_sign_loop
, loopargs
);
2391 mr
? "+R1:%ld:%d:%.2f\n"
2392 : "%ld %d bit private RSA's in %.2fs\n",
2393 count
, rsa_bits
[testnum
], d
);
2394 rsa_results
[testnum
][0] = (double)count
/ d
;
2398 for (i
= 0; i
< loopargs_len
; i
++) {
2399 st
= RSA_verify(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2400 loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2406 "RSA verify failure. No RSA verify will be done.\n");
2407 ERR_print_errors(bio_err
);
2408 rsa_doit
[testnum
] = 0;
2410 pkey_print_message("public", "rsa",
2411 rsa_c
[testnum
][1], rsa_bits
[testnum
],
2414 count
= run_benchmark(async_jobs
, RSA_verify_loop
, loopargs
);
2417 mr
? "+R2:%ld:%d:%.2f\n"
2418 : "%ld %d bit public RSA's in %.2fs\n",
2419 count
, rsa_bits
[testnum
], d
);
2420 rsa_results
[testnum
][1] = (double)count
/ d
;
2423 if (rsa_count
<= 1) {
2424 /* if longer than 10s, don't do any more */
2425 for (testnum
++; testnum
< RSA_NUM
; testnum
++)
2426 rsa_doit
[testnum
] = 0;
2429 #endif /* OPENSSL_NO_RSA */
2431 for (i
= 0; i
< loopargs_len
; i
++)
2432 RAND_bytes(loopargs
[i
].buf
, 36);
2434 #ifndef OPENSSL_NO_DSA
2435 for (testnum
= 0; testnum
< DSA_NUM
; testnum
++) {
2437 if (!dsa_doit
[testnum
])
2440 /* DSA_generate_key(dsa_key[testnum]); */
2441 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2442 for (i
= 0; i
< loopargs_len
; i
++) {
2443 st
= DSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2444 &loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2450 "DSA sign failure. No DSA sign will be done.\n");
2451 ERR_print_errors(bio_err
);
2454 pkey_print_message("sign", "dsa",
2455 dsa_c
[testnum
][0], dsa_bits
[testnum
],
2458 count
= run_benchmark(async_jobs
, DSA_sign_loop
, loopargs
);
2461 mr
? "+R3:%ld:%d:%.2f\n"
2462 : "%ld %d bit DSA signs in %.2fs\n",
2463 count
, dsa_bits
[testnum
], d
);
2464 dsa_results
[testnum
][0] = (double)count
/ d
;
2468 for (i
= 0; i
< loopargs_len
; i
++) {
2469 st
= DSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2470 loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2476 "DSA verify failure. No DSA verify will be done.\n");
2477 ERR_print_errors(bio_err
);
2478 dsa_doit
[testnum
] = 0;
2480 pkey_print_message("verify", "dsa",
2481 dsa_c
[testnum
][1], dsa_bits
[testnum
],
2484 count
= run_benchmark(async_jobs
, DSA_verify_loop
, loopargs
);
2487 mr
? "+R4:%ld:%d:%.2f\n"
2488 : "%ld %d bit DSA verify in %.2fs\n",
2489 count
, dsa_bits
[testnum
], d
);
2490 dsa_results
[testnum
][1] = (double)count
/ d
;
2493 if (rsa_count
<= 1) {
2494 /* if longer than 10s, don't do any more */
2495 for (testnum
++; testnum
< DSA_NUM
; testnum
++)
2496 dsa_doit
[testnum
] = 0;
2499 #endif /* OPENSSL_NO_DSA */
2501 #ifndef OPENSSL_NO_EC
2502 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
2505 if (!ecdsa_doit
[testnum
])
2506 continue; /* Ignore Curve */
2507 for (i
= 0; i
< loopargs_len
; i
++) {
2508 loopargs
[i
].ecdsa
[testnum
] =
2509 EC_KEY_new_by_curve_name(test_curves
[testnum
]);
2510 if (loopargs
[i
].ecdsa
[testnum
] == NULL
) {
2516 BIO_printf(bio_err
, "ECDSA failure.\n");
2517 ERR_print_errors(bio_err
);
2520 for (i
= 0; i
< loopargs_len
; i
++) {
2521 EC_KEY_precompute_mult(loopargs
[i
].ecdsa
[testnum
], NULL
);
2522 /* Perform ECDSA signature test */
2523 EC_KEY_generate_key(loopargs
[i
].ecdsa
[testnum
]);
2524 st
= ECDSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2525 &loopargs
[i
].siglen
,
2526 loopargs
[i
].ecdsa
[testnum
]);
2532 "ECDSA sign failure. No ECDSA sign will be done.\n");
2533 ERR_print_errors(bio_err
);
2536 pkey_print_message("sign", "ecdsa",
2537 ecdsa_c
[testnum
][0],
2538 test_curves_bits
[testnum
], ECDSA_SECONDS
);
2540 count
= run_benchmark(async_jobs
, ECDSA_sign_loop
, loopargs
);
2544 mr
? "+R5:%ld:%d:%.2f\n" :
2545 "%ld %d bit ECDSA signs in %.2fs \n",
2546 count
, test_curves_bits
[testnum
], d
);
2547 ecdsa_results
[testnum
][0] = (double)count
/ d
;
2551 /* Perform ECDSA verification test */
2552 for (i
= 0; i
< loopargs_len
; i
++) {
2553 st
= ECDSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2555 loopargs
[i
].ecdsa
[testnum
]);
2561 "ECDSA verify failure. No ECDSA verify will be done.\n");
2562 ERR_print_errors(bio_err
);
2563 ecdsa_doit
[testnum
] = 0;
2565 pkey_print_message("verify", "ecdsa",
2566 ecdsa_c
[testnum
][1],
2567 test_curves_bits
[testnum
], ECDSA_SECONDS
);
2569 count
= run_benchmark(async_jobs
, ECDSA_verify_loop
, loopargs
);
2572 mr
? "+R6:%ld:%d:%.2f\n"
2573 : "%ld %d bit ECDSA verify in %.2fs\n",
2574 count
, test_curves_bits
[testnum
], d
);
2575 ecdsa_results
[testnum
][1] = (double)count
/ d
;
2578 if (rsa_count
<= 1) {
2579 /* if longer than 10s, don't do any more */
2580 for (testnum
++; testnum
< EC_NUM
; testnum
++)
2581 ecdsa_doit
[testnum
] = 0;
2586 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
2587 int ecdh_checks
= 1;
2589 if (!ecdh_doit
[testnum
])
2592 for (i
= 0; i
< loopargs_len
; i
++) {
2593 EVP_PKEY_CTX
*kctx
= NULL
;
2594 EVP_PKEY_CTX
*test_ctx
= NULL
;
2595 EVP_PKEY_CTX
*ctx
= NULL
;
2596 EVP_PKEY
*key_A
= NULL
;
2597 EVP_PKEY
*key_B
= NULL
;
2601 /* Ensure that the error queue is empty */
2602 if (ERR_peek_error()) {
2604 "WARNING: the error queue contains previous unhandled errors.\n");
2605 ERR_print_errors(bio_err
);
2608 /* Let's try to create a ctx directly from the NID: this works for
2609 * curves like Curve25519 that are not implemented through the low
2610 * level EC interface.
2611 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2612 * then we set the curve by NID before deriving the actual keygen
2613 * ctx for that specific curve. */
2614 kctx
= EVP_PKEY_CTX_new_id(test_curves
[testnum
], NULL
); /* keygen ctx from NID */
2616 EVP_PKEY_CTX
*pctx
= NULL
;
2617 EVP_PKEY
*params
= NULL
;
2619 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2620 * "int_ctx_new:unsupported algorithm" error was added to the
2622 * We remove it from the error queue as we are handling it. */
2623 unsigned long error
= ERR_peek_error(); /* peek the latest error in the queue */
2624 if (error
== ERR_peek_last_error() && /* oldest and latest errors match */
2625 /* check that the error origin matches */
2626 ERR_GET_LIB(error
) == ERR_LIB_EVP
&&
2627 ERR_GET_FUNC(error
) == EVP_F_INT_CTX_NEW
&&
2628 ERR_GET_REASON(error
) == EVP_R_UNSUPPORTED_ALGORITHM
)
2629 ERR_get_error(); /* pop error from queue */
2630 if (ERR_peek_error()) {
2632 "Unhandled error in the error queue during ECDH init.\n");
2633 ERR_print_errors(bio_err
);
2638 if ( /* Create the context for parameter generation */
2639 !(pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
)) ||
2640 /* Initialise the parameter generation */
2641 !EVP_PKEY_paramgen_init(pctx
) ||
2642 /* Set the curve by NID */
2643 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
,
2646 /* Create the parameter object params */
2647 !EVP_PKEY_paramgen(pctx
, ¶ms
)) {
2649 BIO_printf(bio_err
, "ECDH EC params init failure.\n");
2650 ERR_print_errors(bio_err
);
2654 /* Create the context for the key generation */
2655 kctx
= EVP_PKEY_CTX_new(params
, NULL
);
2657 EVP_PKEY_free(params
);
2659 EVP_PKEY_CTX_free(pctx
);
2662 if (kctx
== NULL
|| /* keygen ctx is not null */
2663 !EVP_PKEY_keygen_init(kctx
) /* init keygen ctx */ ) {
2665 BIO_printf(bio_err
, "ECDH keygen failure.\n");
2666 ERR_print_errors(bio_err
);
2671 if (!EVP_PKEY_keygen(kctx
, &key_A
) || /* generate secret key A */
2672 !EVP_PKEY_keygen(kctx
, &key_B
) || /* generate secret key B */
2673 !(ctx
= EVP_PKEY_CTX_new(key_A
, NULL
)) || /* derivation ctx from skeyA */
2674 !EVP_PKEY_derive_init(ctx
) || /* init derivation ctx */
2675 !EVP_PKEY_derive_set_peer(ctx
, key_B
) || /* set peer pubkey in ctx */
2676 !EVP_PKEY_derive(ctx
, NULL
, &outlen
) || /* determine max length */
2677 outlen
== 0 || /* ensure outlen is a valid size */
2678 outlen
> MAX_ECDH_SIZE
/* avoid buffer overflow */ ) {
2680 BIO_printf(bio_err
, "ECDH key generation failure.\n");
2681 ERR_print_errors(bio_err
);
2686 /* Here we perform a test run, comparing the output of a*B and b*A;
2687 * we try this here and assume that further EVP_PKEY_derive calls
2688 * never fail, so we can skip checks in the actually benchmarked
2689 * code, for maximum performance. */
2690 if (!(test_ctx
= EVP_PKEY_CTX_new(key_B
, NULL
)) || /* test ctx from skeyB */
2691 !EVP_PKEY_derive_init(test_ctx
) || /* init derivation test_ctx */
2692 !EVP_PKEY_derive_set_peer(test_ctx
, key_A
) || /* set peer pubkey in test_ctx */
2693 !EVP_PKEY_derive(test_ctx
, NULL
, &test_outlen
) || /* determine max length */
2694 !EVP_PKEY_derive(ctx
, loopargs
[i
].secret_a
, &outlen
) || /* compute a*B */
2695 !EVP_PKEY_derive(test_ctx
, loopargs
[i
].secret_b
, &test_outlen
) || /* compute b*A */
2696 test_outlen
!= outlen
/* compare output length */ ) {
2698 BIO_printf(bio_err
, "ECDH computation failure.\n");
2699 ERR_print_errors(bio_err
);
2704 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
2705 if (CRYPTO_memcmp(loopargs
[i
].secret_a
,
2706 loopargs
[i
].secret_b
, outlen
)) {
2708 BIO_printf(bio_err
, "ECDH computations don't match.\n");
2709 ERR_print_errors(bio_err
);
2714 loopargs
[i
].ecdh_ctx
[testnum
] = ctx
;
2715 loopargs
[i
].outlen
[testnum
] = outlen
;
2717 EVP_PKEY_CTX_free(kctx
);
2719 EVP_PKEY_CTX_free(test_ctx
);
2722 if (ecdh_checks
!= 0) {
2723 pkey_print_message("", "ecdh",
2725 test_curves_bits
[testnum
], ECDH_SECONDS
);
2728 run_benchmark(async_jobs
, ECDH_EVP_derive_key_loop
, loopargs
);
2731 mr
? "+R7:%ld:%d:%.2f\n" :
2732 "%ld %d-bit ECDH ops in %.2fs\n", count
,
2733 test_curves_bits
[testnum
], d
);
2734 ecdh_results
[testnum
][0] = (double)count
/ d
;
2738 if (rsa_count
<= 1) {
2739 /* if longer than 10s, don't do any more */
2740 for (testnum
++; testnum
< EC_NUM
; testnum
++)
2741 ecdh_doit
[testnum
] = 0;
2744 #endif /* OPENSSL_NO_EC */
2749 printf("%s\n", OpenSSL_version(OPENSSL_VERSION
));
2750 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON
));
2752 printf("%s ", BN_options());
2753 #ifndef OPENSSL_NO_MD2
2754 printf("%s ", MD2_options());
2756 #ifndef OPENSSL_NO_RC4
2757 printf("%s ", RC4_options());
2759 #ifndef OPENSSL_NO_DES
2760 printf("%s ", DES_options());
2762 printf("%s ", AES_options());
2763 #ifndef OPENSSL_NO_IDEA
2764 printf("%s ", IDEA_options());
2766 #ifndef OPENSSL_NO_BF
2767 printf("%s ", BF_options());
2769 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS
));
2777 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2780 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++)
2781 printf(mr
? ":%d" : "%7d bytes", lengths
[testnum
]);
2785 for (k
= 0; k
< ALGOR_NUM
; k
++) {
2789 printf("+F:%d:%s", k
, names
[k
]);
2791 printf("%-13s", names
[k
]);
2792 for (testnum
= 0; testnum
< SIZE_NUM
; testnum
++) {
2793 if (results
[k
][testnum
] > 10000 && !mr
)
2794 printf(" %11.2fk", results
[k
][testnum
] / 1e3
);
2796 printf(mr
? ":%.2f" : " %11.2f ", results
[k
][testnum
]);
2800 #ifndef OPENSSL_NO_RSA
2802 for (k
= 0; k
< RSA_NUM
; k
++) {
2805 if (testnum
&& !mr
) {
2806 printf("%18ssign verify sign/s verify/s\n", " ");
2810 printf("+F2:%u:%u:%f:%f\n",
2811 k
, rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1]);
2813 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2814 rsa_bits
[k
], 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1],
2815 rsa_results
[k
][0], rsa_results
[k
][1]);
2818 #ifndef OPENSSL_NO_DSA
2820 for (k
= 0; k
< DSA_NUM
; k
++) {
2823 if (testnum
&& !mr
) {
2824 printf("%18ssign verify sign/s verify/s\n", " ");
2828 printf("+F3:%u:%u:%f:%f\n",
2829 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
2831 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2832 dsa_bits
[k
], 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1],
2833 dsa_results
[k
][0], dsa_results
[k
][1]);
2836 #ifndef OPENSSL_NO_EC
2838 for (k
= 0; k
< EC_NUM
; k
++) {
2841 if (testnum
&& !mr
) {
2842 printf("%30ssign verify sign/s verify/s\n", " ");
2847 printf("+F4:%u:%u:%f:%f\n",
2848 k
, test_curves_bits
[k
],
2849 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
2851 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2852 test_curves_bits
[k
],
2853 test_curves_names
[k
],
2854 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1],
2855 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
2859 for (k
= 0; k
< EC_NUM
; k
++) {
2862 if (testnum
&& !mr
) {
2863 printf("%30sop op/s\n", " ");
2867 printf("+F5:%u:%u:%f:%f\n",
2868 k
, test_curves_bits
[k
],
2869 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
2872 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2873 test_curves_bits
[k
],
2874 test_curves_names
[k
],
2875 1.0 / ecdh_results
[k
][0], ecdh_results
[k
][0]);
2882 ERR_print_errors(bio_err
);
2883 for (i
= 0; i
< loopargs_len
; i
++) {
2884 OPENSSL_free(loopargs
[i
].buf_malloc
);
2885 OPENSSL_free(loopargs
[i
].buf2_malloc
);
2887 #ifndef OPENSSL_NO_RSA
2888 for (k
= 0; k
< RSA_NUM
; k
++)
2889 RSA_free(loopargs
[i
].rsa_key
[k
]);
2891 #ifndef OPENSSL_NO_DSA
2892 for (k
= 0; k
< DSA_NUM
; k
++)
2893 DSA_free(loopargs
[i
].dsa_key
[k
]);
2895 #ifndef OPENSSL_NO_EC
2896 for (k
= 0; k
< EC_NUM
; k
++) {
2897 EC_KEY_free(loopargs
[i
].ecdsa
[k
]);
2898 EVP_PKEY_CTX_free(loopargs
[i
].ecdh_ctx
[k
]);
2900 OPENSSL_free(loopargs
[i
].secret_a
);
2901 OPENSSL_free(loopargs
[i
].secret_b
);
2905 if (async_jobs
> 0) {
2906 for (i
= 0; i
< loopargs_len
; i
++)
2907 ASYNC_WAIT_CTX_free(loopargs
[i
].wait_ctx
);
2911 ASYNC_cleanup_thread();
2913 OPENSSL_free(loopargs
);
2918 static void print_message(const char *s
, long num
, int length
)
2922 mr
? "+DT:%s:%d:%d\n"
2923 : "Doing %s for %ds on %d size blocks: ", s
, SECONDS
, length
);
2924 (void)BIO_flush(bio_err
);
2928 mr
? "+DN:%s:%ld:%d\n"
2929 : "Doing %s %ld times on %d size blocks: ", s
, num
, length
);
2930 (void)BIO_flush(bio_err
);
2934 static void pkey_print_message(const char *str
, const char *str2
, long num
,
2939 mr
? "+DTP:%d:%s:%s:%d\n"
2940 : "Doing %d bit %s %s's for %ds: ", bits
, str
, str2
, tm
);
2941 (void)BIO_flush(bio_err
);
2945 mr
? "+DNP:%ld:%d:%s:%s\n"
2946 : "Doing %ld %d bit %s %s's: ", num
, bits
, str
, str2
);
2947 (void)BIO_flush(bio_err
);
2951 static void print_result(int alg
, int run_no
, int count
, double time_used
)
2954 BIO_puts(bio_err
, "EVP error!\n");
2958 mr
? "+R:%d:%s:%f\n"
2959 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
2960 results
[alg
][run_no
] = ((double)count
) / time_used
* lengths
[run_no
];
2964 static char *sstrsep(char **string
, const char *delim
)
2967 char *token
= *string
;
2972 memset(isdelim
, 0, sizeof isdelim
);
2976 isdelim
[(unsigned char)(*delim
)] = 1;
2980 while (!isdelim
[(unsigned char)(**string
)]) {
2992 static int do_multi(int multi
)
2997 static char sep
[] = ":";
2999 fds
= malloc(sizeof(*fds
) * multi
);
3000 for (n
= 0; n
< multi
; ++n
) {
3001 if (pipe(fd
) == -1) {
3002 BIO_printf(bio_err
, "pipe failure\n");
3006 (void)BIO_flush(bio_err
);
3013 if (dup(fd
[1]) == -1) {
3014 BIO_printf(bio_err
, "dup failed\n");
3023 printf("Forked child %d\n", n
);
3026 /* for now, assume the pipe is long enough to take all the output */
3027 for (n
= 0; n
< multi
; ++n
) {
3032 f
= fdopen(fds
[n
], "r");
3033 while (fgets(buf
, sizeof buf
, f
)) {
3034 p
= strchr(buf
, '\n');
3037 if (buf
[0] != '+') {
3039 "Don't understand line '%s' from child %d\n", buf
,
3043 printf("Got: %s from %d\n", buf
, n
);
3044 if (strncmp(buf
, "+F:", 3) == 0) {
3049 alg
= atoi(sstrsep(&p
, sep
));
3051 for (j
= 0; j
< SIZE_NUM
; ++j
)
3052 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
3053 } else if (strncmp(buf
, "+F2:", 4) == 0) {
3058 k
= atoi(sstrsep(&p
, sep
));
3061 d
= atof(sstrsep(&p
, sep
));
3062 rsa_results
[k
][0] += d
;
3064 d
= atof(sstrsep(&p
, sep
));
3065 rsa_results
[k
][1] += d
;
3067 # ifndef OPENSSL_NO_DSA
3068 else if (strncmp(buf
, "+F3:", 4) == 0) {
3073 k
= atoi(sstrsep(&p
, sep
));
3076 d
= atof(sstrsep(&p
, sep
));
3077 dsa_results
[k
][0] += d
;
3079 d
= atof(sstrsep(&p
, sep
));
3080 dsa_results
[k
][1] += d
;
3083 # ifndef OPENSSL_NO_EC
3084 else if (strncmp(buf
, "+F4:", 4) == 0) {
3089 k
= atoi(sstrsep(&p
, sep
));
3092 d
= atof(sstrsep(&p
, sep
));
3093 ecdsa_results
[k
][0] += d
;
3095 d
= atof(sstrsep(&p
, sep
));
3096 ecdsa_results
[k
][1] += d
;
3097 } else if (strncmp(buf
, "+F5:", 4) == 0) {
3102 k
= atoi(sstrsep(&p
, sep
));
3105 d
= atof(sstrsep(&p
, sep
));
3106 ecdh_results
[k
][0] += d
;
3110 else if (strncmp(buf
, "+H:", 3) == 0) {
3113 BIO_printf(bio_err
, "Unknown type '%s' from child %d\n", buf
,
3124 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
)
3126 static int mblengths
[] =
3127 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3128 int j
, count
, num
= OSSL_NELEM(mblengths
);
3129 const char *alg_name
;
3130 unsigned char *inp
, *out
, no_key
[32], no_iv
[16];
3131 EVP_CIPHER_CTX
*ctx
;
3134 inp
= app_malloc(mblengths
[num
- 1], "multiblock input buffer");
3135 out
= app_malloc(mblengths
[num
- 1] + 1024, "multiblock output buffer");
3136 ctx
= EVP_CIPHER_CTX_new();
3137 EVP_EncryptInit_ex(ctx
, evp_cipher
, NULL
, no_key
, no_iv
);
3138 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_MAC_KEY
, sizeof(no_key
), no_key
);
3139 alg_name
= OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
3141 for (j
= 0; j
< num
; j
++) {
3142 print_message(alg_name
, 0, mblengths
[j
]);
3144 for (count
= 0, run
= 1; run
&& count
< 0x7fffffff; count
++) {
3145 unsigned char aad
[EVP_AEAD_TLS1_AAD_LEN
];
3146 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param
;
3147 size_t len
= mblengths
[j
];
3150 memset(aad
, 0, 8); /* avoid uninitialized values */
3151 aad
[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3152 aad
[9] = 3; /* version */
3154 aad
[11] = 0; /* length */
3156 mb_param
.out
= NULL
;
3159 mb_param
.interleave
= 8;
3161 packlen
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD
,
3162 sizeof(mb_param
), &mb_param
);
3168 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT
,
3169 sizeof(mb_param
), &mb_param
);
3173 RAND_bytes(out
, 16);
3177 pad
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_TLS1_AAD
,
3178 EVP_AEAD_TLS1_AAD_LEN
, aad
);
3179 EVP_Cipher(ctx
, out
, inp
, len
+ pad
);
3183 BIO_printf(bio_err
, mr
? "+R:%d:%s:%f\n"
3184 : "%d %s's in %.2fs\n", count
, "evp", d
);
3185 results
[D_EVP
][j
] = ((double)count
) / d
* mblengths
[j
];
3189 fprintf(stdout
, "+H");
3190 for (j
= 0; j
< num
; j
++)
3191 fprintf(stdout
, ":%d", mblengths
[j
]);
3192 fprintf(stdout
, "\n");
3193 fprintf(stdout
, "+F:%d:%s", D_EVP
, alg_name
);
3194 for (j
= 0; j
< num
; j
++)
3195 fprintf(stdout
, ":%.2f", results
[D_EVP
][j
]);
3196 fprintf(stdout
, "\n");
3199 "The 'numbers' are in 1000s of bytes per second processed.\n");
3200 fprintf(stdout
, "type ");
3201 for (j
= 0; j
< num
; j
++)
3202 fprintf(stdout
, "%7d bytes", mblengths
[j
]);
3203 fprintf(stdout
, "\n");
3204 fprintf(stdout
, "%-24s", alg_name
);
3206 for (j
= 0; j
< num
; j
++) {
3207 if (results
[D_EVP
][j
] > 10000)
3208 fprintf(stdout
, " %11.2fk", results
[D_EVP
][j
] / 1e3
);
3210 fprintf(stdout
, " %11.2f ", results
[D_EVP
][j
]);
3212 fprintf(stdout
, "\n");
3217 EVP_CIPHER_CTX_free(ctx
);