2 * Copyright 1995-2019 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
17 #define EdDSA_SECONDS 10
25 #include <openssl/crypto.h>
26 #include <openssl/rand.h>
27 #include <openssl/err.h>
28 #include <openssl/evp.h>
29 #include <openssl/objects.h>
30 #include <openssl/async.h>
31 #if !defined(OPENSSL_SYS_MSDOS)
32 # include OPENSSL_UNISTD
39 #include <openssl/bn.h>
40 #ifndef OPENSSL_NO_DES
41 # include <openssl/des.h>
43 #include <openssl/aes.h>
44 #ifndef OPENSSL_NO_CAMELLIA
45 # include <openssl/camellia.h>
47 #ifndef OPENSSL_NO_MD2
48 # include <openssl/md2.h>
50 #ifndef OPENSSL_NO_MDC2
51 # include <openssl/mdc2.h>
53 #ifndef OPENSSL_NO_MD4
54 # include <openssl/md4.h>
56 #ifndef OPENSSL_NO_MD5
57 # include <openssl/md5.h>
59 #include <openssl/hmac.h>
60 #include <openssl/sha.h>
61 #ifndef OPENSSL_NO_RMD160
62 # include <openssl/ripemd.h>
64 #ifndef OPENSSL_NO_WHIRLPOOL
65 # include <openssl/whrlpool.h>
67 #ifndef OPENSSL_NO_RC4
68 # include <openssl/rc4.h>
70 #ifndef OPENSSL_NO_RC5
71 # include <openssl/rc5.h>
73 #ifndef OPENSSL_NO_RC2
74 # include <openssl/rc2.h>
76 #ifndef OPENSSL_NO_IDEA
77 # include <openssl/idea.h>
79 #ifndef OPENSSL_NO_SEED
80 # include <openssl/seed.h>
83 # include <openssl/blowfish.h>
85 #ifndef OPENSSL_NO_CAST
86 # include <openssl/cast.h>
88 #ifndef OPENSSL_NO_RSA
89 # include <openssl/rsa.h>
90 # include "./testrsa.h"
92 #include <openssl/x509.h>
93 #ifndef OPENSSL_NO_DSA
94 # include <openssl/dsa.h>
95 # include "./testdsa.h"
98 # include <openssl/ec.h>
100 #include <openssl/modes.h>
103 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
116 #define MAX_MISALIGNMENT 63
117 #define MAX_ECDH_SIZE 256
120 typedef struct openssl_speed_sec_st
{
127 } openssl_speed_sec_t
;
129 static volatile int run
= 0;
132 static int usertime
= 1;
134 #ifndef OPENSSL_NO_MD2
135 static int EVP_Digest_MD2_loop(void *args
);
138 #ifndef OPENSSL_NO_MDC2
139 static int EVP_Digest_MDC2_loop(void *args
);
141 #ifndef OPENSSL_NO_MD4
142 static int EVP_Digest_MD4_loop(void *args
);
144 #ifndef OPENSSL_NO_MD5
145 static int MD5_loop(void *args
);
146 static int HMAC_loop(void *args
);
148 static int SHA1_loop(void *args
);
149 static int SHA256_loop(void *args
);
150 static int SHA512_loop(void *args
);
151 #ifndef OPENSSL_NO_WHIRLPOOL
152 static int WHIRLPOOL_loop(void *args
);
154 #ifndef OPENSSL_NO_RMD160
155 static int EVP_Digest_RMD160_loop(void *args
);
157 #ifndef OPENSSL_NO_RC4
158 static int RC4_loop(void *args
);
160 #ifndef OPENSSL_NO_DES
161 static int DES_ncbc_encrypt_loop(void *args
);
162 static int DES_ede3_cbc_encrypt_loop(void *args
);
164 static int AES_cbc_128_encrypt_loop(void *args
);
165 static int AES_cbc_192_encrypt_loop(void *args
);
166 static int AES_ige_128_encrypt_loop(void *args
);
167 static int AES_cbc_256_encrypt_loop(void *args
);
168 static int AES_ige_192_encrypt_loop(void *args
);
169 static int AES_ige_256_encrypt_loop(void *args
);
170 static int CRYPTO_gcm128_aad_loop(void *args
);
171 static int RAND_bytes_loop(void *args
);
172 static int EVP_Update_loop(void *args
);
173 static int EVP_Update_loop_ccm(void *args
);
174 static int EVP_Update_loop_aead(void *args
);
175 static int EVP_Digest_loop(void *args
);
176 #ifndef OPENSSL_NO_RSA
177 static int RSA_sign_loop(void *args
);
178 static int RSA_verify_loop(void *args
);
180 #ifndef OPENSSL_NO_DSA
181 static int DSA_sign_loop(void *args
);
182 static int DSA_verify_loop(void *args
);
184 #ifndef OPENSSL_NO_EC
185 static int ECDSA_sign_loop(void *args
);
186 static int ECDSA_verify_loop(void *args
);
187 static int EdDSA_sign_loop(void *args
);
188 static int EdDSA_verify_loop(void *args
);
191 static double Time_F(int s
);
192 static void print_message(const char *s
, long num
, int length
, int tm
);
193 static void pkey_print_message(const char *str
, const char *str2
,
194 long num
, unsigned int bits
, int sec
);
195 static void print_result(int alg
, int run_no
, int count
, double time_used
);
197 static int do_multi(int multi
, int size_num
);
200 static const int lengths_list
[] = {
201 16, 64, 256, 1024, 8 * 1024, 16 * 1024
203 static const int *lengths
= lengths_list
;
205 static const int aead_lengths_list
[] = {
206 2, 31, 136, 1024, 8 * 1024, 16 * 1024
214 static void alarmed(int sig
)
216 signal(SIGALRM
, alarmed
);
220 static double Time_F(int s
)
222 double ret
= app_tminterval(s
, usertime
);
228 #elif defined(_WIN32)
232 static unsigned int lapse
;
233 static volatile unsigned int schlock
;
234 static void alarm_win32(unsigned int secs
)
239 # define alarm alarm_win32
241 static DWORD WINAPI
sleepy(VOID
* arg
)
249 static double Time_F(int s
)
256 thr
= CreateThread(NULL
, 4096, sleepy
, NULL
, 0, NULL
);
258 DWORD err
= GetLastError();
259 BIO_printf(bio_err
, "unable to CreateThread (%lu)", err
);
263 Sleep(0); /* scheduler spinlock */
264 ret
= app_tminterval(s
, usertime
);
266 ret
= app_tminterval(s
, usertime
);
268 TerminateThread(thr
, 0);
275 static double Time_F(int s
)
277 return app_tminterval(s
, usertime
);
281 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
, int lengths_single
,
282 const openssl_speed_sec_t
*seconds
);
284 #define found(value, pairs, result)\
285 opt_found(value, result, pairs, OSSL_NELEM(pairs))
286 static int opt_found(const char *name
, unsigned int *result
,
287 const OPT_PAIR pairs
[], unsigned int nbelem
)
291 for (idx
= 0; idx
< nbelem
; ++idx
, pairs
++)
292 if (strcmp(name
, pairs
->name
) == 0) {
293 *result
= pairs
->retval
;
299 typedef enum OPTION_choice
{
300 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
301 OPT_ELAPSED
, OPT_EVP
, OPT_DECRYPT
, OPT_ENGINE
, OPT_MULTI
,
302 OPT_MR
, OPT_MB
, OPT_MISALIGN
, OPT_ASYNCJOBS
, OPT_R_ENUM
,
303 OPT_PRIMES
, OPT_SECONDS
, OPT_BYTES
, OPT_AEAD
306 const OPTIONS speed_options
[] = {
307 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] ciphers...\n"},
308 {OPT_HELP_STR
, 1, '-', "Valid options are:\n"},
309 {"help", OPT_HELP
, '-', "Display this summary"},
310 {"evp", OPT_EVP
, 's', "Use EVP-named cipher or digest"},
311 {"decrypt", OPT_DECRYPT
, '-',
312 "Time decryption instead of encryption (only EVP)"},
313 {"aead", OPT_AEAD
, '-',
314 "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
316 "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
317 {"mr", OPT_MR
, '-', "Produce machine readable output"},
319 {"multi", OPT_MULTI
, 'p', "Run benchmarks in parallel"},
321 #ifndef OPENSSL_NO_ASYNC
322 {"async_jobs", OPT_ASYNCJOBS
, 'p',
323 "Enable async mode and start specified number of jobs"},
326 #ifndef OPENSSL_NO_ENGINE
327 {"engine", OPT_ENGINE
, 's', "Use engine, possibly a hardware device"},
329 {"elapsed", OPT_ELAPSED
, '-',
330 "Use wall-clock time instead of CPU user time as divisor"},
331 {"primes", OPT_PRIMES
, 'p', "Specify number of primes (for RSA only)"},
332 {"seconds", OPT_SECONDS
, 'p',
333 "Run benchmarks for specified amount of seconds"},
334 {"bytes", OPT_BYTES
, 'p',
335 "Run [non-PKI] benchmarks on custom-sized buffer"},
336 {"misalign", OPT_MISALIGN
, 'p',
337 "Use specified offset to mis-align buffers"},
351 #define D_CBC_IDEA 10
352 #define D_CBC_SEED 11
356 #define D_CBC_CAST 15
357 #define D_CBC_128_AES 16
358 #define D_CBC_192_AES 17
359 #define D_CBC_256_AES 18
360 #define D_CBC_128_CML 19
361 #define D_CBC_192_CML 20
362 #define D_CBC_256_CML 21
366 #define D_WHIRLPOOL 25
367 #define D_IGE_128_AES 26
368 #define D_IGE_192_AES 27
369 #define D_IGE_256_AES 28
372 /* name of algorithms to test */
373 static const char *names
[] = {
374 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
375 "des cbc", "des ede3", "idea cbc", "seed cbc",
376 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
377 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
378 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
379 "evp", "sha256", "sha512", "whirlpool",
380 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
383 #define ALGOR_NUM OSSL_NELEM(names)
385 /* list of configured algorithm (remaining) */
386 static const OPT_PAIR doit_choices
[] = {
387 #ifndef OPENSSL_NO_MD2
390 #ifndef OPENSSL_NO_MDC2
393 #ifndef OPENSSL_NO_MD4
396 #ifndef OPENSSL_NO_MD5
401 {"sha256", D_SHA256
},
402 {"sha512", D_SHA512
},
403 #ifndef OPENSSL_NO_WHIRLPOOL
404 {"whirlpool", D_WHIRLPOOL
},
406 #ifndef OPENSSL_NO_RMD160
407 {"ripemd", D_RMD160
},
408 {"rmd160", D_RMD160
},
409 {"ripemd160", D_RMD160
},
411 #ifndef OPENSSL_NO_RC4
414 #ifndef OPENSSL_NO_DES
415 {"des-cbc", D_CBC_DES
},
416 {"des-ede3", D_EDE3_DES
},
418 {"aes-128-cbc", D_CBC_128_AES
},
419 {"aes-192-cbc", D_CBC_192_AES
},
420 {"aes-256-cbc", D_CBC_256_AES
},
421 {"aes-128-ige", D_IGE_128_AES
},
422 {"aes-192-ige", D_IGE_192_AES
},
423 {"aes-256-ige", D_IGE_256_AES
},
424 #ifndef OPENSSL_NO_RC2
425 {"rc2-cbc", D_CBC_RC2
},
428 #ifndef OPENSSL_NO_RC5
429 {"rc5-cbc", D_CBC_RC5
},
432 #ifndef OPENSSL_NO_IDEA
433 {"idea-cbc", D_CBC_IDEA
},
434 {"idea", D_CBC_IDEA
},
436 #ifndef OPENSSL_NO_SEED
437 {"seed-cbc", D_CBC_SEED
},
438 {"seed", D_CBC_SEED
},
440 #ifndef OPENSSL_NO_BF
441 {"bf-cbc", D_CBC_BF
},
442 {"blowfish", D_CBC_BF
},
445 #ifndef OPENSSL_NO_CAST
446 {"cast-cbc", D_CBC_CAST
},
447 {"cast", D_CBC_CAST
},
448 {"cast5", D_CBC_CAST
},
454 static double results
[ALGOR_NUM
][OSSL_NELEM(lengths_list
)];
456 #ifndef OPENSSL_NO_DSA
458 # define R_DSA_1024 1
459 # define R_DSA_2048 2
460 static const OPT_PAIR dsa_choices
[] = {
461 {"dsa512", R_DSA_512
},
462 {"dsa1024", R_DSA_1024
},
463 {"dsa2048", R_DSA_2048
}
465 # define DSA_NUM OSSL_NELEM(dsa_choices)
467 static double dsa_results
[DSA_NUM
][2]; /* 2 ops: sign then verify */
468 #endif /* OPENSSL_NO_DSA */
476 #define R_RSA_15360 6
477 #ifndef OPENSSL_NO_RSA
478 static const OPT_PAIR rsa_choices
[] = {
479 {"rsa512", R_RSA_512
},
480 {"rsa1024", R_RSA_1024
},
481 {"rsa2048", R_RSA_2048
},
482 {"rsa3072", R_RSA_3072
},
483 {"rsa4096", R_RSA_4096
},
484 {"rsa7680", R_RSA_7680
},
485 {"rsa15360", R_RSA_15360
}
487 # define RSA_NUM OSSL_NELEM(rsa_choices)
489 static double rsa_results
[RSA_NUM
][2]; /* 2 ops: sign then verify */
490 #endif /* OPENSSL_NO_RSA */
499 #ifndef OPENSSL_NO_EC2M
521 #ifndef OPENSSL_NO_EC
522 static OPT_PAIR ecdsa_choices
[] = {
523 {"ecdsap160", R_EC_P160
},
524 {"ecdsap192", R_EC_P192
},
525 {"ecdsap224", R_EC_P224
},
526 {"ecdsap256", R_EC_P256
},
527 {"ecdsap384", R_EC_P384
},
528 {"ecdsap521", R_EC_P521
},
529 # ifndef OPENSSL_NO_EC2M
530 {"ecdsak163", R_EC_K163
},
531 {"ecdsak233", R_EC_K233
},
532 {"ecdsak283", R_EC_K283
},
533 {"ecdsak409", R_EC_K409
},
534 {"ecdsak571", R_EC_K571
},
535 {"ecdsab163", R_EC_B163
},
536 {"ecdsab233", R_EC_B233
},
537 {"ecdsab283", R_EC_B283
},
538 {"ecdsab409", R_EC_B409
},
539 {"ecdsab571", R_EC_B571
},
541 {"ecdsabrp256r1", R_EC_BRP256R1
},
542 {"ecdsabrp256t1", R_EC_BRP256T1
},
543 {"ecdsabrp384r1", R_EC_BRP384R1
},
544 {"ecdsabrp384t1", R_EC_BRP384T1
},
545 {"ecdsabrp512r1", R_EC_BRP512R1
},
546 {"ecdsabrp512t1", R_EC_BRP512T1
}
548 # define ECDSA_NUM OSSL_NELEM(ecdsa_choices)
550 static double ecdsa_results
[ECDSA_NUM
][2]; /* 2 ops: sign then verify */
552 static const OPT_PAIR ecdh_choices
[] = {
553 {"ecdhp160", R_EC_P160
},
554 {"ecdhp192", R_EC_P192
},
555 {"ecdhp224", R_EC_P224
},
556 {"ecdhp256", R_EC_P256
},
557 {"ecdhp384", R_EC_P384
},
558 {"ecdhp521", R_EC_P521
},
559 # ifndef OPENSSL_NO_EC2M
560 {"ecdhk163", R_EC_K163
},
561 {"ecdhk233", R_EC_K233
},
562 {"ecdhk283", R_EC_K283
},
563 {"ecdhk409", R_EC_K409
},
564 {"ecdhk571", R_EC_K571
},
565 {"ecdhb163", R_EC_B163
},
566 {"ecdhb233", R_EC_B233
},
567 {"ecdhb283", R_EC_B283
},
568 {"ecdhb409", R_EC_B409
},
569 {"ecdhb571", R_EC_B571
},
571 {"ecdhbrp256r1", R_EC_BRP256R1
},
572 {"ecdhbrp256t1", R_EC_BRP256T1
},
573 {"ecdhbrp384r1", R_EC_BRP384R1
},
574 {"ecdhbrp384t1", R_EC_BRP384T1
},
575 {"ecdhbrp512r1", R_EC_BRP512R1
},
576 {"ecdhbrp512t1", R_EC_BRP512T1
},
577 {"ecdhx25519", R_EC_X25519
},
578 {"ecdhx448", R_EC_X448
}
580 # define EC_NUM OSSL_NELEM(ecdh_choices)
582 static double ecdh_results
[EC_NUM
][1]; /* 1 op: derivation */
584 #define R_EC_Ed25519 0
586 static OPT_PAIR eddsa_choices
[] = {
587 {"ed25519", R_EC_Ed25519
},
588 {"ed448", R_EC_Ed448
}
590 # define EdDSA_NUM OSSL_NELEM(eddsa_choices)
592 static double eddsa_results
[EdDSA_NUM
][2]; /* 2 ops: sign then verify */
593 #endif /* OPENSSL_NO_EC */
596 # define COND(d) (count < (d))
597 # define COUNT(d) (d)
599 # define COND(unused_cond) (run && count<0x7fffffff)
600 # define COUNT(d) (count)
603 typedef struct loopargs_st
{
604 ASYNC_JOB
*inprogress_job
;
605 ASYNC_WAIT_CTX
*wait_ctx
;
608 unsigned char *buf_malloc
;
609 unsigned char *buf2_malloc
;
613 #ifndef OPENSSL_NO_RSA
614 RSA
*rsa_key
[RSA_NUM
];
616 #ifndef OPENSSL_NO_DSA
617 DSA
*dsa_key
[DSA_NUM
];
619 #ifndef OPENSSL_NO_EC
620 EC_KEY
*ecdsa
[ECDSA_NUM
];
621 EVP_PKEY_CTX
*ecdh_ctx
[EC_NUM
];
622 EVP_MD_CTX
*eddsa_ctx
[EdDSA_NUM
];
623 unsigned char *secret_a
;
624 unsigned char *secret_b
;
625 size_t outlen
[EC_NUM
];
629 GCM128_CONTEXT
*gcm_ctx
;
631 static int run_benchmark(int async_jobs
, int (*loop_function
) (void *),
632 loopargs_t
* loopargs
);
634 static unsigned int testnum
;
636 /* Nb of iterations to do per algorithm and key-size */
637 static long c
[ALGOR_NUM
][OSSL_NELEM(lengths_list
)];
639 #ifndef OPENSSL_NO_MD2
640 static int EVP_Digest_MD2_loop(void *args
)
642 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
643 unsigned char *buf
= tempargs
->buf
;
644 unsigned char md2
[MD2_DIGEST_LENGTH
];
647 for (count
= 0; COND(c
[D_MD2
][testnum
]); count
++) {
648 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md2
, NULL
, EVP_md2(),
656 #ifndef OPENSSL_NO_MDC2
657 static int EVP_Digest_MDC2_loop(void *args
)
659 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
660 unsigned char *buf
= tempargs
->buf
;
661 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
664 for (count
= 0; COND(c
[D_MDC2
][testnum
]); count
++) {
665 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], mdc2
, NULL
, EVP_mdc2(),
673 #ifndef OPENSSL_NO_MD4
674 static int EVP_Digest_MD4_loop(void *args
)
676 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
677 unsigned char *buf
= tempargs
->buf
;
678 unsigned char md4
[MD4_DIGEST_LENGTH
];
681 for (count
= 0; COND(c
[D_MD4
][testnum
]); count
++) {
682 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], md4
, NULL
, EVP_md4(),
690 #ifndef OPENSSL_NO_MD5
691 static int MD5_loop(void *args
)
693 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
694 unsigned char *buf
= tempargs
->buf
;
695 unsigned char md5
[MD5_DIGEST_LENGTH
];
697 for (count
= 0; COND(c
[D_MD5
][testnum
]); count
++)
698 MD5(buf
, lengths
[testnum
], md5
);
702 static int HMAC_loop(void *args
)
704 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
705 unsigned char *buf
= tempargs
->buf
;
706 HMAC_CTX
*hctx
= tempargs
->hctx
;
707 unsigned char hmac
[MD5_DIGEST_LENGTH
];
710 for (count
= 0; COND(c
[D_HMAC
][testnum
]); count
++) {
711 HMAC_Init_ex(hctx
, NULL
, 0, NULL
, NULL
);
712 HMAC_Update(hctx
, buf
, lengths
[testnum
]);
713 HMAC_Final(hctx
, hmac
, NULL
);
719 static int SHA1_loop(void *args
)
721 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
722 unsigned char *buf
= tempargs
->buf
;
723 unsigned char sha
[SHA_DIGEST_LENGTH
];
725 for (count
= 0; COND(c
[D_SHA1
][testnum
]); count
++)
726 SHA1(buf
, lengths
[testnum
], sha
);
730 static int SHA256_loop(void *args
)
732 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
733 unsigned char *buf
= tempargs
->buf
;
734 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
736 for (count
= 0; COND(c
[D_SHA256
][testnum
]); count
++)
737 SHA256(buf
, lengths
[testnum
], sha256
);
741 static int SHA512_loop(void *args
)
743 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
744 unsigned char *buf
= tempargs
->buf
;
745 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
747 for (count
= 0; COND(c
[D_SHA512
][testnum
]); count
++)
748 SHA512(buf
, lengths
[testnum
], sha512
);
752 #ifndef OPENSSL_NO_WHIRLPOOL
753 static int WHIRLPOOL_loop(void *args
)
755 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
756 unsigned char *buf
= tempargs
->buf
;
757 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
759 for (count
= 0; COND(c
[D_WHIRLPOOL
][testnum
]); count
++)
760 WHIRLPOOL(buf
, lengths
[testnum
], whirlpool
);
765 #ifndef OPENSSL_NO_RMD160
766 static int EVP_Digest_RMD160_loop(void *args
)
768 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
769 unsigned char *buf
= tempargs
->buf
;
770 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
772 for (count
= 0; COND(c
[D_RMD160
][testnum
]); count
++) {
773 if (!EVP_Digest(buf
, (size_t)lengths
[testnum
], &(rmd160
[0]),
774 NULL
, EVP_ripemd160(), NULL
))
781 #ifndef OPENSSL_NO_RC4
782 static RC4_KEY rc4_ks
;
783 static int RC4_loop(void *args
)
785 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
786 unsigned char *buf
= tempargs
->buf
;
788 for (count
= 0; COND(c
[D_RC4
][testnum
]); count
++)
789 RC4(&rc4_ks
, (size_t)lengths
[testnum
], buf
, buf
);
794 #ifndef OPENSSL_NO_DES
795 static unsigned char DES_iv
[8];
796 static DES_key_schedule sch
;
797 static DES_key_schedule sch2
;
798 static DES_key_schedule sch3
;
799 static int DES_ncbc_encrypt_loop(void *args
)
801 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
802 unsigned char *buf
= tempargs
->buf
;
804 for (count
= 0; COND(c
[D_CBC_DES
][testnum
]); count
++)
805 DES_ncbc_encrypt(buf
, buf
, lengths
[testnum
], &sch
,
806 &DES_iv
, DES_ENCRYPT
);
810 static int DES_ede3_cbc_encrypt_loop(void *args
)
812 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
813 unsigned char *buf
= tempargs
->buf
;
815 for (count
= 0; COND(c
[D_EDE3_DES
][testnum
]); count
++)
816 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[testnum
],
817 &sch
, &sch2
, &sch3
, &DES_iv
, DES_ENCRYPT
);
822 #define MAX_BLOCK_SIZE 128
824 static unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
825 static AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
826 static int AES_cbc_128_encrypt_loop(void *args
)
828 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
829 unsigned char *buf
= tempargs
->buf
;
831 for (count
= 0; COND(c
[D_CBC_128_AES
][testnum
]); count
++)
832 AES_cbc_encrypt(buf
, buf
,
833 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
837 static int AES_cbc_192_encrypt_loop(void *args
)
839 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
840 unsigned char *buf
= tempargs
->buf
;
842 for (count
= 0; COND(c
[D_CBC_192_AES
][testnum
]); count
++)
843 AES_cbc_encrypt(buf
, buf
,
844 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
848 static int AES_cbc_256_encrypt_loop(void *args
)
850 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
851 unsigned char *buf
= tempargs
->buf
;
853 for (count
= 0; COND(c
[D_CBC_256_AES
][testnum
]); count
++)
854 AES_cbc_encrypt(buf
, buf
,
855 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
859 static int AES_ige_128_encrypt_loop(void *args
)
861 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
862 unsigned char *buf
= tempargs
->buf
;
863 unsigned char *buf2
= tempargs
->buf2
;
865 for (count
= 0; COND(c
[D_IGE_128_AES
][testnum
]); count
++)
866 AES_ige_encrypt(buf
, buf2
,
867 (size_t)lengths
[testnum
], &aes_ks1
, iv
, AES_ENCRYPT
);
871 static int AES_ige_192_encrypt_loop(void *args
)
873 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
874 unsigned char *buf
= tempargs
->buf
;
875 unsigned char *buf2
= tempargs
->buf2
;
877 for (count
= 0; COND(c
[D_IGE_192_AES
][testnum
]); count
++)
878 AES_ige_encrypt(buf
, buf2
,
879 (size_t)lengths
[testnum
], &aes_ks2
, iv
, AES_ENCRYPT
);
883 static int AES_ige_256_encrypt_loop(void *args
)
885 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
886 unsigned char *buf
= tempargs
->buf
;
887 unsigned char *buf2
= tempargs
->buf2
;
889 for (count
= 0; COND(c
[D_IGE_256_AES
][testnum
]); count
++)
890 AES_ige_encrypt(buf
, buf2
,
891 (size_t)lengths
[testnum
], &aes_ks3
, iv
, AES_ENCRYPT
);
895 static int CRYPTO_gcm128_aad_loop(void *args
)
897 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
898 unsigned char *buf
= tempargs
->buf
;
899 GCM128_CONTEXT
*gcm_ctx
= tempargs
->gcm_ctx
;
901 for (count
= 0; COND(c
[D_GHASH
][testnum
]); count
++)
902 CRYPTO_gcm128_aad(gcm_ctx
, buf
, lengths
[testnum
]);
906 static int RAND_bytes_loop(void *args
)
908 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
909 unsigned char *buf
= tempargs
->buf
;
912 for (count
= 0; COND(c
[D_RAND
][testnum
]); count
++)
913 RAND_bytes(buf
, lengths
[testnum
]);
917 static long save_count
= 0;
918 static int decrypt
= 0;
919 static int EVP_Update_loop(void *args
)
921 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
922 unsigned char *buf
= tempargs
->buf
;
923 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
926 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
929 for (count
= 0; COND(nb_iter
); count
++) {
930 rc
= EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
932 /* reset iv in case of counter overflow */
933 EVP_CipherInit_ex(ctx
, NULL
, NULL
, NULL
, iv
, -1);
937 for (count
= 0; COND(nb_iter
); count
++) {
938 rc
= EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
940 /* reset iv in case of counter overflow */
941 EVP_CipherInit_ex(ctx
, NULL
, NULL
, NULL
, iv
, -1);
946 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
948 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
953 * CCM does not support streaming. For the purpose of performance measurement,
954 * each message is encrypted using the same (key,iv)-pair. Do not use this
955 * code in your application.
957 static int EVP_Update_loop_ccm(void *args
)
959 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
960 unsigned char *buf
= tempargs
->buf
;
961 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
963 unsigned char tag
[12];
965 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
968 for (count
= 0; COND(nb_iter
); count
++) {
969 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_TAG
, sizeof(tag
), tag
);
971 EVP_DecryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
972 /* counter is reset on every update */
973 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
976 for (count
= 0; COND(nb_iter
); count
++) {
977 /* restore iv length field */
978 EVP_EncryptUpdate(ctx
, NULL
, &outl
, NULL
, lengths
[testnum
]);
979 /* counter is reset on every update */
980 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
984 EVP_DecryptFinal_ex(ctx
, buf
, &outl
);
986 EVP_EncryptFinal_ex(ctx
, buf
, &outl
);
991 * To make AEAD benchmarking more relevant perform TLS-like operations,
992 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
993 * payload length is not actually limited by 16KB...
995 static int EVP_Update_loop_aead(void *args
)
997 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
998 unsigned char *buf
= tempargs
->buf
;
999 EVP_CIPHER_CTX
*ctx
= tempargs
->ctx
;
1001 unsigned char aad
[13] = { 0xcc };
1002 unsigned char faketag
[16] = { 0xcc };
1004 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
1007 for (count
= 0; COND(nb_iter
); count
++) {
1008 EVP_DecryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
1009 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_TAG
,
1010 sizeof(faketag
), faketag
);
1011 EVP_DecryptUpdate(ctx
, NULL
, &outl
, aad
, sizeof(aad
));
1012 EVP_DecryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
1013 EVP_DecryptFinal_ex(ctx
, buf
+ outl
, &outl
);
1016 for (count
= 0; COND(nb_iter
); count
++) {
1017 EVP_EncryptInit_ex(ctx
, NULL
, NULL
, NULL
, iv
);
1018 EVP_EncryptUpdate(ctx
, NULL
, &outl
, aad
, sizeof(aad
));
1019 EVP_EncryptUpdate(ctx
, buf
, &outl
, buf
, lengths
[testnum
]);
1020 EVP_EncryptFinal_ex(ctx
, buf
+ outl
, &outl
);
1026 static const EVP_MD
*evp_md
= NULL
;
1027 static int EVP_Digest_loop(void *args
)
1029 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1030 unsigned char *buf
= tempargs
->buf
;
1031 unsigned char md
[EVP_MAX_MD_SIZE
];
1034 int nb_iter
= save_count
* 4 * lengths
[0] / lengths
[testnum
];
1037 for (count
= 0; COND(nb_iter
); count
++) {
1038 if (!EVP_Digest(buf
, lengths
[testnum
], md
, NULL
, evp_md
, NULL
))
1044 #ifndef OPENSSL_NO_RSA
1045 static long rsa_c
[RSA_NUM
][2]; /* # RSA iteration test */
1047 static int RSA_sign_loop(void *args
)
1049 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1050 unsigned char *buf
= tempargs
->buf
;
1051 unsigned char *buf2
= tempargs
->buf2
;
1052 unsigned int *rsa_num
= &tempargs
->siglen
;
1053 RSA
**rsa_key
= tempargs
->rsa_key
;
1055 for (count
= 0; COND(rsa_c
[testnum
][0]); count
++) {
1056 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
1058 BIO_printf(bio_err
, "RSA sign failure\n");
1059 ERR_print_errors(bio_err
);
1067 static int RSA_verify_loop(void *args
)
1069 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1070 unsigned char *buf
= tempargs
->buf
;
1071 unsigned char *buf2
= tempargs
->buf2
;
1072 unsigned int rsa_num
= tempargs
->siglen
;
1073 RSA
**rsa_key
= tempargs
->rsa_key
;
1075 for (count
= 0; COND(rsa_c
[testnum
][1]); count
++) {
1077 RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[testnum
]);
1079 BIO_printf(bio_err
, "RSA verify failure\n");
1080 ERR_print_errors(bio_err
);
1089 #ifndef OPENSSL_NO_DSA
1090 static long dsa_c
[DSA_NUM
][2];
1091 static int DSA_sign_loop(void *args
)
1093 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1094 unsigned char *buf
= tempargs
->buf
;
1095 unsigned char *buf2
= tempargs
->buf2
;
1096 DSA
**dsa_key
= tempargs
->dsa_key
;
1097 unsigned int *siglen
= &tempargs
->siglen
;
1099 for (count
= 0; COND(dsa_c
[testnum
][0]); count
++) {
1100 ret
= DSA_sign(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
1102 BIO_printf(bio_err
, "DSA sign failure\n");
1103 ERR_print_errors(bio_err
);
1111 static int DSA_verify_loop(void *args
)
1113 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1114 unsigned char *buf
= tempargs
->buf
;
1115 unsigned char *buf2
= tempargs
->buf2
;
1116 DSA
**dsa_key
= tempargs
->dsa_key
;
1117 unsigned int siglen
= tempargs
->siglen
;
1119 for (count
= 0; COND(dsa_c
[testnum
][1]); count
++) {
1120 ret
= DSA_verify(0, buf
, 20, buf2
, siglen
, dsa_key
[testnum
]);
1122 BIO_printf(bio_err
, "DSA verify failure\n");
1123 ERR_print_errors(bio_err
);
1132 #ifndef OPENSSL_NO_EC
1133 static long ecdsa_c
[ECDSA_NUM
][2];
1134 static int ECDSA_sign_loop(void *args
)
1136 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1137 unsigned char *buf
= tempargs
->buf
;
1138 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1139 unsigned char *ecdsasig
= tempargs
->buf2
;
1140 unsigned int *ecdsasiglen
= &tempargs
->siglen
;
1142 for (count
= 0; COND(ecdsa_c
[testnum
][0]); count
++) {
1143 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1145 BIO_printf(bio_err
, "ECDSA sign failure\n");
1146 ERR_print_errors(bio_err
);
1154 static int ECDSA_verify_loop(void *args
)
1156 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1157 unsigned char *buf
= tempargs
->buf
;
1158 EC_KEY
**ecdsa
= tempargs
->ecdsa
;
1159 unsigned char *ecdsasig
= tempargs
->buf2
;
1160 unsigned int ecdsasiglen
= tempargs
->siglen
;
1162 for (count
= 0; COND(ecdsa_c
[testnum
][1]); count
++) {
1163 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[testnum
]);
1165 BIO_printf(bio_err
, "ECDSA verify failure\n");
1166 ERR_print_errors(bio_err
);
1174 /* ******************************************************************** */
1175 static long ecdh_c
[EC_NUM
][1];
1177 static int ECDH_EVP_derive_key_loop(void *args
)
1179 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1180 EVP_PKEY_CTX
*ctx
= tempargs
->ecdh_ctx
[testnum
];
1181 unsigned char *derived_secret
= tempargs
->secret_a
;
1183 size_t *outlen
= &(tempargs
->outlen
[testnum
]);
1185 for (count
= 0; COND(ecdh_c
[testnum
][0]); count
++)
1186 EVP_PKEY_derive(ctx
, derived_secret
, outlen
);
1191 static long eddsa_c
[EdDSA_NUM
][2];
1192 static int EdDSA_sign_loop(void *args
)
1194 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1195 unsigned char *buf
= tempargs
->buf
;
1196 EVP_MD_CTX
**edctx
= tempargs
->eddsa_ctx
;
1197 unsigned char *eddsasig
= tempargs
->buf2
;
1198 size_t *eddsasigsize
= &tempargs
->sigsize
;
1201 for (count
= 0; COND(eddsa_c
[testnum
][0]); count
++) {
1202 ret
= EVP_DigestSign(edctx
[testnum
], eddsasig
, eddsasigsize
, buf
, 20);
1204 BIO_printf(bio_err
, "EdDSA sign failure\n");
1205 ERR_print_errors(bio_err
);
1213 static int EdDSA_verify_loop(void *args
)
1215 loopargs_t
*tempargs
= *(loopargs_t
**) args
;
1216 unsigned char *buf
= tempargs
->buf
;
1217 EVP_MD_CTX
**edctx
= tempargs
->eddsa_ctx
;
1218 unsigned char *eddsasig
= tempargs
->buf2
;
1219 size_t eddsasigsize
= tempargs
->sigsize
;
1222 for (count
= 0; COND(eddsa_c
[testnum
][1]); count
++) {
1223 ret
= EVP_DigestVerify(edctx
[testnum
], eddsasig
, eddsasigsize
, buf
, 20);
1225 BIO_printf(bio_err
, "EdDSA verify failure\n");
1226 ERR_print_errors(bio_err
);
1233 #endif /* OPENSSL_NO_EC */
1235 static int run_benchmark(int async_jobs
,
1236 int (*loop_function
) (void *), loopargs_t
* loopargs
)
1238 int job_op_count
= 0;
1239 int total_op_count
= 0;
1240 int num_inprogress
= 0;
1241 int error
= 0, i
= 0, ret
= 0;
1242 OSSL_ASYNC_FD job_fd
= 0;
1243 size_t num_job_fds
= 0;
1247 if (async_jobs
== 0) {
1248 return loop_function((void *)&loopargs
);
1251 for (i
= 0; i
< async_jobs
&& !error
; i
++) {
1252 loopargs_t
*looparg_item
= loopargs
+ i
;
1254 /* Copy pointer content (looparg_t item address) into async context */
1255 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
, loopargs
[i
].wait_ctx
,
1256 &job_op_count
, loop_function
,
1257 (void *)&looparg_item
, sizeof(looparg_item
));
1263 if (job_op_count
== -1) {
1266 total_op_count
+= job_op_count
;
1271 BIO_printf(bio_err
, "Failure in the job\n");
1272 ERR_print_errors(bio_err
);
1278 while (num_inprogress
> 0) {
1279 #if defined(OPENSSL_SYS_WINDOWS)
1281 #elif defined(OPENSSL_SYS_UNIX)
1282 int select_result
= 0;
1283 OSSL_ASYNC_FD max_fd
= 0;
1286 FD_ZERO(&waitfdset
);
1288 for (i
= 0; i
< async_jobs
&& num_inprogress
> 0; i
++) {
1289 if (loopargs
[i
].inprogress_job
== NULL
)
1292 if (!ASYNC_WAIT_CTX_get_all_fds
1293 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1294 || num_job_fds
> 1) {
1295 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1296 ERR_print_errors(bio_err
);
1300 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1302 FD_SET(job_fd
, &waitfdset
);
1303 if (job_fd
> max_fd
)
1307 if (max_fd
>= (OSSL_ASYNC_FD
)FD_SETSIZE
) {
1309 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1310 "Decrease the value of async_jobs\n",
1311 max_fd
, FD_SETSIZE
);
1312 ERR_print_errors(bio_err
);
1317 select_result
= select(max_fd
+ 1, &waitfdset
, NULL
, NULL
, NULL
);
1318 if (select_result
== -1 && errno
== EINTR
)
1321 if (select_result
== -1) {
1322 BIO_printf(bio_err
, "Failure in the select\n");
1323 ERR_print_errors(bio_err
);
1328 if (select_result
== 0)
1332 for (i
= 0; i
< async_jobs
; i
++) {
1333 if (loopargs
[i
].inprogress_job
== NULL
)
1336 if (!ASYNC_WAIT_CTX_get_all_fds
1337 (loopargs
[i
].wait_ctx
, NULL
, &num_job_fds
)
1338 || num_job_fds
> 1) {
1339 BIO_printf(bio_err
, "Too many fds in ASYNC_WAIT_CTX\n");
1340 ERR_print_errors(bio_err
);
1344 ASYNC_WAIT_CTX_get_all_fds(loopargs
[i
].wait_ctx
, &job_fd
,
1347 #if defined(OPENSSL_SYS_UNIX)
1348 if (num_job_fds
== 1 && !FD_ISSET(job_fd
, &waitfdset
))
1350 #elif defined(OPENSSL_SYS_WINDOWS)
1351 if (num_job_fds
== 1
1352 && !PeekNamedPipe(job_fd
, NULL
, 0, NULL
, &avail
, NULL
)
1357 ret
= ASYNC_start_job(&loopargs
[i
].inprogress_job
,
1358 loopargs
[i
].wait_ctx
, &job_op_count
,
1359 loop_function
, (void *)(loopargs
+ i
),
1360 sizeof(loopargs_t
));
1365 if (job_op_count
== -1) {
1368 total_op_count
+= job_op_count
;
1371 loopargs
[i
].inprogress_job
= NULL
;
1376 loopargs
[i
].inprogress_job
= NULL
;
1377 BIO_printf(bio_err
, "Failure in the job\n");
1378 ERR_print_errors(bio_err
);
1385 return error
? -1 : total_op_count
;
1388 int speed_main(int argc
, char **argv
)
1391 loopargs_t
*loopargs
= NULL
;
1393 const char *engine_id
= NULL
;
1394 const EVP_CIPHER
*evp_cipher
= NULL
;
1397 int async_init
= 0, multiblock
= 0, pr_header
= 0;
1398 int doit
[ALGOR_NUM
] = { 0 };
1399 int ret
= 1, misalign
= 0, lengths_single
= 0, aead
= 0;
1401 unsigned int size_num
= OSSL_NELEM(lengths_list
);
1402 unsigned int i
, k
, loop
, loopargs_len
= 0, async_jobs
= 0;
1408 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
1409 || !defined(OPENSSL_NO_EC)
1412 openssl_speed_sec_t seconds
= { SECONDS
, RSA_SECONDS
, DSA_SECONDS
,
1413 ECDSA_SECONDS
, ECDH_SECONDS
,
1416 /* What follows are the buffers and key material. */
1417 #ifndef OPENSSL_NO_RC5
1420 #ifndef OPENSSL_NO_RC2
1423 #ifndef OPENSSL_NO_IDEA
1424 IDEA_KEY_SCHEDULE idea_ks
;
1426 #ifndef OPENSSL_NO_SEED
1427 SEED_KEY_SCHEDULE seed_ks
;
1429 #ifndef OPENSSL_NO_BF
1432 #ifndef OPENSSL_NO_CAST
1435 static const unsigned char key16
[16] = {
1436 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1437 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1439 static const unsigned char key24
[24] = {
1440 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1441 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1442 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1444 static const unsigned char key32
[32] = {
1445 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1446 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1447 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1448 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1450 #ifndef OPENSSL_NO_CAMELLIA
1451 static const unsigned char ckey24
[24] = {
1452 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1453 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1454 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1456 static const unsigned char ckey32
[32] = {
1457 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1458 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1459 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1460 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1462 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
1464 #ifndef OPENSSL_NO_DES
1465 static DES_cblock key
= {
1466 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1468 static DES_cblock key2
= {
1469 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1471 static DES_cblock key3
= {
1472 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1475 #ifndef OPENSSL_NO_RSA
1476 static const unsigned int rsa_bits
[RSA_NUM
] = {
1477 512, 1024, 2048, 3072, 4096, 7680, 15360
1479 static const unsigned char *rsa_data
[RSA_NUM
] = {
1480 test512
, test1024
, test2048
, test3072
, test4096
, test7680
, test15360
1482 static const int rsa_data_length
[RSA_NUM
] = {
1483 sizeof(test512
), sizeof(test1024
),
1484 sizeof(test2048
), sizeof(test3072
),
1485 sizeof(test4096
), sizeof(test7680
),
1488 int rsa_doit
[RSA_NUM
] = { 0 };
1489 int primes
= RSA_DEFAULT_PRIME_NUM
;
1491 #ifndef OPENSSL_NO_DSA
1492 static const unsigned int dsa_bits
[DSA_NUM
] = { 512, 1024, 2048 };
1493 int dsa_doit
[DSA_NUM
] = { 0 };
1495 #ifndef OPENSSL_NO_EC
1497 * We only test over the following curves as they are representative, To
1498 * add tests over more curves, simply add the curve NID and curve name to
1499 * the following arrays and increase the |ecdh_choices| list accordingly.
1501 static const struct {
1507 {"secp160r1", NID_secp160r1
, 160},
1508 {"nistp192", NID_X9_62_prime192v1
, 192},
1509 {"nistp224", NID_secp224r1
, 224},
1510 {"nistp256", NID_X9_62_prime256v1
, 256},
1511 {"nistp384", NID_secp384r1
, 384},
1512 {"nistp521", NID_secp521r1
, 521},
1513 # ifndef OPENSSL_NO_EC2M
1515 {"nistk163", NID_sect163k1
, 163},
1516 {"nistk233", NID_sect233k1
, 233},
1517 {"nistk283", NID_sect283k1
, 283},
1518 {"nistk409", NID_sect409k1
, 409},
1519 {"nistk571", NID_sect571k1
, 571},
1520 {"nistb163", NID_sect163r2
, 163},
1521 {"nistb233", NID_sect233r1
, 233},
1522 {"nistb283", NID_sect283r1
, 283},
1523 {"nistb409", NID_sect409r1
, 409},
1524 {"nistb571", NID_sect571r1
, 571},
1526 {"brainpoolP256r1", NID_brainpoolP256r1
, 256},
1527 {"brainpoolP256t1", NID_brainpoolP256t1
, 256},
1528 {"brainpoolP384r1", NID_brainpoolP384r1
, 384},
1529 {"brainpoolP384t1", NID_brainpoolP384t1
, 384},
1530 {"brainpoolP512r1", NID_brainpoolP512r1
, 512},
1531 {"brainpoolP512t1", NID_brainpoolP512t1
, 512},
1532 /* Other and ECDH only ones */
1533 {"X25519", NID_X25519
, 253},
1534 {"X448", NID_X448
, 448}
1536 static const struct {
1541 } test_ed_curves
[] = {
1543 {"Ed25519", NID_ED25519
, 253, 64},
1544 {"Ed448", NID_ED448
, 456, 114}
1546 int ecdsa_doit
[ECDSA_NUM
] = { 0 };
1547 int ecdh_doit
[EC_NUM
] = { 0 };
1548 int eddsa_doit
[EdDSA_NUM
] = { 0 };
1549 OPENSSL_assert(OSSL_NELEM(test_curves
) >= EC_NUM
);
1550 OPENSSL_assert(OSSL_NELEM(test_ed_curves
) >= EdDSA_NUM
);
1551 #endif /* ndef OPENSSL_NO_EC */
1553 prog
= opt_init(argc
, argv
, speed_options
);
1554 while ((o
= opt_next()) != OPT_EOF
) {
1559 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
1562 opt_help(speed_options
);
1570 evp_cipher
= EVP_get_cipherbyname(opt_arg());
1571 if (evp_cipher
== NULL
)
1572 evp_md
= EVP_get_digestbyname(opt_arg());
1573 if (evp_cipher
== NULL
&& evp_md
== NULL
) {
1575 "%s: %s is an unknown cipher or digest\n",
1586 * In a forked execution, an engine might need to be
1587 * initialised by each child process, not by the parent.
1588 * So store the name here and run setup_engine() later on.
1590 engine_id
= opt_arg();
1594 multi
= atoi(opt_arg());
1598 #ifndef OPENSSL_NO_ASYNC
1599 async_jobs
= atoi(opt_arg());
1600 if (!ASYNC_is_capable()) {
1602 "%s: async_jobs specified but async not supported\n",
1606 if (async_jobs
> 99999) {
1607 BIO_printf(bio_err
, "%s: too many async_jobs\n", prog
);
1613 if (!opt_int(opt_arg(), &misalign
))
1615 if (misalign
> MISALIGN
) {
1617 "%s: Maximum offset is %d\n", prog
, MISALIGN
);
1626 #ifdef OPENSSL_NO_MULTIBLOCK
1628 "%s: -mb specified but multi-block support is disabled\n",
1638 if (!opt_int(opt_arg(), &primes
))
1642 seconds
.sym
= seconds
.rsa
= seconds
.dsa
= seconds
.ecdsa
1643 = seconds
.ecdh
= seconds
.eddsa
= atoi(opt_arg());
1646 lengths_single
= atoi(opt_arg());
1647 lengths
= &lengths_single
;
1655 argc
= opt_num_rest();
1658 /* Remaining arguments are algorithms. */
1659 for (; *argv
; argv
++) {
1660 if (found(*argv
, doit_choices
, &i
)) {
1664 #ifndef OPENSSL_NO_DES
1665 if (strcmp(*argv
, "des") == 0) {
1666 doit
[D_CBC_DES
] = doit
[D_EDE3_DES
] = 1;
1670 if (strcmp(*argv
, "sha") == 0) {
1671 doit
[D_SHA1
] = doit
[D_SHA256
] = doit
[D_SHA512
] = 1;
1674 #ifndef OPENSSL_NO_RSA
1675 if (strcmp(*argv
, "openssl") == 0)
1677 if (strcmp(*argv
, "rsa") == 0) {
1678 for (loop
= 0; loop
< OSSL_NELEM(rsa_doit
); loop
++)
1682 if (found(*argv
, rsa_choices
, &i
)) {
1687 #ifndef OPENSSL_NO_DSA
1688 if (strcmp(*argv
, "dsa") == 0) {
1689 dsa_doit
[R_DSA_512
] = dsa_doit
[R_DSA_1024
] =
1690 dsa_doit
[R_DSA_2048
] = 1;
1693 if (found(*argv
, dsa_choices
, &i
)) {
1698 if (strcmp(*argv
, "aes") == 0) {
1699 doit
[D_CBC_128_AES
] = doit
[D_CBC_192_AES
] = doit
[D_CBC_256_AES
] = 1;
1702 #ifndef OPENSSL_NO_CAMELLIA
1703 if (strcmp(*argv
, "camellia") == 0) {
1704 doit
[D_CBC_128_CML
] = doit
[D_CBC_192_CML
] = doit
[D_CBC_256_CML
] = 1;
1708 #ifndef OPENSSL_NO_EC
1709 if (strcmp(*argv
, "ecdsa") == 0) {
1710 for (loop
= 0; loop
< OSSL_NELEM(ecdsa_doit
); loop
++)
1711 ecdsa_doit
[loop
] = 1;
1714 if (found(*argv
, ecdsa_choices
, &i
)) {
1718 if (strcmp(*argv
, "ecdh") == 0) {
1719 for (loop
= 0; loop
< OSSL_NELEM(ecdh_doit
); loop
++)
1720 ecdh_doit
[loop
] = 1;
1723 if (found(*argv
, ecdh_choices
, &i
)) {
1727 if (strcmp(*argv
, "eddsa") == 0) {
1728 for (loop
= 0; loop
< OSSL_NELEM(eddsa_doit
); loop
++)
1729 eddsa_doit
[loop
] = 1;
1732 if (found(*argv
, eddsa_choices
, &i
)) {
1737 BIO_printf(bio_err
, "%s: Unknown algorithm %s\n", prog
, *argv
);
1743 if (evp_cipher
== NULL
) {
1744 BIO_printf(bio_err
, "-aead can be used only with an AEAD cipher\n");
1746 } else if (!(EVP_CIPHER_flags(evp_cipher
) &
1747 EVP_CIPH_FLAG_AEAD_CIPHER
)) {
1748 BIO_printf(bio_err
, "%s is not an AEAD cipher\n",
1749 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
1754 if (evp_cipher
== NULL
) {
1755 BIO_printf(bio_err
,"-mb can be used only with a multi-block"
1756 " capable cipher\n");
1758 } else if (!(EVP_CIPHER_flags(evp_cipher
) &
1759 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
1760 BIO_printf(bio_err
, "%s is not a multi-block capable\n",
1761 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
)));
1763 } else if (async_jobs
> 0) {
1764 BIO_printf(bio_err
, "Async mode is not supported with -mb");
1769 /* Initialize the job pool if async mode is enabled */
1770 if (async_jobs
> 0) {
1771 async_init
= ASYNC_init_thread(async_jobs
, async_jobs
);
1773 BIO_printf(bio_err
, "Error creating the ASYNC job pool\n");
1778 loopargs_len
= (async_jobs
== 0 ? 1 : async_jobs
);
1780 app_malloc(loopargs_len
* sizeof(loopargs_t
), "array of loopargs");
1781 memset(loopargs
, 0, loopargs_len
* sizeof(loopargs_t
));
1783 for (i
= 0; i
< loopargs_len
; i
++) {
1784 if (async_jobs
> 0) {
1785 loopargs
[i
].wait_ctx
= ASYNC_WAIT_CTX_new();
1786 if (loopargs
[i
].wait_ctx
== NULL
) {
1787 BIO_printf(bio_err
, "Error creating the ASYNC_WAIT_CTX\n");
1792 buflen
= lengths
[size_num
- 1];
1793 if (buflen
< 36) /* size of random vector in RSA benchmark */
1795 buflen
+= MAX_MISALIGNMENT
+ 1;
1796 loopargs
[i
].buf_malloc
= app_malloc(buflen
, "input buffer");
1797 loopargs
[i
].buf2_malloc
= app_malloc(buflen
, "input buffer");
1798 memset(loopargs
[i
].buf_malloc
, 0, buflen
);
1799 memset(loopargs
[i
].buf2_malloc
, 0, buflen
);
1801 /* Align the start of buffers on a 64 byte boundary */
1802 loopargs
[i
].buf
= loopargs
[i
].buf_malloc
+ misalign
;
1803 loopargs
[i
].buf2
= loopargs
[i
].buf2_malloc
+ misalign
;
1804 #ifndef OPENSSL_NO_EC
1805 loopargs
[i
].secret_a
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret a");
1806 loopargs
[i
].secret_b
= app_malloc(MAX_ECDH_SIZE
, "ECDH secret b");
1811 if (multi
&& do_multi(multi
, size_num
))
1815 /* Initialize the engine after the fork */
1816 e
= setup_engine(engine_id
, 0);
1818 /* No parameters; turn on everything. */
1819 if ((argc
== 0) && !doit
[D_EVP
]) {
1820 for (i
= 0; i
< ALGOR_NUM
; i
++)
1823 #ifndef OPENSSL_NO_RSA
1824 for (i
= 0; i
< RSA_NUM
; i
++)
1827 #ifndef OPENSSL_NO_DSA
1828 for (i
= 0; i
< DSA_NUM
; i
++)
1831 #ifndef OPENSSL_NO_EC
1832 for (loop
= 0; loop
< OSSL_NELEM(ecdsa_doit
); loop
++)
1833 ecdsa_doit
[loop
] = 1;
1834 for (loop
= 0; loop
< OSSL_NELEM(ecdh_doit
); loop
++)
1835 ecdh_doit
[loop
] = 1;
1836 for (loop
= 0; loop
< OSSL_NELEM(eddsa_doit
); loop
++)
1837 eddsa_doit
[loop
] = 1;
1840 for (i
= 0; i
< ALGOR_NUM
; i
++)
1844 if (usertime
== 0 && !mr
)
1846 "You have chosen to measure elapsed time "
1847 "instead of user CPU time.\n");
1849 #ifndef OPENSSL_NO_RSA
1850 for (i
= 0; i
< loopargs_len
; i
++) {
1851 if (primes
> RSA_DEFAULT_PRIME_NUM
) {
1852 /* for multi-prime RSA, skip this */
1855 for (k
= 0; k
< RSA_NUM
; k
++) {
1856 const unsigned char *p
;
1859 loopargs
[i
].rsa_key
[k
] =
1860 d2i_RSAPrivateKey(NULL
, &p
, rsa_data_length
[k
]);
1861 if (loopargs
[i
].rsa_key
[k
] == NULL
) {
1863 "internal error loading RSA key number %d\n", k
);
1869 #ifndef OPENSSL_NO_DSA
1870 for (i
= 0; i
< loopargs_len
; i
++) {
1871 loopargs
[i
].dsa_key
[0] = get_dsa(512);
1872 loopargs
[i
].dsa_key
[1] = get_dsa(1024);
1873 loopargs
[i
].dsa_key
[2] = get_dsa(2048);
1876 #ifndef OPENSSL_NO_DES
1877 DES_set_key_unchecked(&key
, &sch
);
1878 DES_set_key_unchecked(&key2
, &sch2
);
1879 DES_set_key_unchecked(&key3
, &sch3
);
1881 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
1882 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
1883 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
1884 #ifndef OPENSSL_NO_CAMELLIA
1885 Camellia_set_key(key16
, 128, &camellia_ks1
);
1886 Camellia_set_key(ckey24
, 192, &camellia_ks2
);
1887 Camellia_set_key(ckey32
, 256, &camellia_ks3
);
1889 #ifndef OPENSSL_NO_IDEA
1890 IDEA_set_encrypt_key(key16
, &idea_ks
);
1892 #ifndef OPENSSL_NO_SEED
1893 SEED_set_key(key16
, &seed_ks
);
1895 #ifndef OPENSSL_NO_RC4
1896 RC4_set_key(&rc4_ks
, 16, key16
);
1898 #ifndef OPENSSL_NO_RC2
1899 RC2_set_key(&rc2_ks
, 16, key16
, 128);
1901 #ifndef OPENSSL_NO_RC5
1902 RC5_32_set_key(&rc5_ks
, 16, key16
, 12);
1904 #ifndef OPENSSL_NO_BF
1905 BF_set_key(&bf_ks
, 16, key16
);
1907 #ifndef OPENSSL_NO_CAST
1908 CAST_set_key(&cast_ks
, 16, key16
);
1911 # ifndef OPENSSL_NO_DES
1912 BIO_printf(bio_err
, "First we calculate the approximate speed ...\n");
1918 for (it
= count
; it
; it
--)
1919 DES_ecb_encrypt((DES_cblock
*)loopargs
[0].buf
,
1920 (DES_cblock
*)loopargs
[0].buf
, &sch
, DES_ENCRYPT
);
1924 c
[D_MD2
][0] = count
/ 10;
1925 c
[D_MDC2
][0] = count
/ 10;
1926 c
[D_MD4
][0] = count
;
1927 c
[D_MD5
][0] = count
;
1928 c
[D_HMAC
][0] = count
;
1929 c
[D_SHA1
][0] = count
;
1930 c
[D_RMD160
][0] = count
;
1931 c
[D_RC4
][0] = count
* 5;
1932 c
[D_CBC_DES
][0] = count
;
1933 c
[D_EDE3_DES
][0] = count
/ 3;
1934 c
[D_CBC_IDEA
][0] = count
;
1935 c
[D_CBC_SEED
][0] = count
;
1936 c
[D_CBC_RC2
][0] = count
;
1937 c
[D_CBC_RC5
][0] = count
;
1938 c
[D_CBC_BF
][0] = count
;
1939 c
[D_CBC_CAST
][0] = count
;
1940 c
[D_CBC_128_AES
][0] = count
;
1941 c
[D_CBC_192_AES
][0] = count
;
1942 c
[D_CBC_256_AES
][0] = count
;
1943 c
[D_CBC_128_CML
][0] = count
;
1944 c
[D_CBC_192_CML
][0] = count
;
1945 c
[D_CBC_256_CML
][0] = count
;
1946 c
[D_SHA256
][0] = count
;
1947 c
[D_SHA512
][0] = count
;
1948 c
[D_WHIRLPOOL
][0] = count
;
1949 c
[D_IGE_128_AES
][0] = count
;
1950 c
[D_IGE_192_AES
][0] = count
;
1951 c
[D_IGE_256_AES
][0] = count
;
1952 c
[D_GHASH
][0] = count
;
1953 c
[D_RAND
][0] = count
;
1955 for (i
= 1; i
< size_num
; i
++) {
1958 l0
= (long)lengths
[0];
1959 l1
= (long)lengths
[i
];
1961 c
[D_MD2
][i
] = c
[D_MD2
][0] * 4 * l0
/ l1
;
1962 c
[D_MDC2
][i
] = c
[D_MDC2
][0] * 4 * l0
/ l1
;
1963 c
[D_MD4
][i
] = c
[D_MD4
][0] * 4 * l0
/ l1
;
1964 c
[D_MD5
][i
] = c
[D_MD5
][0] * 4 * l0
/ l1
;
1965 c
[D_HMAC
][i
] = c
[D_HMAC
][0] * 4 * l0
/ l1
;
1966 c
[D_SHA1
][i
] = c
[D_SHA1
][0] * 4 * l0
/ l1
;
1967 c
[D_RMD160
][i
] = c
[D_RMD160
][0] * 4 * l0
/ l1
;
1968 c
[D_SHA256
][i
] = c
[D_SHA256
][0] * 4 * l0
/ l1
;
1969 c
[D_SHA512
][i
] = c
[D_SHA512
][0] * 4 * l0
/ l1
;
1970 c
[D_WHIRLPOOL
][i
] = c
[D_WHIRLPOOL
][0] * 4 * l0
/ l1
;
1971 c
[D_GHASH
][i
] = c
[D_GHASH
][0] * 4 * l0
/ l1
;
1972 c
[D_RAND
][i
] = c
[D_RAND
][0] * 4 * l0
/ l1
;
1974 l0
= (long)lengths
[i
- 1];
1976 c
[D_RC4
][i
] = c
[D_RC4
][i
- 1] * l0
/ l1
;
1977 c
[D_CBC_DES
][i
] = c
[D_CBC_DES
][i
- 1] * l0
/ l1
;
1978 c
[D_EDE3_DES
][i
] = c
[D_EDE3_DES
][i
- 1] * l0
/ l1
;
1979 c
[D_CBC_IDEA
][i
] = c
[D_CBC_IDEA
][i
- 1] * l0
/ l1
;
1980 c
[D_CBC_SEED
][i
] = c
[D_CBC_SEED
][i
- 1] * l0
/ l1
;
1981 c
[D_CBC_RC2
][i
] = c
[D_CBC_RC2
][i
- 1] * l0
/ l1
;
1982 c
[D_CBC_RC5
][i
] = c
[D_CBC_RC5
][i
- 1] * l0
/ l1
;
1983 c
[D_CBC_BF
][i
] = c
[D_CBC_BF
][i
- 1] * l0
/ l1
;
1984 c
[D_CBC_CAST
][i
] = c
[D_CBC_CAST
][i
- 1] * l0
/ l1
;
1985 c
[D_CBC_128_AES
][i
] = c
[D_CBC_128_AES
][i
- 1] * l0
/ l1
;
1986 c
[D_CBC_192_AES
][i
] = c
[D_CBC_192_AES
][i
- 1] * l0
/ l1
;
1987 c
[D_CBC_256_AES
][i
] = c
[D_CBC_256_AES
][i
- 1] * l0
/ l1
;
1988 c
[D_CBC_128_CML
][i
] = c
[D_CBC_128_CML
][i
- 1] * l0
/ l1
;
1989 c
[D_CBC_192_CML
][i
] = c
[D_CBC_192_CML
][i
- 1] * l0
/ l1
;
1990 c
[D_CBC_256_CML
][i
] = c
[D_CBC_256_CML
][i
- 1] * l0
/ l1
;
1991 c
[D_IGE_128_AES
][i
] = c
[D_IGE_128_AES
][i
- 1] * l0
/ l1
;
1992 c
[D_IGE_192_AES
][i
] = c
[D_IGE_192_AES
][i
- 1] * l0
/ l1
;
1993 c
[D_IGE_256_AES
][i
] = c
[D_IGE_256_AES
][i
- 1] * l0
/ l1
;
1996 # ifndef OPENSSL_NO_RSA
1997 rsa_c
[R_RSA_512
][0] = count
/ 2000;
1998 rsa_c
[R_RSA_512
][1] = count
/ 400;
1999 for (i
= 1; i
< RSA_NUM
; i
++) {
2000 rsa_c
[i
][0] = rsa_c
[i
- 1][0] / 8;
2001 rsa_c
[i
][1] = rsa_c
[i
- 1][1] / 4;
2002 if (rsa_doit
[i
] <= 1 && rsa_c
[i
][0] == 0)
2005 if (rsa_c
[i
][0] == 0) {
2006 rsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
2013 # ifndef OPENSSL_NO_DSA
2014 dsa_c
[R_DSA_512
][0] = count
/ 1000;
2015 dsa_c
[R_DSA_512
][1] = count
/ 1000 / 2;
2016 for (i
= 1; i
< DSA_NUM
; i
++) {
2017 dsa_c
[i
][0] = dsa_c
[i
- 1][0] / 4;
2018 dsa_c
[i
][1] = dsa_c
[i
- 1][1] / 4;
2019 if (dsa_doit
[i
] <= 1 && dsa_c
[i
][0] == 0)
2022 if (dsa_c
[i
][0] == 0) {
2023 dsa_c
[i
][0] = 1; /* Set minimum iteration Nb to 1. */
2030 # ifndef OPENSSL_NO_EC
2031 ecdsa_c
[R_EC_P160
][0] = count
/ 1000;
2032 ecdsa_c
[R_EC_P160
][1] = count
/ 1000 / 2;
2033 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
2034 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2035 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2036 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2039 if (ecdsa_c
[i
][0] == 0) {
2045 # ifndef OPENSSL_NO_EC2M
2046 ecdsa_c
[R_EC_K163
][0] = count
/ 1000;
2047 ecdsa_c
[R_EC_K163
][1] = count
/ 1000 / 2;
2048 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
2049 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2050 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2051 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2054 if (ecdsa_c
[i
][0] == 0) {
2060 ecdsa_c
[R_EC_B163
][0] = count
/ 1000;
2061 ecdsa_c
[R_EC_B163
][1] = count
/ 1000 / 2;
2062 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
2063 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
2064 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
2065 if (ecdsa_doit
[i
] <= 1 && ecdsa_c
[i
][0] == 0)
2068 if (ecdsa_c
[i
][0] == 0) {
2076 ecdh_c
[R_EC_P160
][0] = count
/ 1000;
2077 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
2078 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2079 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2082 if (ecdh_c
[i
][0] == 0) {
2087 # ifndef OPENSSL_NO_EC2M
2088 ecdh_c
[R_EC_K163
][0] = count
/ 1000;
2089 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
2090 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2091 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2094 if (ecdh_c
[i
][0] == 0) {
2099 ecdh_c
[R_EC_B163
][0] = count
/ 1000;
2100 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
2101 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
2102 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2105 if (ecdh_c
[i
][0] == 0) {
2111 /* repeated code good to factorize */
2112 ecdh_c
[R_EC_BRP256R1
][0] = count
/ 1000;
2113 for (i
= R_EC_BRP384R1
; i
<= R_EC_BRP512R1
; i
+= 2) {
2114 ecdh_c
[i
][0] = ecdh_c
[i
- 2][0] / 2;
2115 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2118 if (ecdh_c
[i
][0] == 0) {
2123 ecdh_c
[R_EC_BRP256T1
][0] = count
/ 1000;
2124 for (i
= R_EC_BRP384T1
; i
<= R_EC_BRP512T1
; i
+= 2) {
2125 ecdh_c
[i
][0] = ecdh_c
[i
- 2][0] / 2;
2126 if (ecdh_doit
[i
] <= 1 && ecdh_c
[i
][0] == 0)
2129 if (ecdh_c
[i
][0] == 0) {
2134 /* default iteration count for the last two EC Curves */
2135 ecdh_c
[R_EC_X25519
][0] = count
/ 1800;
2136 ecdh_c
[R_EC_X448
][0] = count
/ 7200;
2138 eddsa_c
[R_EC_Ed25519
][0] = count
/ 1800;
2139 eddsa_c
[R_EC_Ed448
][0] = count
/ 7200;
2143 /* not worth fixing */
2144 # error "You cannot disable DES on systems without SIGALRM."
2145 # endif /* OPENSSL_NO_DES */
2147 signal(SIGALRM
, alarmed
);
2148 #endif /* SIGALRM */
2150 #ifndef OPENSSL_NO_MD2
2152 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2153 print_message(names
[D_MD2
], c
[D_MD2
][testnum
], lengths
[testnum
],
2156 count
= run_benchmark(async_jobs
, EVP_Digest_MD2_loop
, loopargs
);
2158 print_result(D_MD2
, testnum
, count
, d
);
2162 #ifndef OPENSSL_NO_MDC2
2164 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2165 print_message(names
[D_MDC2
], c
[D_MDC2
][testnum
], lengths
[testnum
],
2168 count
= run_benchmark(async_jobs
, EVP_Digest_MDC2_loop
, loopargs
);
2170 print_result(D_MDC2
, testnum
, count
, d
);
2175 #ifndef OPENSSL_NO_MD4
2177 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2178 print_message(names
[D_MD4
], c
[D_MD4
][testnum
], lengths
[testnum
],
2181 count
= run_benchmark(async_jobs
, EVP_Digest_MD4_loop
, loopargs
);
2183 print_result(D_MD4
, testnum
, count
, d
);
2188 #ifndef OPENSSL_NO_MD5
2190 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2191 print_message(names
[D_MD5
], c
[D_MD5
][testnum
], lengths
[testnum
],
2194 count
= run_benchmark(async_jobs
, MD5_loop
, loopargs
);
2196 print_result(D_MD5
, testnum
, count
, d
);
2201 static const char hmac_key
[] = "This is a key...";
2202 int len
= strlen(hmac_key
);
2204 for (i
= 0; i
< loopargs_len
; i
++) {
2205 loopargs
[i
].hctx
= HMAC_CTX_new();
2206 if (loopargs
[i
].hctx
== NULL
) {
2207 BIO_printf(bio_err
, "HMAC malloc failure, exiting...");
2211 HMAC_Init_ex(loopargs
[i
].hctx
, hmac_key
, len
, EVP_md5(), NULL
);
2213 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2214 print_message(names
[D_HMAC
], c
[D_HMAC
][testnum
], lengths
[testnum
],
2217 count
= run_benchmark(async_jobs
, HMAC_loop
, loopargs
);
2219 print_result(D_HMAC
, testnum
, count
, d
);
2221 for (i
= 0; i
< loopargs_len
; i
++) {
2222 HMAC_CTX_free(loopargs
[i
].hctx
);
2227 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2228 print_message(names
[D_SHA1
], c
[D_SHA1
][testnum
], lengths
[testnum
],
2231 count
= run_benchmark(async_jobs
, SHA1_loop
, loopargs
);
2233 print_result(D_SHA1
, testnum
, count
, d
);
2236 if (doit
[D_SHA256
]) {
2237 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2238 print_message(names
[D_SHA256
], c
[D_SHA256
][testnum
],
2239 lengths
[testnum
], seconds
.sym
);
2241 count
= run_benchmark(async_jobs
, SHA256_loop
, loopargs
);
2243 print_result(D_SHA256
, testnum
, count
, d
);
2246 if (doit
[D_SHA512
]) {
2247 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2248 print_message(names
[D_SHA512
], c
[D_SHA512
][testnum
],
2249 lengths
[testnum
], seconds
.sym
);
2251 count
= run_benchmark(async_jobs
, SHA512_loop
, loopargs
);
2253 print_result(D_SHA512
, testnum
, count
, d
);
2256 #ifndef OPENSSL_NO_WHIRLPOOL
2257 if (doit
[D_WHIRLPOOL
]) {
2258 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2259 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][testnum
],
2260 lengths
[testnum
], seconds
.sym
);
2262 count
= run_benchmark(async_jobs
, WHIRLPOOL_loop
, loopargs
);
2264 print_result(D_WHIRLPOOL
, testnum
, count
, d
);
2269 #ifndef OPENSSL_NO_RMD160
2270 if (doit
[D_RMD160
]) {
2271 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2272 print_message(names
[D_RMD160
], c
[D_RMD160
][testnum
],
2273 lengths
[testnum
], seconds
.sym
);
2275 count
= run_benchmark(async_jobs
, EVP_Digest_RMD160_loop
, loopargs
);
2277 print_result(D_RMD160
, testnum
, count
, d
);
2281 #ifndef OPENSSL_NO_RC4
2283 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2284 print_message(names
[D_RC4
], c
[D_RC4
][testnum
], lengths
[testnum
],
2287 count
= run_benchmark(async_jobs
, RC4_loop
, loopargs
);
2289 print_result(D_RC4
, testnum
, count
, d
);
2293 #ifndef OPENSSL_NO_DES
2294 if (doit
[D_CBC_DES
]) {
2295 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2296 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][testnum
],
2297 lengths
[testnum
], seconds
.sym
);
2299 count
= run_benchmark(async_jobs
, DES_ncbc_encrypt_loop
, loopargs
);
2301 print_result(D_CBC_DES
, testnum
, count
, d
);
2305 if (doit
[D_EDE3_DES
]) {
2306 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2307 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][testnum
],
2308 lengths
[testnum
], seconds
.sym
);
2311 run_benchmark(async_jobs
, DES_ede3_cbc_encrypt_loop
, loopargs
);
2313 print_result(D_EDE3_DES
, testnum
, count
, d
);
2318 if (doit
[D_CBC_128_AES
]) {
2319 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2320 print_message(names
[D_CBC_128_AES
], c
[D_CBC_128_AES
][testnum
],
2321 lengths
[testnum
], seconds
.sym
);
2324 run_benchmark(async_jobs
, AES_cbc_128_encrypt_loop
, loopargs
);
2326 print_result(D_CBC_128_AES
, testnum
, count
, d
);
2329 if (doit
[D_CBC_192_AES
]) {
2330 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2331 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][testnum
],
2332 lengths
[testnum
], seconds
.sym
);
2335 run_benchmark(async_jobs
, AES_cbc_192_encrypt_loop
, loopargs
);
2337 print_result(D_CBC_192_AES
, testnum
, count
, d
);
2340 if (doit
[D_CBC_256_AES
]) {
2341 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2342 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][testnum
],
2343 lengths
[testnum
], seconds
.sym
);
2346 run_benchmark(async_jobs
, AES_cbc_256_encrypt_loop
, loopargs
);
2348 print_result(D_CBC_256_AES
, testnum
, count
, d
);
2352 if (doit
[D_IGE_128_AES
]) {
2353 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2354 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][testnum
],
2355 lengths
[testnum
], seconds
.sym
);
2358 run_benchmark(async_jobs
, AES_ige_128_encrypt_loop
, loopargs
);
2360 print_result(D_IGE_128_AES
, testnum
, count
, d
);
2363 if (doit
[D_IGE_192_AES
]) {
2364 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2365 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][testnum
],
2366 lengths
[testnum
], seconds
.sym
);
2369 run_benchmark(async_jobs
, AES_ige_192_encrypt_loop
, loopargs
);
2371 print_result(D_IGE_192_AES
, testnum
, count
, d
);
2374 if (doit
[D_IGE_256_AES
]) {
2375 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2376 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][testnum
],
2377 lengths
[testnum
], seconds
.sym
);
2380 run_benchmark(async_jobs
, AES_ige_256_encrypt_loop
, loopargs
);
2382 print_result(D_IGE_256_AES
, testnum
, count
, d
);
2385 if (doit
[D_GHASH
]) {
2386 for (i
= 0; i
< loopargs_len
; i
++) {
2387 loopargs
[i
].gcm_ctx
=
2388 CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
2389 CRYPTO_gcm128_setiv(loopargs
[i
].gcm_ctx
,
2390 (unsigned char *)"0123456789ab", 12);
2393 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2394 print_message(names
[D_GHASH
], c
[D_GHASH
][testnum
],
2395 lengths
[testnum
], seconds
.sym
);
2397 count
= run_benchmark(async_jobs
, CRYPTO_gcm128_aad_loop
, loopargs
);
2399 print_result(D_GHASH
, testnum
, count
, d
);
2401 for (i
= 0; i
< loopargs_len
; i
++)
2402 CRYPTO_gcm128_release(loopargs
[i
].gcm_ctx
);
2404 #ifndef OPENSSL_NO_CAMELLIA
2405 if (doit
[D_CBC_128_CML
]) {
2406 if (async_jobs
> 0) {
2407 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2408 names
[D_CBC_128_CML
]);
2409 doit
[D_CBC_128_CML
] = 0;
2411 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2412 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][testnum
],
2413 lengths
[testnum
], seconds
.sym
);
2415 for (count
= 0, run
= 1; COND(c
[D_CBC_128_CML
][testnum
]); count
++)
2416 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2417 (size_t)lengths
[testnum
], &camellia_ks1
,
2418 iv
, CAMELLIA_ENCRYPT
);
2420 print_result(D_CBC_128_CML
, testnum
, count
, d
);
2423 if (doit
[D_CBC_192_CML
]) {
2424 if (async_jobs
> 0) {
2425 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2426 names
[D_CBC_192_CML
]);
2427 doit
[D_CBC_192_CML
] = 0;
2429 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2430 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][testnum
],
2431 lengths
[testnum
], seconds
.sym
);
2432 if (async_jobs
> 0) {
2433 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2437 for (count
= 0, run
= 1; COND(c
[D_CBC_192_CML
][testnum
]); count
++)
2438 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2439 (size_t)lengths
[testnum
], &camellia_ks2
,
2440 iv
, CAMELLIA_ENCRYPT
);
2442 print_result(D_CBC_192_CML
, testnum
, count
, d
);
2445 if (doit
[D_CBC_256_CML
]) {
2446 if (async_jobs
> 0) {
2447 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2448 names
[D_CBC_256_CML
]);
2449 doit
[D_CBC_256_CML
] = 0;
2451 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2452 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][testnum
],
2453 lengths
[testnum
], seconds
.sym
);
2455 for (count
= 0, run
= 1; COND(c
[D_CBC_256_CML
][testnum
]); count
++)
2456 Camellia_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2457 (size_t)lengths
[testnum
], &camellia_ks3
,
2458 iv
, CAMELLIA_ENCRYPT
);
2460 print_result(D_CBC_256_CML
, testnum
, count
, d
);
2464 #ifndef OPENSSL_NO_IDEA
2465 if (doit
[D_CBC_IDEA
]) {
2466 if (async_jobs
> 0) {
2467 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2469 doit
[D_CBC_IDEA
] = 0;
2471 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2472 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][testnum
],
2473 lengths
[testnum
], seconds
.sym
);
2475 for (count
= 0, run
= 1; COND(c
[D_CBC_IDEA
][testnum
]); count
++)
2476 IDEA_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2477 (size_t)lengths
[testnum
], &idea_ks
,
2480 print_result(D_CBC_IDEA
, testnum
, count
, d
);
2484 #ifndef OPENSSL_NO_SEED
2485 if (doit
[D_CBC_SEED
]) {
2486 if (async_jobs
> 0) {
2487 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2489 doit
[D_CBC_SEED
] = 0;
2491 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2492 print_message(names
[D_CBC_SEED
], c
[D_CBC_SEED
][testnum
],
2493 lengths
[testnum
], seconds
.sym
);
2495 for (count
= 0, run
= 1; COND(c
[D_CBC_SEED
][testnum
]); count
++)
2496 SEED_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2497 (size_t)lengths
[testnum
], &seed_ks
, iv
, 1);
2499 print_result(D_CBC_SEED
, testnum
, count
, d
);
2503 #ifndef OPENSSL_NO_RC2
2504 if (doit
[D_CBC_RC2
]) {
2505 if (async_jobs
> 0) {
2506 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2508 doit
[D_CBC_RC2
] = 0;
2510 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2511 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][testnum
],
2512 lengths
[testnum
], seconds
.sym
);
2513 if (async_jobs
> 0) {
2514 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2518 for (count
= 0, run
= 1; COND(c
[D_CBC_RC2
][testnum
]); count
++)
2519 RC2_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2520 (size_t)lengths
[testnum
], &rc2_ks
,
2523 print_result(D_CBC_RC2
, testnum
, count
, d
);
2527 #ifndef OPENSSL_NO_RC5
2528 if (doit
[D_CBC_RC5
]) {
2529 if (async_jobs
> 0) {
2530 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2532 doit
[D_CBC_RC5
] = 0;
2534 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2535 print_message(names
[D_CBC_RC5
], c
[D_CBC_RC5
][testnum
],
2536 lengths
[testnum
], seconds
.sym
);
2537 if (async_jobs
> 0) {
2538 BIO_printf(bio_err
, "Async mode is not supported, exiting...");
2542 for (count
= 0, run
= 1; COND(c
[D_CBC_RC5
][testnum
]); count
++)
2543 RC5_32_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2544 (size_t)lengths
[testnum
], &rc5_ks
,
2547 print_result(D_CBC_RC5
, testnum
, count
, d
);
2551 #ifndef OPENSSL_NO_BF
2552 if (doit
[D_CBC_BF
]) {
2553 if (async_jobs
> 0) {
2554 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2558 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2559 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][testnum
],
2560 lengths
[testnum
], seconds
.sym
);
2562 for (count
= 0, run
= 1; COND(c
[D_CBC_BF
][testnum
]); count
++)
2563 BF_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2564 (size_t)lengths
[testnum
], &bf_ks
,
2567 print_result(D_CBC_BF
, testnum
, count
, d
);
2571 #ifndef OPENSSL_NO_CAST
2572 if (doit
[D_CBC_CAST
]) {
2573 if (async_jobs
> 0) {
2574 BIO_printf(bio_err
, "Async mode is not supported with %s\n",
2576 doit
[D_CBC_CAST
] = 0;
2578 for (testnum
= 0; testnum
< size_num
&& async_init
== 0; testnum
++) {
2579 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][testnum
],
2580 lengths
[testnum
], seconds
.sym
);
2582 for (count
= 0, run
= 1; COND(c
[D_CBC_CAST
][testnum
]); count
++)
2583 CAST_cbc_encrypt(loopargs
[0].buf
, loopargs
[0].buf
,
2584 (size_t)lengths
[testnum
], &cast_ks
,
2587 print_result(D_CBC_CAST
, testnum
, count
, d
);
2592 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2593 print_message(names
[D_RAND
], c
[D_RAND
][testnum
], lengths
[testnum
],
2596 count
= run_benchmark(async_jobs
, RAND_bytes_loop
, loopargs
);
2598 print_result(D_RAND
, testnum
, count
, d
);
2603 if (evp_cipher
!= NULL
) {
2604 int (*loopfunc
)(void *args
) = EVP_Update_loop
;
2606 if (multiblock
&& (EVP_CIPHER_flags(evp_cipher
) &
2607 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
)) {
2608 multiblock_speed(evp_cipher
, lengths_single
, &seconds
);
2613 names
[D_EVP
] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
2615 if (EVP_CIPHER_mode(evp_cipher
) == EVP_CIPH_CCM_MODE
) {
2616 loopfunc
= EVP_Update_loop_ccm
;
2617 } else if (aead
&& (EVP_CIPHER_flags(evp_cipher
) &
2618 EVP_CIPH_FLAG_AEAD_CIPHER
)) {
2619 loopfunc
= EVP_Update_loop_aead
;
2620 if (lengths
== lengths_list
) {
2621 lengths
= aead_lengths_list
;
2622 size_num
= OSSL_NELEM(aead_lengths_list
);
2626 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2627 print_message(names
[D_EVP
], save_count
, lengths
[testnum
],
2630 for (k
= 0; k
< loopargs_len
; k
++) {
2631 loopargs
[k
].ctx
= EVP_CIPHER_CTX_new();
2632 if (loopargs
[k
].ctx
== NULL
) {
2633 BIO_printf(bio_err
, "\nEVP_CIPHER_CTX_new failure\n");
2636 if (!EVP_CipherInit_ex(loopargs
[k
].ctx
, evp_cipher
, NULL
,
2637 NULL
, iv
, decrypt
? 0 : 1)) {
2638 BIO_printf(bio_err
, "\nEVP_CipherInit_ex failure\n");
2639 ERR_print_errors(bio_err
);
2643 EVP_CIPHER_CTX_set_padding(loopargs
[k
].ctx
, 0);
2645 keylen
= EVP_CIPHER_CTX_key_length(loopargs
[k
].ctx
);
2646 loopargs
[k
].key
= app_malloc(keylen
, "evp_cipher key");
2647 EVP_CIPHER_CTX_rand_key(loopargs
[k
].ctx
, loopargs
[k
].key
);
2648 if (!EVP_CipherInit_ex(loopargs
[k
].ctx
, NULL
, NULL
,
2649 loopargs
[k
].key
, NULL
, -1)) {
2650 BIO_printf(bio_err
, "\nEVP_CipherInit_ex failure\n");
2651 ERR_print_errors(bio_err
);
2654 OPENSSL_clear_free(loopargs
[k
].key
, keylen
);
2658 count
= run_benchmark(async_jobs
, loopfunc
, loopargs
);
2660 for (k
= 0; k
< loopargs_len
; k
++) {
2661 EVP_CIPHER_CTX_free(loopargs
[k
].ctx
);
2663 print_result(D_EVP
, testnum
, count
, d
);
2665 } else if (evp_md
!= NULL
) {
2666 names
[D_EVP
] = OBJ_nid2ln(EVP_MD_type(evp_md
));
2668 for (testnum
= 0; testnum
< size_num
; testnum
++) {
2669 print_message(names
[D_EVP
], save_count
, lengths
[testnum
],
2672 count
= run_benchmark(async_jobs
, EVP_Digest_loop
, loopargs
);
2674 print_result(D_EVP
, testnum
, count
, d
);
2679 for (i
= 0; i
< loopargs_len
; i
++)
2680 if (RAND_bytes(loopargs
[i
].buf
, 36) <= 0)
2683 #ifndef OPENSSL_NO_RSA
2684 for (testnum
= 0; testnum
< RSA_NUM
; testnum
++) {
2686 if (!rsa_doit
[testnum
])
2688 for (i
= 0; i
< loopargs_len
; i
++) {
2690 /* we haven't set keys yet, generate multi-prime RSA keys */
2691 BIGNUM
*bn
= BN_new();
2695 if (!BN_set_word(bn
, RSA_F4
)) {
2700 BIO_printf(bio_err
, "Generate multi-prime RSA key for %s\n",
2701 rsa_choices
[testnum
].name
);
2703 loopargs
[i
].rsa_key
[testnum
] = RSA_new();
2704 if (loopargs
[i
].rsa_key
[testnum
] == NULL
) {
2709 if (!RSA_generate_multi_prime_key(loopargs
[i
].rsa_key
[testnum
],
2711 primes
, bn
, NULL
)) {
2717 st
= RSA_sign(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2718 &loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2724 "RSA sign failure. No RSA sign will be done.\n");
2725 ERR_print_errors(bio_err
);
2728 pkey_print_message("private", "rsa",
2729 rsa_c
[testnum
][0], rsa_bits
[testnum
],
2731 /* RSA_blinding_on(rsa_key[testnum],NULL); */
2733 count
= run_benchmark(async_jobs
, RSA_sign_loop
, loopargs
);
2736 mr
? "+R1:%ld:%d:%.2f\n"
2737 : "%ld %u bits private RSA's in %.2fs\n",
2738 count
, rsa_bits
[testnum
], d
);
2739 rsa_results
[testnum
][0] = (double)count
/ d
;
2743 for (i
= 0; i
< loopargs_len
; i
++) {
2744 st
= RSA_verify(NID_md5_sha1
, loopargs
[i
].buf
, 36, loopargs
[i
].buf2
,
2745 loopargs
[i
].siglen
, loopargs
[i
].rsa_key
[testnum
]);
2751 "RSA verify failure. No RSA verify will be done.\n");
2752 ERR_print_errors(bio_err
);
2753 rsa_doit
[testnum
] = 0;
2755 pkey_print_message("public", "rsa",
2756 rsa_c
[testnum
][1], rsa_bits
[testnum
],
2759 count
= run_benchmark(async_jobs
, RSA_verify_loop
, loopargs
);
2762 mr
? "+R2:%ld:%d:%.2f\n"
2763 : "%ld %u bits public RSA's in %.2fs\n",
2764 count
, rsa_bits
[testnum
], d
);
2765 rsa_results
[testnum
][1] = (double)count
/ d
;
2768 if (rsa_count
<= 1) {
2769 /* if longer than 10s, don't do any more */
2770 for (testnum
++; testnum
< RSA_NUM
; testnum
++)
2771 rsa_doit
[testnum
] = 0;
2774 #endif /* OPENSSL_NO_RSA */
2776 for (i
= 0; i
< loopargs_len
; i
++)
2777 if (RAND_bytes(loopargs
[i
].buf
, 36) <= 0)
2780 #ifndef OPENSSL_NO_DSA
2781 for (testnum
= 0; testnum
< DSA_NUM
; testnum
++) {
2783 if (!dsa_doit
[testnum
])
2786 /* DSA_generate_key(dsa_key[testnum]); */
2787 /* DSA_sign_setup(dsa_key[testnum],NULL); */
2788 for (i
= 0; i
< loopargs_len
; i
++) {
2789 st
= DSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2790 &loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2796 "DSA sign failure. No DSA sign will be done.\n");
2797 ERR_print_errors(bio_err
);
2800 pkey_print_message("sign", "dsa",
2801 dsa_c
[testnum
][0], dsa_bits
[testnum
],
2804 count
= run_benchmark(async_jobs
, DSA_sign_loop
, loopargs
);
2807 mr
? "+R3:%ld:%u:%.2f\n"
2808 : "%ld %u bits DSA signs in %.2fs\n",
2809 count
, dsa_bits
[testnum
], d
);
2810 dsa_results
[testnum
][0] = (double)count
/ d
;
2814 for (i
= 0; i
< loopargs_len
; i
++) {
2815 st
= DSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2816 loopargs
[i
].siglen
, loopargs
[i
].dsa_key
[testnum
]);
2822 "DSA verify failure. No DSA verify will be done.\n");
2823 ERR_print_errors(bio_err
);
2824 dsa_doit
[testnum
] = 0;
2826 pkey_print_message("verify", "dsa",
2827 dsa_c
[testnum
][1], dsa_bits
[testnum
],
2830 count
= run_benchmark(async_jobs
, DSA_verify_loop
, loopargs
);
2833 mr
? "+R4:%ld:%u:%.2f\n"
2834 : "%ld %u bits DSA verify in %.2fs\n",
2835 count
, dsa_bits
[testnum
], d
);
2836 dsa_results
[testnum
][1] = (double)count
/ d
;
2839 if (rsa_count
<= 1) {
2840 /* if longer than 10s, don't do any more */
2841 for (testnum
++; testnum
< DSA_NUM
; testnum
++)
2842 dsa_doit
[testnum
] = 0;
2845 #endif /* OPENSSL_NO_DSA */
2847 #ifndef OPENSSL_NO_EC
2848 for (testnum
= 0; testnum
< ECDSA_NUM
; testnum
++) {
2851 if (!ecdsa_doit
[testnum
])
2852 continue; /* Ignore Curve */
2853 for (i
= 0; i
< loopargs_len
; i
++) {
2854 loopargs
[i
].ecdsa
[testnum
] =
2855 EC_KEY_new_by_curve_name(test_curves
[testnum
].nid
);
2856 if (loopargs
[i
].ecdsa
[testnum
] == NULL
) {
2862 BIO_printf(bio_err
, "ECDSA failure.\n");
2863 ERR_print_errors(bio_err
);
2866 for (i
= 0; i
< loopargs_len
; i
++) {
2867 EC_KEY_precompute_mult(loopargs
[i
].ecdsa
[testnum
], NULL
);
2868 /* Perform ECDSA signature test */
2869 EC_KEY_generate_key(loopargs
[i
].ecdsa
[testnum
]);
2870 st
= ECDSA_sign(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2871 &loopargs
[i
].siglen
,
2872 loopargs
[i
].ecdsa
[testnum
]);
2878 "ECDSA sign failure. No ECDSA sign will be done.\n");
2879 ERR_print_errors(bio_err
);
2882 pkey_print_message("sign", "ecdsa",
2883 ecdsa_c
[testnum
][0],
2884 test_curves
[testnum
].bits
, seconds
.ecdsa
);
2886 count
= run_benchmark(async_jobs
, ECDSA_sign_loop
, loopargs
);
2890 mr
? "+R5:%ld:%u:%.2f\n" :
2891 "%ld %u bits ECDSA signs in %.2fs \n",
2892 count
, test_curves
[testnum
].bits
, d
);
2893 ecdsa_results
[testnum
][0] = (double)count
/ d
;
2897 /* Perform ECDSA verification test */
2898 for (i
= 0; i
< loopargs_len
; i
++) {
2899 st
= ECDSA_verify(0, loopargs
[i
].buf
, 20, loopargs
[i
].buf2
,
2901 loopargs
[i
].ecdsa
[testnum
]);
2907 "ECDSA verify failure. No ECDSA verify will be done.\n");
2908 ERR_print_errors(bio_err
);
2909 ecdsa_doit
[testnum
] = 0;
2911 pkey_print_message("verify", "ecdsa",
2912 ecdsa_c
[testnum
][1],
2913 test_curves
[testnum
].bits
, seconds
.ecdsa
);
2915 count
= run_benchmark(async_jobs
, ECDSA_verify_loop
, loopargs
);
2918 mr
? "+R6:%ld:%u:%.2f\n"
2919 : "%ld %u bits ECDSA verify in %.2fs\n",
2920 count
, test_curves
[testnum
].bits
, d
);
2921 ecdsa_results
[testnum
][1] = (double)count
/ d
;
2924 if (rsa_count
<= 1) {
2925 /* if longer than 10s, don't do any more */
2926 for (testnum
++; testnum
< ECDSA_NUM
; testnum
++)
2927 ecdsa_doit
[testnum
] = 0;
2932 for (testnum
= 0; testnum
< EC_NUM
; testnum
++) {
2933 int ecdh_checks
= 1;
2935 if (!ecdh_doit
[testnum
])
2938 for (i
= 0; i
< loopargs_len
; i
++) {
2939 EVP_PKEY_CTX
*kctx
= NULL
;
2940 EVP_PKEY_CTX
*test_ctx
= NULL
;
2941 EVP_PKEY_CTX
*ctx
= NULL
;
2942 EVP_PKEY
*key_A
= NULL
;
2943 EVP_PKEY
*key_B
= NULL
;
2947 /* Ensure that the error queue is empty */
2948 if (ERR_peek_error()) {
2950 "WARNING: the error queue contains previous unhandled errors.\n");
2951 ERR_print_errors(bio_err
);
2954 /* Let's try to create a ctx directly from the NID: this works for
2955 * curves like Curve25519 that are not implemented through the low
2956 * level EC interface.
2957 * If this fails we try creating a EVP_PKEY_EC generic param ctx,
2958 * then we set the curve by NID before deriving the actual keygen
2959 * ctx for that specific curve. */
2960 kctx
= EVP_PKEY_CTX_new_id(test_curves
[testnum
].nid
, NULL
); /* keygen ctx from NID */
2962 EVP_PKEY_CTX
*pctx
= NULL
;
2963 EVP_PKEY
*params
= NULL
;
2965 /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
2966 * "int_ctx_new:unsupported algorithm" error was added to the
2968 * We remove it from the error queue as we are handling it. */
2969 unsigned long error
= ERR_peek_error(); /* peek the latest error in the queue */
2970 if (error
== ERR_peek_last_error() && /* oldest and latest errors match */
2971 /* check that the error origin matches */
2972 ERR_GET_LIB(error
) == ERR_LIB_EVP
&&
2973 ERR_GET_FUNC(error
) == EVP_F_INT_CTX_NEW
&&
2974 ERR_GET_REASON(error
) == EVP_R_UNSUPPORTED_ALGORITHM
)
2975 ERR_get_error(); /* pop error from queue */
2976 if (ERR_peek_error()) {
2978 "Unhandled error in the error queue during ECDH init.\n");
2979 ERR_print_errors(bio_err
);
2984 if ( /* Create the context for parameter generation */
2985 !(pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
)) ||
2986 /* Initialise the parameter generation */
2987 !EVP_PKEY_paramgen_init(pctx
) ||
2988 /* Set the curve by NID */
2989 !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
,
2992 /* Create the parameter object params */
2993 !EVP_PKEY_paramgen(pctx
, ¶ms
)) {
2995 BIO_printf(bio_err
, "ECDH EC params init failure.\n");
2996 ERR_print_errors(bio_err
);
3000 /* Create the context for the key generation */
3001 kctx
= EVP_PKEY_CTX_new(params
, NULL
);
3003 EVP_PKEY_free(params
);
3005 EVP_PKEY_CTX_free(pctx
);
3008 if (kctx
== NULL
|| /* keygen ctx is not null */
3009 EVP_PKEY_keygen_init(kctx
) <= 0/* init keygen ctx */ ) {
3011 BIO_printf(bio_err
, "ECDH keygen failure.\n");
3012 ERR_print_errors(bio_err
);
3017 if (EVP_PKEY_keygen(kctx
, &key_A
) <= 0 || /* generate secret key A */
3018 EVP_PKEY_keygen(kctx
, &key_B
) <= 0 || /* generate secret key B */
3019 !(ctx
= EVP_PKEY_CTX_new(key_A
, NULL
)) || /* derivation ctx from skeyA */
3020 EVP_PKEY_derive_init(ctx
) <= 0 || /* init derivation ctx */
3021 EVP_PKEY_derive_set_peer(ctx
, key_B
) <= 0 || /* set peer pubkey in ctx */
3022 EVP_PKEY_derive(ctx
, NULL
, &outlen
) <= 0 || /* determine max length */
3023 outlen
== 0 || /* ensure outlen is a valid size */
3024 outlen
> MAX_ECDH_SIZE
/* avoid buffer overflow */ ) {
3026 BIO_printf(bio_err
, "ECDH key generation failure.\n");
3027 ERR_print_errors(bio_err
);
3032 /* Here we perform a test run, comparing the output of a*B and b*A;
3033 * we try this here and assume that further EVP_PKEY_derive calls
3034 * never fail, so we can skip checks in the actually benchmarked
3035 * code, for maximum performance. */
3036 if (!(test_ctx
= EVP_PKEY_CTX_new(key_B
, NULL
)) || /* test ctx from skeyB */
3037 !EVP_PKEY_derive_init(test_ctx
) || /* init derivation test_ctx */
3038 !EVP_PKEY_derive_set_peer(test_ctx
, key_A
) || /* set peer pubkey in test_ctx */
3039 !EVP_PKEY_derive(test_ctx
, NULL
, &test_outlen
) || /* determine max length */
3040 !EVP_PKEY_derive(ctx
, loopargs
[i
].secret_a
, &outlen
) || /* compute a*B */
3041 !EVP_PKEY_derive(test_ctx
, loopargs
[i
].secret_b
, &test_outlen
) || /* compute b*A */
3042 test_outlen
!= outlen
/* compare output length */ ) {
3044 BIO_printf(bio_err
, "ECDH computation failure.\n");
3045 ERR_print_errors(bio_err
);
3050 /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
3051 if (CRYPTO_memcmp(loopargs
[i
].secret_a
,
3052 loopargs
[i
].secret_b
, outlen
)) {
3054 BIO_printf(bio_err
, "ECDH computations don't match.\n");
3055 ERR_print_errors(bio_err
);
3060 loopargs
[i
].ecdh_ctx
[testnum
] = ctx
;
3061 loopargs
[i
].outlen
[testnum
] = outlen
;
3063 EVP_PKEY_free(key_A
);
3064 EVP_PKEY_free(key_B
);
3065 EVP_PKEY_CTX_free(kctx
);
3067 EVP_PKEY_CTX_free(test_ctx
);
3070 if (ecdh_checks
!= 0) {
3071 pkey_print_message("", "ecdh",
3073 test_curves
[testnum
].bits
, seconds
.ecdh
);
3076 run_benchmark(async_jobs
, ECDH_EVP_derive_key_loop
, loopargs
);
3079 mr
? "+R7:%ld:%d:%.2f\n" :
3080 "%ld %u-bits ECDH ops in %.2fs\n", count
,
3081 test_curves
[testnum
].bits
, d
);
3082 ecdh_results
[testnum
][0] = (double)count
/ d
;
3086 if (rsa_count
<= 1) {
3087 /* if longer than 10s, don't do any more */
3088 for (testnum
++; testnum
< OSSL_NELEM(ecdh_doit
); testnum
++)
3089 ecdh_doit
[testnum
] = 0;
3093 for (testnum
= 0; testnum
< EdDSA_NUM
; testnum
++) {
3095 EVP_PKEY
*ed_pkey
= NULL
;
3096 EVP_PKEY_CTX
*ed_pctx
= NULL
;
3098 if (!eddsa_doit
[testnum
])
3099 continue; /* Ignore Curve */
3100 for (i
= 0; i
< loopargs_len
; i
++) {
3101 loopargs
[i
].eddsa_ctx
[testnum
] = EVP_MD_CTX_new();
3102 if (loopargs
[i
].eddsa_ctx
[testnum
] == NULL
) {
3107 if ((ed_pctx
= EVP_PKEY_CTX_new_id(test_ed_curves
[testnum
].nid
, NULL
))
3109 || EVP_PKEY_keygen_init(ed_pctx
) <= 0
3110 || EVP_PKEY_keygen(ed_pctx
, &ed_pkey
) <= 0) {
3112 EVP_PKEY_CTX_free(ed_pctx
);
3115 EVP_PKEY_CTX_free(ed_pctx
);
3117 if (!EVP_DigestSignInit(loopargs
[i
].eddsa_ctx
[testnum
], NULL
, NULL
,
3120 EVP_PKEY_free(ed_pkey
);
3123 EVP_PKEY_free(ed_pkey
);
3126 BIO_printf(bio_err
, "EdDSA failure.\n");
3127 ERR_print_errors(bio_err
);
3130 for (i
= 0; i
< loopargs_len
; i
++) {
3131 /* Perform EdDSA signature test */
3132 loopargs
[i
].sigsize
= test_ed_curves
[testnum
].sigsize
;
3133 st
= EVP_DigestSign(loopargs
[i
].eddsa_ctx
[testnum
],
3134 loopargs
[i
].buf2
, &loopargs
[i
].sigsize
,
3135 loopargs
[i
].buf
, 20);
3141 "EdDSA sign failure. No EdDSA sign will be done.\n");
3142 ERR_print_errors(bio_err
);
3145 pkey_print_message("sign", test_ed_curves
[testnum
].name
,
3146 eddsa_c
[testnum
][0],
3147 test_ed_curves
[testnum
].bits
, seconds
.eddsa
);
3149 count
= run_benchmark(async_jobs
, EdDSA_sign_loop
, loopargs
);
3153 mr
? "+R8:%ld:%u:%s:%.2f\n" :
3154 "%ld %u bits %s signs in %.2fs \n",
3155 count
, test_ed_curves
[testnum
].bits
,
3156 test_ed_curves
[testnum
].name
, d
);
3157 eddsa_results
[testnum
][0] = (double)count
/ d
;
3161 /* Perform EdDSA verification test */
3162 for (i
= 0; i
< loopargs_len
; i
++) {
3163 st
= EVP_DigestVerify(loopargs
[i
].eddsa_ctx
[testnum
],
3164 loopargs
[i
].buf2
, loopargs
[i
].sigsize
,
3165 loopargs
[i
].buf
, 20);
3171 "EdDSA verify failure. No EdDSA verify will be done.\n");
3172 ERR_print_errors(bio_err
);
3173 eddsa_doit
[testnum
] = 0;
3175 pkey_print_message("verify", test_ed_curves
[testnum
].name
,
3176 eddsa_c
[testnum
][1],
3177 test_ed_curves
[testnum
].bits
, seconds
.eddsa
);
3179 count
= run_benchmark(async_jobs
, EdDSA_verify_loop
, loopargs
);
3182 mr
? "+R9:%ld:%u:%s:%.2f\n"
3183 : "%ld %u bits %s verify in %.2fs\n",
3184 count
, test_ed_curves
[testnum
].bits
,
3185 test_ed_curves
[testnum
].name
, d
);
3186 eddsa_results
[testnum
][1] = (double)count
/ d
;
3189 if (rsa_count
<= 1) {
3190 /* if longer than 10s, don't do any more */
3191 for (testnum
++; testnum
< EdDSA_NUM
; testnum
++)
3192 eddsa_doit
[testnum
] = 0;
3197 #endif /* OPENSSL_NO_EC */
3202 printf("%s\n", OpenSSL_version(OPENSSL_VERSION
));
3203 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON
));
3205 printf("%s ", BN_options());
3206 #ifndef OPENSSL_NO_MD2
3207 printf("%s ", MD2_options());
3209 #ifndef OPENSSL_NO_RC4
3210 printf("%s ", RC4_options());
3212 #ifndef OPENSSL_NO_DES
3213 printf("%s ", DES_options());
3215 printf("%s ", AES_options());
3216 #ifndef OPENSSL_NO_IDEA
3217 printf("%s ", IDEA_options());
3219 #ifndef OPENSSL_NO_BF
3220 printf("%s ", BF_options());
3222 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS
));
3230 ("The 'numbers' are in 1000s of bytes per second processed.\n");
3233 for (testnum
= 0; testnum
< size_num
; testnum
++)
3234 printf(mr
? ":%d" : "%7d bytes", lengths
[testnum
]);
3238 for (k
= 0; k
< ALGOR_NUM
; k
++) {
3242 printf("+F:%u:%s", k
, names
[k
]);
3244 printf("%-13s", names
[k
]);
3245 for (testnum
= 0; testnum
< size_num
; testnum
++) {
3246 if (results
[k
][testnum
] > 10000 && !mr
)
3247 printf(" %11.2fk", results
[k
][testnum
] / 1e3
);
3249 printf(mr
? ":%.2f" : " %11.2f ", results
[k
][testnum
]);
3253 #ifndef OPENSSL_NO_RSA
3255 for (k
= 0; k
< RSA_NUM
; k
++) {
3258 if (testnum
&& !mr
) {
3259 printf("%18ssign verify sign/s verify/s\n", " ");
3263 printf("+F2:%u:%u:%f:%f\n",
3264 k
, rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1]);
3266 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3267 rsa_bits
[k
], 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1],
3268 rsa_results
[k
][0], rsa_results
[k
][1]);
3271 #ifndef OPENSSL_NO_DSA
3273 for (k
= 0; k
< DSA_NUM
; k
++) {
3276 if (testnum
&& !mr
) {
3277 printf("%18ssign verify sign/s verify/s\n", " ");
3281 printf("+F3:%u:%u:%f:%f\n",
3282 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
3284 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
3285 dsa_bits
[k
], 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1],
3286 dsa_results
[k
][0], dsa_results
[k
][1]);
3289 #ifndef OPENSSL_NO_EC
3291 for (k
= 0; k
< OSSL_NELEM(ecdsa_doit
); k
++) {
3294 if (testnum
&& !mr
) {
3295 printf("%30ssign verify sign/s verify/s\n", " ");
3300 printf("+F4:%u:%u:%f:%f\n",
3301 k
, test_curves
[k
].bits
,
3302 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
3304 printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3305 test_curves
[k
].bits
, test_curves
[k
].name
,
3306 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1],
3307 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
3311 for (k
= 0; k
< EC_NUM
; k
++) {
3314 if (testnum
&& !mr
) {
3315 printf("%30sop op/s\n", " ");
3319 printf("+F5:%u:%u:%f:%f\n",
3320 k
, test_curves
[k
].bits
,
3321 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
3324 printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
3325 test_curves
[k
].bits
, test_curves
[k
].name
,
3326 1.0 / ecdh_results
[k
][0], ecdh_results
[k
][0]);
3330 for (k
= 0; k
< OSSL_NELEM(eddsa_doit
); k
++) {
3333 if (testnum
&& !mr
) {
3334 printf("%30ssign verify sign/s verify/s\n", " ");
3339 printf("+F6:%u:%u:%s:%f:%f\n",
3340 k
, test_ed_curves
[k
].bits
, test_ed_curves
[k
].name
,
3341 eddsa_results
[k
][0], eddsa_results
[k
][1]);
3343 printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
3344 test_ed_curves
[k
].bits
, test_ed_curves
[k
].name
,
3345 1.0 / eddsa_results
[k
][0], 1.0 / eddsa_results
[k
][1],
3346 eddsa_results
[k
][0], eddsa_results
[k
][1]);
3353 ERR_print_errors(bio_err
);
3354 for (i
= 0; i
< loopargs_len
; i
++) {
3355 OPENSSL_free(loopargs
[i
].buf_malloc
);
3356 OPENSSL_free(loopargs
[i
].buf2_malloc
);
3358 #ifndef OPENSSL_NO_RSA
3359 for (k
= 0; k
< RSA_NUM
; k
++)
3360 RSA_free(loopargs
[i
].rsa_key
[k
]);
3362 #ifndef OPENSSL_NO_DSA
3363 for (k
= 0; k
< DSA_NUM
; k
++)
3364 DSA_free(loopargs
[i
].dsa_key
[k
]);
3366 #ifndef OPENSSL_NO_EC
3367 for (k
= 0; k
< ECDSA_NUM
; k
++)
3368 EC_KEY_free(loopargs
[i
].ecdsa
[k
]);
3369 for (k
= 0; k
< EC_NUM
; k
++)
3370 EVP_PKEY_CTX_free(loopargs
[i
].ecdh_ctx
[k
]);
3371 for (k
= 0; k
< EdDSA_NUM
; k
++)
3372 EVP_MD_CTX_free(loopargs
[i
].eddsa_ctx
[k
]);
3373 OPENSSL_free(loopargs
[i
].secret_a
);
3374 OPENSSL_free(loopargs
[i
].secret_b
);
3378 if (async_jobs
> 0) {
3379 for (i
= 0; i
< loopargs_len
; i
++)
3380 ASYNC_WAIT_CTX_free(loopargs
[i
].wait_ctx
);
3384 ASYNC_cleanup_thread();
3386 OPENSSL_free(loopargs
);
3391 static void print_message(const char *s
, long num
, int length
, int tm
)
3395 mr
? "+DT:%s:%d:%d\n"
3396 : "Doing %s for %ds on %d size blocks: ", s
, tm
, length
);
3397 (void)BIO_flush(bio_err
);
3401 mr
? "+DN:%s:%ld:%d\n"
3402 : "Doing %s %ld times on %d size blocks: ", s
, num
, length
);
3403 (void)BIO_flush(bio_err
);
3407 static void pkey_print_message(const char *str
, const char *str2
, long num
,
3408 unsigned int bits
, int tm
)
3412 mr
? "+DTP:%d:%s:%s:%d\n"
3413 : "Doing %u bits %s %s's for %ds: ", bits
, str
, str2
, tm
);
3414 (void)BIO_flush(bio_err
);
3418 mr
? "+DNP:%ld:%d:%s:%s\n"
3419 : "Doing %ld %u bits %s %s's: ", num
, bits
, str
, str2
);
3420 (void)BIO_flush(bio_err
);
3424 static void print_result(int alg
, int run_no
, int count
, double time_used
)
3427 BIO_puts(bio_err
, "EVP error!\n");
3431 mr
? "+R:%d:%s:%f\n"
3432 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
3433 results
[alg
][run_no
] = ((double)count
) / time_used
* lengths
[run_no
];
3437 static char *sstrsep(char **string
, const char *delim
)
3440 char *token
= *string
;
3445 memset(isdelim
, 0, sizeof(isdelim
));
3449 isdelim
[(unsigned char)(*delim
)] = 1;
3453 while (!isdelim
[(unsigned char)(**string
)]) {
3465 static int do_multi(int multi
, int size_num
)
3470 static char sep
[] = ":";
3472 fds
= app_malloc(sizeof(*fds
) * multi
, "fd buffer for do_multi");
3473 for (n
= 0; n
< multi
; ++n
) {
3474 if (pipe(fd
) == -1) {
3475 BIO_printf(bio_err
, "pipe failure\n");
3479 (void)BIO_flush(bio_err
);
3486 if (dup(fd
[1]) == -1) {
3487 BIO_printf(bio_err
, "dup failed\n");
3496 printf("Forked child %d\n", n
);
3499 /* for now, assume the pipe is long enough to take all the output */
3500 for (n
= 0; n
< multi
; ++n
) {
3505 f
= fdopen(fds
[n
], "r");
3506 while (fgets(buf
, sizeof(buf
), f
)) {
3507 p
= strchr(buf
, '\n');
3510 if (buf
[0] != '+') {
3512 "Don't understand line '%s' from child %d\n", buf
,
3516 printf("Got: %s from %d\n", buf
, n
);
3517 if (strncmp(buf
, "+F:", 3) == 0) {
3522 alg
= atoi(sstrsep(&p
, sep
));
3524 for (j
= 0; j
< size_num
; ++j
)
3525 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
3526 } else if (strncmp(buf
, "+F2:", 4) == 0) {
3531 k
= atoi(sstrsep(&p
, sep
));
3534 d
= atof(sstrsep(&p
, sep
));
3535 rsa_results
[k
][0] += d
;
3537 d
= atof(sstrsep(&p
, sep
));
3538 rsa_results
[k
][1] += d
;
3540 # ifndef OPENSSL_NO_DSA
3541 else if (strncmp(buf
, "+F3:", 4) == 0) {
3546 k
= atoi(sstrsep(&p
, sep
));
3549 d
= atof(sstrsep(&p
, sep
));
3550 dsa_results
[k
][0] += d
;
3552 d
= atof(sstrsep(&p
, sep
));
3553 dsa_results
[k
][1] += d
;
3556 # ifndef OPENSSL_NO_EC
3557 else if (strncmp(buf
, "+F4:", 4) == 0) {
3562 k
= atoi(sstrsep(&p
, sep
));
3565 d
= atof(sstrsep(&p
, sep
));
3566 ecdsa_results
[k
][0] += d
;
3568 d
= atof(sstrsep(&p
, sep
));
3569 ecdsa_results
[k
][1] += d
;
3570 } else if (strncmp(buf
, "+F5:", 4) == 0) {
3575 k
= atoi(sstrsep(&p
, sep
));
3578 d
= atof(sstrsep(&p
, sep
));
3579 ecdh_results
[k
][0] += d
;
3580 } else if (strncmp(buf
, "+F6:", 4) == 0) {
3585 k
= atoi(sstrsep(&p
, sep
));
3589 d
= atof(sstrsep(&p
, sep
));
3590 eddsa_results
[k
][0] += d
;
3592 d
= atof(sstrsep(&p
, sep
));
3593 eddsa_results
[k
][1] += d
;
3597 else if (strncmp(buf
, "+H:", 3) == 0) {
3600 BIO_printf(bio_err
, "Unknown type '%s' from child %d\n", buf
,
3611 static void multiblock_speed(const EVP_CIPHER
*evp_cipher
, int lengths_single
,
3612 const openssl_speed_sec_t
*seconds
)
3614 static const int mblengths_list
[] =
3615 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
3616 const int *mblengths
= mblengths_list
;
3617 int j
, count
, keylen
, num
= OSSL_NELEM(mblengths_list
);
3618 const char *alg_name
;
3619 unsigned char *inp
, *out
, *key
, no_key
[32], no_iv
[16];
3620 EVP_CIPHER_CTX
*ctx
;
3623 if (lengths_single
) {
3624 mblengths
= &lengths_single
;
3628 inp
= app_malloc(mblengths
[num
- 1], "multiblock input buffer");
3629 out
= app_malloc(mblengths
[num
- 1] + 1024, "multiblock output buffer");
3630 ctx
= EVP_CIPHER_CTX_new();
3631 EVP_EncryptInit_ex(ctx
, evp_cipher
, NULL
, NULL
, no_iv
);
3633 keylen
= EVP_CIPHER_CTX_key_length(ctx
);
3634 key
= app_malloc(keylen
, "evp_cipher key");
3635 EVP_CIPHER_CTX_rand_key(ctx
, key
);
3636 EVP_EncryptInit_ex(ctx
, NULL
, NULL
, key
, NULL
);
3637 OPENSSL_clear_free(key
, keylen
);
3639 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_SET_MAC_KEY
, sizeof(no_key
), no_key
);
3640 alg_name
= OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher
));
3642 for (j
= 0; j
< num
; j
++) {
3643 print_message(alg_name
, 0, mblengths
[j
], seconds
->sym
);
3645 for (count
= 0, run
= 1; run
&& count
< 0x7fffffff; count
++) {
3646 unsigned char aad
[EVP_AEAD_TLS1_AAD_LEN
];
3647 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param
;
3648 size_t len
= mblengths
[j
];
3651 memset(aad
, 0, 8); /* avoid uninitialized values */
3652 aad
[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3653 aad
[9] = 3; /* version */
3655 aad
[11] = 0; /* length */
3657 mb_param
.out
= NULL
;
3660 mb_param
.interleave
= 8;
3662 packlen
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD
,
3663 sizeof(mb_param
), &mb_param
);
3669 EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT
,
3670 sizeof(mb_param
), &mb_param
);
3674 RAND_bytes(out
, 16);
3676 aad
[11] = (unsigned char)(len
>> 8);
3677 aad
[12] = (unsigned char)(len
);
3678 pad
= EVP_CIPHER_CTX_ctrl(ctx
, EVP_CTRL_AEAD_TLS1_AAD
,
3679 EVP_AEAD_TLS1_AAD_LEN
, aad
);
3680 EVP_Cipher(ctx
, out
, inp
, len
+ pad
);
3684 BIO_printf(bio_err
, mr
? "+R:%d:%s:%f\n"
3685 : "%d %s's in %.2fs\n", count
, "evp", d
);
3686 results
[D_EVP
][j
] = ((double)count
) / d
* mblengths
[j
];
3690 fprintf(stdout
, "+H");
3691 for (j
= 0; j
< num
; j
++)
3692 fprintf(stdout
, ":%d", mblengths
[j
]);
3693 fprintf(stdout
, "\n");
3694 fprintf(stdout
, "+F:%d:%s", D_EVP
, alg_name
);
3695 for (j
= 0; j
< num
; j
++)
3696 fprintf(stdout
, ":%.2f", results
[D_EVP
][j
]);
3697 fprintf(stdout
, "\n");
3700 "The 'numbers' are in 1000s of bytes per second processed.\n");
3701 fprintf(stdout
, "type ");
3702 for (j
= 0; j
< num
; j
++)
3703 fprintf(stdout
, "%7d bytes", mblengths
[j
]);
3704 fprintf(stdout
, "\n");
3705 fprintf(stdout
, "%-24s", alg_name
);
3707 for (j
= 0; j
< num
; j
++) {
3708 if (results
[D_EVP
][j
] > 10000)
3709 fprintf(stdout
, " %11.2fk", results
[D_EVP
][j
] / 1e3
);
3711 fprintf(stdout
, " %11.2f ", results
[D_EVP
][j
]);
3713 fprintf(stdout
, "\n");
3718 EVP_CIPHER_CTX_free(ctx
);