1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 # define RSA_SECONDS 10
79 # define DSA_SECONDS 10
80 # define ECDSA_SECONDS 10
81 # define ECDH_SECONDS 10
83 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
84 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
87 # define PROG speed_main
95 # ifdef OPENSSL_NO_STDIO
98 # include <openssl/crypto.h>
99 # include <openssl/rand.h>
100 # include <openssl/err.h>
101 # include <openssl/evp.h>
102 # include <openssl/objects.h>
103 # if !defined(OPENSSL_SYS_MSDOS)
104 # include OPENSSL_UNISTD
107 # ifndef OPENSSL_SYS_NETWARE
111 # if defined(_WIN32) || defined(__CYGWIN__)
112 # include <windows.h>
113 # if defined(__CYGWIN__) && !defined(_WIN32)
115 * <windows.h> should define _WIN32, which normally is mutually exclusive
116 * with __CYGWIN__, but if it didn't...
119 /* this is done because Cygwin alarm() fails sometimes. */
123 # include <openssl/bn.h>
124 # ifndef OPENSSL_NO_DES
125 # include <openssl/des.h>
127 # ifndef OPENSSL_NO_AES
128 # include <openssl/aes.h>
130 # ifndef OPENSSL_NO_CAMELLIA
131 # include <openssl/camellia.h>
133 # ifndef OPENSSL_NO_MD2
134 # include <openssl/md2.h>
136 # ifndef OPENSSL_NO_MDC2
137 # include <openssl/mdc2.h>
139 # ifndef OPENSSL_NO_MD4
140 # include <openssl/md4.h>
142 # ifndef OPENSSL_NO_MD5
143 # include <openssl/md5.h>
145 # ifndef OPENSSL_NO_HMAC
146 # include <openssl/hmac.h>
148 # include <openssl/evp.h>
149 # ifndef OPENSSL_NO_SHA
150 # include <openssl/sha.h>
152 # ifndef OPENSSL_NO_RIPEMD
153 # include <openssl/ripemd.h>
155 # ifndef OPENSSL_NO_WHIRLPOOL
156 # include <openssl/whrlpool.h>
158 # ifndef OPENSSL_NO_RC4
159 # include <openssl/rc4.h>
161 # ifndef OPENSSL_NO_RC5
162 # include <openssl/rc5.h>
164 # ifndef OPENSSL_NO_RC2
165 # include <openssl/rc2.h>
167 # ifndef OPENSSL_NO_IDEA
168 # include <openssl/idea.h>
170 # ifndef OPENSSL_NO_SEED
171 # include <openssl/seed.h>
173 # ifndef OPENSSL_NO_BF
174 # include <openssl/blowfish.h>
176 # ifndef OPENSSL_NO_CAST
177 # include <openssl/cast.h>
179 # ifndef OPENSSL_NO_RSA
180 # include <openssl/rsa.h>
181 # include "./testrsa.h"
183 # include <openssl/x509.h>
184 # ifndef OPENSSL_NO_DSA
185 # include <openssl/dsa.h>
186 # include "./testdsa.h"
188 # ifndef OPENSSL_NO_ECDSA
189 # include <openssl/ecdsa.h>
191 # ifndef OPENSSL_NO_ECDH
192 # include <openssl/ecdh.h>
194 # include <openssl/modes.h>
197 # ifdef OPENSSL_DOING_MAKEDEPEND
198 # undef AES_set_encrypt_key
199 # undef AES_set_decrypt_key
200 # undef DES_set_key_unchecked
202 # define BF_set_key private_BF_set_key
203 # define CAST_set_key private_CAST_set_key
204 # define idea_set_encrypt_key private_idea_set_encrypt_key
205 # define SEED_set_key private_SEED_set_key
206 # define RC2_set_key private_RC2_set_key
207 # define RC4_set_key private_RC4_set_key
208 # define DES_set_key_unchecked private_DES_set_key_unchecked
209 # define AES_set_encrypt_key private_AES_set_encrypt_key
210 # define AES_set_decrypt_key private_AES_set_decrypt_key
211 # define Camellia_set_key private_Camellia_set_key
215 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
229 # define BUFSIZE ((long)1024*8+1)
230 static volatile int run
= 0;
233 static int usertime
= 1;
235 static double Time_F(int s
);
236 static void print_message(const char *s
, long num
, int length
);
237 static void pkey_print_message(const char *str
, const char *str2
,
238 long num
, int bits
, int sec
);
239 static void print_result(int alg
, int run_no
, int count
, double time_used
);
241 static int do_multi(int multi
);
244 # define ALGOR_NUM 30
250 # define MAX_ECDH_SIZE 256
252 static const char *names
[ALGOR_NUM
] = {
253 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
254 "des cbc", "des ede3", "idea cbc", "seed cbc",
255 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
256 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
257 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
258 "evp", "sha256", "sha512", "whirlpool",
259 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
262 static double results
[ALGOR_NUM
][SIZE_NUM
];
263 static int lengths
[SIZE_NUM
] = { 16, 64, 256, 1024, 8 * 1024 };
265 # ifndef OPENSSL_NO_RSA
266 static double rsa_results
[RSA_NUM
][2];
268 # ifndef OPENSSL_NO_DSA
269 static double dsa_results
[DSA_NUM
][2];
271 # ifndef OPENSSL_NO_ECDSA
272 static double ecdsa_results
[EC_NUM
][2];
274 # ifndef OPENSSL_NO_ECDH
275 static double ecdh_results
[EC_NUM
][1];
278 # if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
279 static const char rnd_seed
[] =
280 "string to make the random number generator think it has entropy";
281 static int rnd_fake
= 0;
285 # if defined(__STDC__) || defined(sgi) || defined(_AIX)
286 # define SIGRETTYPE void
288 # define SIGRETTYPE int
291 static SIGRETTYPE
sig_done(int sig
);
292 static SIGRETTYPE
sig_done(int sig
)
294 signal(SIGALRM
, sig_done
);
307 # if !defined(SIGALRM)
310 static unsigned int lapse
, schlock
;
311 static void alarm_win32(unsigned int secs
)
316 # define alarm alarm_win32
318 static DWORD WINAPI
sleepy(VOID
* arg
)
326 static double Time_F(int s
)
331 thr
= CreateThread(NULL
, 4096, sleepy
, NULL
, 0, NULL
);
333 DWORD ret
= GetLastError();
334 BIO_printf(bio_err
, "unable to CreateThread (%d)", ret
);
337 CloseHandle(thr
); /* detach the thread */
339 Sleep(0); /* scheduler spinlock */
342 return app_tminterval(s
, usertime
);
346 static double Time_F(int s
)
348 return app_tminterval(s
, usertime
);
352 # ifndef OPENSSL_NO_ECDH
353 static const int KDF1_SHA1_len
= 20;
354 static void *KDF1_SHA1(const void *in
, size_t inlen
, void *out
,
357 # ifndef OPENSSL_NO_SHA
358 if (*outlen
< SHA_DIGEST_LENGTH
)
361 *outlen
= SHA_DIGEST_LENGTH
;
362 return SHA1(in
, inlen
, out
);
365 # endif /* OPENSSL_NO_SHA */
367 # endif /* OPENSSL_NO_ECDH */
369 int MAIN(int, char **);
371 int MAIN(int argc
, char **argv
)
373 unsigned char *buf
= NULL
, *buf2
= NULL
;
375 long count
= 0, save_count
= 0;
377 # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
380 # ifndef OPENSSL_NO_RSA
383 unsigned char md
[EVP_MAX_MD_SIZE
];
384 # ifndef OPENSSL_NO_MD2
385 unsigned char md2
[MD2_DIGEST_LENGTH
];
387 # ifndef OPENSSL_NO_MDC2
388 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
390 # ifndef OPENSSL_NO_MD4
391 unsigned char md4
[MD4_DIGEST_LENGTH
];
393 # ifndef OPENSSL_NO_MD5
394 unsigned char md5
[MD5_DIGEST_LENGTH
];
395 unsigned char hmac
[MD5_DIGEST_LENGTH
];
397 # ifndef OPENSSL_NO_SHA
398 unsigned char sha
[SHA_DIGEST_LENGTH
];
399 # ifndef OPENSSL_NO_SHA256
400 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
402 # ifndef OPENSSL_NO_SHA512
403 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
406 # ifndef OPENSSL_NO_WHIRLPOOL
407 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
409 # ifndef OPENSSL_NO_RIPEMD
410 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
412 # ifndef OPENSSL_NO_RC4
415 # ifndef OPENSSL_NO_RC5
418 # ifndef OPENSSL_NO_RC2
421 # ifndef OPENSSL_NO_IDEA
422 IDEA_KEY_SCHEDULE idea_ks
;
424 # ifndef OPENSSL_NO_SEED
425 SEED_KEY_SCHEDULE seed_ks
;
427 # ifndef OPENSSL_NO_BF
430 # ifndef OPENSSL_NO_CAST
433 static const unsigned char key16
[16] = {
434 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
435 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
437 # ifndef OPENSSL_NO_AES
438 static const unsigned char key24
[24] = {
439 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
440 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
441 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
443 static const unsigned char key32
[32] = {
444 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
445 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
446 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
447 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
450 # ifndef OPENSSL_NO_CAMELLIA
451 static const unsigned char ckey24
[24] = {
452 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
453 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
454 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
456 static const unsigned char ckey32
[32] = {
457 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
458 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
459 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
460 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
463 # ifndef OPENSSL_NO_AES
464 # define MAX_BLOCK_SIZE 128
466 # define MAX_BLOCK_SIZE 64
468 unsigned char DES_iv
[8];
469 unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
470 # ifndef OPENSSL_NO_DES
471 static DES_cblock key
=
472 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
473 static DES_cblock key2
=
474 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
475 static DES_cblock key3
=
476 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
477 DES_key_schedule sch
;
478 DES_key_schedule sch2
;
479 DES_key_schedule sch3
;
481 # ifndef OPENSSL_NO_AES
482 AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
484 # ifndef OPENSSL_NO_CAMELLIA
485 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
496 # define D_EDE3_DES 9
497 # define D_CBC_IDEA 10
498 # define D_CBC_SEED 11
499 # define D_CBC_RC2 12
500 # define D_CBC_RC5 13
502 # define D_CBC_CAST 15
503 # define D_CBC_128_AES 16
504 # define D_CBC_192_AES 17
505 # define D_CBC_256_AES 18
506 # define D_CBC_128_CML 19
507 # define D_CBC_192_CML 20
508 # define D_CBC_256_CML 21
512 # define D_WHIRLPOOL 25
513 # define D_IGE_128_AES 26
514 # define D_IGE_192_AES 27
515 # define D_IGE_256_AES 28
518 long c
[ALGOR_NUM
][SIZE_NUM
];
520 # define R_DSA_1024 1
521 # define R_DSA_2048 2
523 # define R_RSA_1024 1
524 # define R_RSA_2048 2
525 # define R_RSA_4096 3
537 # define R_EC_K571 10
538 # define R_EC_B163 11
539 # define R_EC_B233 12
540 # define R_EC_B283 13
541 # define R_EC_B409 14
542 # define R_EC_B571 15
544 # ifndef OPENSSL_NO_RSA
545 RSA
*rsa_key
[RSA_NUM
];
546 long rsa_c
[RSA_NUM
][2];
547 static unsigned int rsa_bits
[RSA_NUM
] = {
548 512, 1024, 2048, 4096
550 static unsigned char *rsa_data
[RSA_NUM
] = {
551 test512
, test1024
, test2048
, test4096
553 static int rsa_data_length
[RSA_NUM
] = {
554 sizeof(test512
), sizeof(test1024
),
555 sizeof(test2048
), sizeof(test4096
)
558 # ifndef OPENSSL_NO_DSA
559 DSA
*dsa_key
[DSA_NUM
];
560 long dsa_c
[DSA_NUM
][2];
561 static unsigned int dsa_bits
[DSA_NUM
] = { 512, 1024, 2048 };
563 # ifndef OPENSSL_NO_EC
565 * We only test over the following curves as they are representative, To
566 * add tests over more curves, simply add the curve NID and curve name to
567 * the following arrays and increase the EC_NUM value accordingly.
569 static unsigned int test_curves
[EC_NUM
] = {
572 NID_X9_62_prime192v1
,
574 NID_X9_62_prime256v1
,
589 static const char *test_curves_names
[EC_NUM
] = {
609 static int test_curves_bits
[EC_NUM
] = {
610 160, 192, 224, 256, 384, 521,
611 163, 233, 283, 409, 571,
612 163, 233, 283, 409, 571
617 # ifndef OPENSSL_NO_ECDSA
618 unsigned char ecdsasig
[256];
619 unsigned int ecdsasiglen
;
620 EC_KEY
*ecdsa
[EC_NUM
];
621 long ecdsa_c
[EC_NUM
][2];
624 # ifndef OPENSSL_NO_ECDH
625 EC_KEY
*ecdh_a
[EC_NUM
], *ecdh_b
[EC_NUM
];
626 unsigned char secret_a
[MAX_ECDH_SIZE
], secret_b
[MAX_ECDH_SIZE
];
627 int secret_size_a
, secret_size_b
;
630 long ecdh_c
[EC_NUM
][2];
633 int rsa_doit
[RSA_NUM
];
634 int dsa_doit
[DSA_NUM
];
635 # ifndef OPENSSL_NO_ECDSA
636 int ecdsa_doit
[EC_NUM
];
638 # ifndef OPENSSL_NO_ECDH
639 int ecdh_doit
[EC_NUM
];
643 const EVP_CIPHER
*evp_cipher
= NULL
;
644 const EVP_MD
*evp_md
= NULL
;
655 memset(results
, 0, sizeof(results
));
656 # ifndef OPENSSL_NO_DSA
657 memset(dsa_key
, 0, sizeof(dsa_key
));
659 # ifndef OPENSSL_NO_ECDSA
660 for (i
= 0; i
< EC_NUM
; i
++)
663 # ifndef OPENSSL_NO_ECDH
664 for (i
= 0; i
< EC_NUM
; i
++) {
671 if ((bio_err
= BIO_new(BIO_s_file())) != NULL
)
672 BIO_set_fp(bio_err
, stderr
, BIO_NOCLOSE
| BIO_FP_TEXT
);
674 if (!load_config(bio_err
, NULL
))
677 # ifndef OPENSSL_NO_RSA
678 memset(rsa_key
, 0, sizeof(rsa_key
));
679 for (i
= 0; i
< RSA_NUM
; i
++)
683 if ((buf
= (unsigned char *)OPENSSL_malloc((int)BUFSIZE
)) == NULL
) {
684 BIO_printf(bio_err
, "out of memory\n");
687 if ((buf2
= (unsigned char *)OPENSSL_malloc((int)BUFSIZE
)) == NULL
) {
688 BIO_printf(bio_err
, "out of memory\n");
692 memset(c
, 0, sizeof(c
));
693 memset(DES_iv
, 0, sizeof(DES_iv
));
694 memset(iv
, 0, sizeof(iv
));
696 for (i
= 0; i
< ALGOR_NUM
; i
++)
698 for (i
= 0; i
< RSA_NUM
; i
++)
700 for (i
= 0; i
< DSA_NUM
; i
++)
702 # ifndef OPENSSL_NO_ECDSA
703 for (i
= 0; i
< EC_NUM
; i
++)
706 # ifndef OPENSSL_NO_ECDH
707 for (i
= 0; i
< EC_NUM
; i
++)
715 if ((argc
> 0) && (strcmp(*argv
, "-elapsed") == 0)) {
717 j
--; /* Otherwise, -elapsed gets confused with an
719 } else if ((argc
> 0) && (strcmp(*argv
, "-evp") == 0)) {
723 BIO_printf(bio_err
, "no EVP given\n");
726 evp_cipher
= EVP_get_cipherbyname(*argv
);
728 evp_md
= EVP_get_digestbyname(*argv
);
730 if (!evp_cipher
&& !evp_md
) {
731 BIO_printf(bio_err
, "%s is an unknown cipher or digest\n",
736 } else if (argc
> 0 && !strcmp(*argv
, "-decrypt")) {
738 j
--; /* Otherwise, -elapsed gets confused with an
741 # ifndef OPENSSL_NO_ENGINE
742 else if ((argc
> 0) && (strcmp(*argv
, "-engine") == 0)) {
746 BIO_printf(bio_err
, "no engine given\n");
749 setup_engine(bio_err
, *argv
, 0);
751 * j will be increased again further down. We just don't want
752 * speed to confuse an engine with an algorithm, especially when
753 * none is given (which means all of them should be run)
759 else if ((argc
> 0) && (strcmp(*argv
, "-multi") == 0)) {
763 BIO_printf(bio_err
, "no multi count given\n");
766 multi
= atoi(argv
[0]);
768 BIO_printf(bio_err
, "bad multi count\n");
771 j
--; /* Otherwise, -mr gets confused with an
775 else if (argc
> 0 && !strcmp(*argv
, "-mr")) {
777 j
--; /* Otherwise, -mr gets confused with an
780 # ifndef OPENSSL_NO_MD2
781 if (strcmp(*argv
, "md2") == 0)
785 # ifndef OPENSSL_NO_MDC2
786 if (strcmp(*argv
, "mdc2") == 0)
790 # ifndef OPENSSL_NO_MD4
791 if (strcmp(*argv
, "md4") == 0)
795 # ifndef OPENSSL_NO_MD5
796 if (strcmp(*argv
, "md5") == 0)
800 # ifndef OPENSSL_NO_MD5
801 if (strcmp(*argv
, "hmac") == 0)
805 # ifndef OPENSSL_NO_SHA
806 if (strcmp(*argv
, "sha1") == 0)
808 else if (strcmp(*argv
, "sha") == 0)
809 doit
[D_SHA1
] = 1, doit
[D_SHA256
] = 1, doit
[D_SHA512
] = 1;
811 # ifndef OPENSSL_NO_SHA256
812 if (strcmp(*argv
, "sha256") == 0)
816 # ifndef OPENSSL_NO_SHA512
817 if (strcmp(*argv
, "sha512") == 0)
822 # ifndef OPENSSL_NO_WHIRLPOOL
823 if (strcmp(*argv
, "whirlpool") == 0)
824 doit
[D_WHIRLPOOL
] = 1;
827 # ifndef OPENSSL_NO_RIPEMD
828 if (strcmp(*argv
, "ripemd") == 0)
830 else if (strcmp(*argv
, "rmd160") == 0)
832 else if (strcmp(*argv
, "ripemd160") == 0)
836 # ifndef OPENSSL_NO_RC4
837 if (strcmp(*argv
, "rc4") == 0)
841 # ifndef OPENSSL_NO_DES
842 if (strcmp(*argv
, "des-cbc") == 0)
844 else if (strcmp(*argv
, "des-ede3") == 0)
845 doit
[D_EDE3_DES
] = 1;
848 # ifndef OPENSSL_NO_AES
849 if (strcmp(*argv
, "aes-128-cbc") == 0)
850 doit
[D_CBC_128_AES
] = 1;
851 else if (strcmp(*argv
, "aes-192-cbc") == 0)
852 doit
[D_CBC_192_AES
] = 1;
853 else if (strcmp(*argv
, "aes-256-cbc") == 0)
854 doit
[D_CBC_256_AES
] = 1;
855 else if (strcmp(*argv
, "aes-128-ige") == 0)
856 doit
[D_IGE_128_AES
] = 1;
857 else if (strcmp(*argv
, "aes-192-ige") == 0)
858 doit
[D_IGE_192_AES
] = 1;
859 else if (strcmp(*argv
, "aes-256-ige") == 0)
860 doit
[D_IGE_256_AES
] = 1;
863 # ifndef OPENSSL_NO_CAMELLIA
864 if (strcmp(*argv
, "camellia-128-cbc") == 0)
865 doit
[D_CBC_128_CML
] = 1;
866 else if (strcmp(*argv
, "camellia-192-cbc") == 0)
867 doit
[D_CBC_192_CML
] = 1;
868 else if (strcmp(*argv
, "camellia-256-cbc") == 0)
869 doit
[D_CBC_256_CML
] = 1;
872 # ifndef OPENSSL_NO_RSA
873 # if 0 /* was: #ifdef RSAref */
874 if (strcmp(*argv
, "rsaref") == 0) {
875 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
880 if (strcmp(*argv
, "openssl") == 0) {
881 RSA_set_default_method(RSA_PKCS1_SSLeay());
885 # endif /* !OPENSSL_NO_RSA */
886 if (strcmp(*argv
, "dsa512") == 0)
887 dsa_doit
[R_DSA_512
] = 2;
888 else if (strcmp(*argv
, "dsa1024") == 0)
889 dsa_doit
[R_DSA_1024
] = 2;
890 else if (strcmp(*argv
, "dsa2048") == 0)
891 dsa_doit
[R_DSA_2048
] = 2;
892 else if (strcmp(*argv
, "rsa512") == 0)
893 rsa_doit
[R_RSA_512
] = 2;
894 else if (strcmp(*argv
, "rsa1024") == 0)
895 rsa_doit
[R_RSA_1024
] = 2;
896 else if (strcmp(*argv
, "rsa2048") == 0)
897 rsa_doit
[R_RSA_2048
] = 2;
898 else if (strcmp(*argv
, "rsa4096") == 0)
899 rsa_doit
[R_RSA_4096
] = 2;
901 # ifndef OPENSSL_NO_RC2
902 if (strcmp(*argv
, "rc2-cbc") == 0)
904 else if (strcmp(*argv
, "rc2") == 0)
908 # ifndef OPENSSL_NO_RC5
909 if (strcmp(*argv
, "rc5-cbc") == 0)
911 else if (strcmp(*argv
, "rc5") == 0)
915 # ifndef OPENSSL_NO_IDEA
916 if (strcmp(*argv
, "idea-cbc") == 0)
917 doit
[D_CBC_IDEA
] = 1;
918 else if (strcmp(*argv
, "idea") == 0)
919 doit
[D_CBC_IDEA
] = 1;
922 # ifndef OPENSSL_NO_SEED
923 if (strcmp(*argv
, "seed-cbc") == 0)
924 doit
[D_CBC_SEED
] = 1;
925 else if (strcmp(*argv
, "seed") == 0)
926 doit
[D_CBC_SEED
] = 1;
929 # ifndef OPENSSL_NO_BF
930 if (strcmp(*argv
, "bf-cbc") == 0)
932 else if (strcmp(*argv
, "blowfish") == 0)
934 else if (strcmp(*argv
, "bf") == 0)
938 # ifndef OPENSSL_NO_CAST
939 if (strcmp(*argv
, "cast-cbc") == 0)
940 doit
[D_CBC_CAST
] = 1;
941 else if (strcmp(*argv
, "cast") == 0)
942 doit
[D_CBC_CAST
] = 1;
943 else if (strcmp(*argv
, "cast5") == 0)
944 doit
[D_CBC_CAST
] = 1;
947 # ifndef OPENSSL_NO_DES
948 if (strcmp(*argv
, "des") == 0) {
950 doit
[D_EDE3_DES
] = 1;
953 # ifndef OPENSSL_NO_AES
954 if (strcmp(*argv
, "aes") == 0) {
955 doit
[D_CBC_128_AES
] = 1;
956 doit
[D_CBC_192_AES
] = 1;
957 doit
[D_CBC_256_AES
] = 1;
958 } else if (strcmp(*argv
, "ghash") == 0) {
962 # ifndef OPENSSL_NO_CAMELLIA
963 if (strcmp(*argv
, "camellia") == 0) {
964 doit
[D_CBC_128_CML
] = 1;
965 doit
[D_CBC_192_CML
] = 1;
966 doit
[D_CBC_256_CML
] = 1;
969 # ifndef OPENSSL_NO_RSA
970 if (strcmp(*argv
, "rsa") == 0) {
971 rsa_doit
[R_RSA_512
] = 1;
972 rsa_doit
[R_RSA_1024
] = 1;
973 rsa_doit
[R_RSA_2048
] = 1;
974 rsa_doit
[R_RSA_4096
] = 1;
977 # ifndef OPENSSL_NO_DSA
978 if (strcmp(*argv
, "dsa") == 0) {
979 dsa_doit
[R_DSA_512
] = 1;
980 dsa_doit
[R_DSA_1024
] = 1;
981 dsa_doit
[R_DSA_2048
] = 1;
984 # ifndef OPENSSL_NO_ECDSA
985 if (strcmp(*argv
, "ecdsap160") == 0)
986 ecdsa_doit
[R_EC_P160
] = 2;
987 else if (strcmp(*argv
, "ecdsap192") == 0)
988 ecdsa_doit
[R_EC_P192
] = 2;
989 else if (strcmp(*argv
, "ecdsap224") == 0)
990 ecdsa_doit
[R_EC_P224
] = 2;
991 else if (strcmp(*argv
, "ecdsap256") == 0)
992 ecdsa_doit
[R_EC_P256
] = 2;
993 else if (strcmp(*argv
, "ecdsap384") == 0)
994 ecdsa_doit
[R_EC_P384
] = 2;
995 else if (strcmp(*argv
, "ecdsap521") == 0)
996 ecdsa_doit
[R_EC_P521
] = 2;
997 else if (strcmp(*argv
, "ecdsak163") == 0)
998 ecdsa_doit
[R_EC_K163
] = 2;
999 else if (strcmp(*argv
, "ecdsak233") == 0)
1000 ecdsa_doit
[R_EC_K233
] = 2;
1001 else if (strcmp(*argv
, "ecdsak283") == 0)
1002 ecdsa_doit
[R_EC_K283
] = 2;
1003 else if (strcmp(*argv
, "ecdsak409") == 0)
1004 ecdsa_doit
[R_EC_K409
] = 2;
1005 else if (strcmp(*argv
, "ecdsak571") == 0)
1006 ecdsa_doit
[R_EC_K571
] = 2;
1007 else if (strcmp(*argv
, "ecdsab163") == 0)
1008 ecdsa_doit
[R_EC_B163
] = 2;
1009 else if (strcmp(*argv
, "ecdsab233") == 0)
1010 ecdsa_doit
[R_EC_B233
] = 2;
1011 else if (strcmp(*argv
, "ecdsab283") == 0)
1012 ecdsa_doit
[R_EC_B283
] = 2;
1013 else if (strcmp(*argv
, "ecdsab409") == 0)
1014 ecdsa_doit
[R_EC_B409
] = 2;
1015 else if (strcmp(*argv
, "ecdsab571") == 0)
1016 ecdsa_doit
[R_EC_B571
] = 2;
1017 else if (strcmp(*argv
, "ecdsa") == 0) {
1018 for (i
= 0; i
< EC_NUM
; i
++)
1022 # ifndef OPENSSL_NO_ECDH
1023 if (strcmp(*argv
, "ecdhp160") == 0)
1024 ecdh_doit
[R_EC_P160
] = 2;
1025 else if (strcmp(*argv
, "ecdhp192") == 0)
1026 ecdh_doit
[R_EC_P192
] = 2;
1027 else if (strcmp(*argv
, "ecdhp224") == 0)
1028 ecdh_doit
[R_EC_P224
] = 2;
1029 else if (strcmp(*argv
, "ecdhp256") == 0)
1030 ecdh_doit
[R_EC_P256
] = 2;
1031 else if (strcmp(*argv
, "ecdhp384") == 0)
1032 ecdh_doit
[R_EC_P384
] = 2;
1033 else if (strcmp(*argv
, "ecdhp521") == 0)
1034 ecdh_doit
[R_EC_P521
] = 2;
1035 else if (strcmp(*argv
, "ecdhk163") == 0)
1036 ecdh_doit
[R_EC_K163
] = 2;
1037 else if (strcmp(*argv
, "ecdhk233") == 0)
1038 ecdh_doit
[R_EC_K233
] = 2;
1039 else if (strcmp(*argv
, "ecdhk283") == 0)
1040 ecdh_doit
[R_EC_K283
] = 2;
1041 else if (strcmp(*argv
, "ecdhk409") == 0)
1042 ecdh_doit
[R_EC_K409
] = 2;
1043 else if (strcmp(*argv
, "ecdhk571") == 0)
1044 ecdh_doit
[R_EC_K571
] = 2;
1045 else if (strcmp(*argv
, "ecdhb163") == 0)
1046 ecdh_doit
[R_EC_B163
] = 2;
1047 else if (strcmp(*argv
, "ecdhb233") == 0)
1048 ecdh_doit
[R_EC_B233
] = 2;
1049 else if (strcmp(*argv
, "ecdhb283") == 0)
1050 ecdh_doit
[R_EC_B283
] = 2;
1051 else if (strcmp(*argv
, "ecdhb409") == 0)
1052 ecdh_doit
[R_EC_B409
] = 2;
1053 else if (strcmp(*argv
, "ecdhb571") == 0)
1054 ecdh_doit
[R_EC_B571
] = 2;
1055 else if (strcmp(*argv
, "ecdh") == 0) {
1056 for (i
= 0; i
< EC_NUM
; i
++)
1061 BIO_printf(bio_err
, "Error: bad option or value\n");
1062 BIO_printf(bio_err
, "\n");
1063 BIO_printf(bio_err
, "Available values:\n");
1064 # ifndef OPENSSL_NO_MD2
1065 BIO_printf(bio_err
, "md2 ");
1067 # ifndef OPENSSL_NO_MDC2
1068 BIO_printf(bio_err
, "mdc2 ");
1070 # ifndef OPENSSL_NO_MD4
1071 BIO_printf(bio_err
, "md4 ");
1073 # ifndef OPENSSL_NO_MD5
1074 BIO_printf(bio_err
, "md5 ");
1075 # ifndef OPENSSL_NO_HMAC
1076 BIO_printf(bio_err
, "hmac ");
1079 # ifndef OPENSSL_NO_SHA1
1080 BIO_printf(bio_err
, "sha1 ");
1082 # ifndef OPENSSL_NO_SHA256
1083 BIO_printf(bio_err
, "sha256 ");
1085 # ifndef OPENSSL_NO_SHA512
1086 BIO_printf(bio_err
, "sha512 ");
1088 # ifndef OPENSSL_NO_WHIRLPOOL
1089 BIO_printf(bio_err
, "whirlpool");
1091 # ifndef OPENSSL_NO_RIPEMD160
1092 BIO_printf(bio_err
, "rmd160");
1094 # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1095 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1096 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1097 !defined(OPENSSL_NO_WHIRLPOOL)
1098 BIO_printf(bio_err
, "\n");
1101 # ifndef OPENSSL_NO_IDEA
1102 BIO_printf(bio_err
, "idea-cbc ");
1104 # ifndef OPENSSL_NO_SEED
1105 BIO_printf(bio_err
, "seed-cbc ");
1107 # ifndef OPENSSL_NO_RC2
1108 BIO_printf(bio_err
, "rc2-cbc ");
1110 # ifndef OPENSSL_NO_RC5
1111 BIO_printf(bio_err
, "rc5-cbc ");
1113 # ifndef OPENSSL_NO_BF
1114 BIO_printf(bio_err
, "bf-cbc");
1116 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1117 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1118 BIO_printf(bio_err
, "\n");
1120 # ifndef OPENSSL_NO_DES
1121 BIO_printf(bio_err
, "des-cbc des-ede3 ");
1123 # ifndef OPENSSL_NO_AES
1124 BIO_printf(bio_err
, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1125 BIO_printf(bio_err
, "aes-128-ige aes-192-ige aes-256-ige ");
1127 # ifndef OPENSSL_NO_CAMELLIA
1128 BIO_printf(bio_err
, "\n");
1130 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1132 # ifndef OPENSSL_NO_RC4
1133 BIO_printf(bio_err
, "rc4");
1135 BIO_printf(bio_err
, "\n");
1137 # ifndef OPENSSL_NO_RSA
1138 BIO_printf(bio_err
, "rsa512 rsa1024 rsa2048 rsa4096\n");
1141 # ifndef OPENSSL_NO_DSA
1142 BIO_printf(bio_err
, "dsa512 dsa1024 dsa2048\n");
1144 # ifndef OPENSSL_NO_ECDSA
1145 BIO_printf(bio_err
, "ecdsap160 ecdsap192 ecdsap224 "
1146 "ecdsap256 ecdsap384 ecdsap521\n");
1148 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1150 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1151 BIO_printf(bio_err
, "ecdsa\n");
1153 # ifndef OPENSSL_NO_ECDH
1154 BIO_printf(bio_err
, "ecdhp160 ecdhp192 ecdhp224 "
1155 "ecdhp256 ecdhp384 ecdhp521\n");
1157 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1159 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1160 BIO_printf(bio_err
, "ecdh\n");
1163 # ifndef OPENSSL_NO_IDEA
1164 BIO_printf(bio_err
, "idea ");
1166 # ifndef OPENSSL_NO_SEED
1167 BIO_printf(bio_err
, "seed ");
1169 # ifndef OPENSSL_NO_RC2
1170 BIO_printf(bio_err
, "rc2 ");
1172 # ifndef OPENSSL_NO_DES
1173 BIO_printf(bio_err
, "des ");
1175 # ifndef OPENSSL_NO_AES
1176 BIO_printf(bio_err
, "aes ");
1178 # ifndef OPENSSL_NO_CAMELLIA
1179 BIO_printf(bio_err
, "camellia ");
1181 # ifndef OPENSSL_NO_RSA
1182 BIO_printf(bio_err
, "rsa ");
1184 # ifndef OPENSSL_NO_BF
1185 BIO_printf(bio_err
, "blowfish");
1187 # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1188 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1189 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1190 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1191 BIO_printf(bio_err
, "\n");
1194 BIO_printf(bio_err
, "\n");
1195 BIO_printf(bio_err
, "Available options:\n");
1196 # if defined(TIMES) || defined(USE_TOD)
1197 BIO_printf(bio_err
, "-elapsed "
1198 "measure time in real time instead of CPU user time.\n");
1200 # ifndef OPENSSL_NO_ENGINE
1203 "use engine e, possibly a hardware device.\n");
1205 BIO_printf(bio_err
, "-evp e " "use EVP e.\n");
1208 "time decryption instead of encryption (only EVP).\n");
1211 "produce machine readable output.\n");
1214 "-multi n " "run n benchmarks in parallel.\n");
1224 if (multi
&& do_multi(multi
))
1229 for (i
= 0; i
< ALGOR_NUM
; i
++) {
1233 for (i
= 0; i
< RSA_NUM
; i
++)
1235 for (i
= 0; i
< DSA_NUM
; i
++)
1237 # ifndef OPENSSL_NO_ECDSA
1238 for (i
= 0; i
< EC_NUM
; i
++)
1241 # ifndef OPENSSL_NO_ECDH
1242 for (i
= 0; i
< EC_NUM
; i
++)
1246 for (i
= 0; i
< ALGOR_NUM
; i
++)
1250 if (usertime
== 0 && !mr
)
1252 "You have chosen to measure elapsed time "
1253 "instead of user CPU time.\n");
1255 # ifndef OPENSSL_NO_RSA
1256 for (i
= 0; i
< RSA_NUM
; i
++) {
1257 const unsigned char *p
;
1260 rsa_key
[i
] = d2i_RSAPrivateKey(NULL
, &p
, rsa_data_length
[i
]);
1261 if (rsa_key
[i
] == NULL
) {
1262 BIO_printf(bio_err
, "internal error loading RSA key number %d\n",
1270 : "Loaded RSA key, %d bit modulus and e= 0x",
1271 BN_num_bits(rsa_key
[i
]->n
));
1272 BN_print(bio_err
, rsa_key
[i
]->e
);
1273 BIO_printf(bio_err
, "\n");
1279 # ifndef OPENSSL_NO_DSA
1280 dsa_key
[0] = get_dsa512();
1281 dsa_key
[1] = get_dsa1024();
1282 dsa_key
[2] = get_dsa2048();
1285 # ifndef OPENSSL_NO_DES
1286 DES_set_key_unchecked(&key
, &sch
);
1287 DES_set_key_unchecked(&key2
, &sch2
);
1288 DES_set_key_unchecked(&key3
, &sch3
);
1290 # ifndef OPENSSL_NO_AES
1291 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
1292 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
1293 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
1295 # ifndef OPENSSL_NO_CAMELLIA
1296 Camellia_set_key(key16
, 128, &camellia_ks1
);
1297 Camellia_set_key(ckey24
, 192, &camellia_ks2
);
1298 Camellia_set_key(ckey32
, 256, &camellia_ks3
);
1300 # ifndef OPENSSL_NO_IDEA
1301 idea_set_encrypt_key(key16
, &idea_ks
);
1303 # ifndef OPENSSL_NO_SEED
1304 SEED_set_key(key16
, &seed_ks
);
1306 # ifndef OPENSSL_NO_RC4
1307 RC4_set_key(&rc4_ks
, 16, key16
);
1309 # ifndef OPENSSL_NO_RC2
1310 RC2_set_key(&rc2_ks
, 16, key16
, 128);
1312 # ifndef OPENSSL_NO_RC5
1313 RC5_32_set_key(&rc5_ks
, 16, key16
, 12);
1315 # ifndef OPENSSL_NO_BF
1316 BF_set_key(&bf_ks
, 16, key16
);
1318 # ifndef OPENSSL_NO_CAST
1319 CAST_set_key(&cast_ks
, 16, key16
);
1321 # ifndef OPENSSL_NO_RSA
1322 memset(rsa_c
, 0, sizeof(rsa_c
));
1325 # ifndef OPENSSL_NO_DES
1326 BIO_printf(bio_err
, "First we calculate the approximate speed ...\n");
1332 for (it
= count
; it
; it
--)
1333 DES_ecb_encrypt((DES_cblock
*)buf
,
1334 (DES_cblock
*)buf
, &sch
, DES_ENCRYPT
);
1338 c
[D_MD2
][0] = count
/ 10;
1339 c
[D_MDC2
][0] = count
/ 10;
1340 c
[D_MD4
][0] = count
;
1341 c
[D_MD5
][0] = count
;
1342 c
[D_HMAC
][0] = count
;
1343 c
[D_SHA1
][0] = count
;
1344 c
[D_RMD160
][0] = count
;
1345 c
[D_RC4
][0] = count
* 5;
1346 c
[D_CBC_DES
][0] = count
;
1347 c
[D_EDE3_DES
][0] = count
/ 3;
1348 c
[D_CBC_IDEA
][0] = count
;
1349 c
[D_CBC_SEED
][0] = count
;
1350 c
[D_CBC_RC2
][0] = count
;
1351 c
[D_CBC_RC5
][0] = count
;
1352 c
[D_CBC_BF
][0] = count
;
1353 c
[D_CBC_CAST
][0] = count
;
1354 c
[D_CBC_128_AES
][0] = count
;
1355 c
[D_CBC_192_AES
][0] = count
;
1356 c
[D_CBC_256_AES
][0] = count
;
1357 c
[D_CBC_128_CML
][0] = count
;
1358 c
[D_CBC_192_CML
][0] = count
;
1359 c
[D_CBC_256_CML
][0] = count
;
1360 c
[D_SHA256
][0] = count
;
1361 c
[D_SHA512
][0] = count
;
1362 c
[D_WHIRLPOOL
][0] = count
;
1363 c
[D_IGE_128_AES
][0] = count
;
1364 c
[D_IGE_192_AES
][0] = count
;
1365 c
[D_IGE_256_AES
][0] = count
;
1366 c
[D_GHASH
][0] = count
;
1368 for (i
= 1; i
< SIZE_NUM
; i
++) {
1369 c
[D_MD2
][i
] = c
[D_MD2
][0] * 4 * lengths
[0] / lengths
[i
];
1370 c
[D_MDC2
][i
] = c
[D_MDC2
][0] * 4 * lengths
[0] / lengths
[i
];
1371 c
[D_MD4
][i
] = c
[D_MD4
][0] * 4 * lengths
[0] / lengths
[i
];
1372 c
[D_MD5
][i
] = c
[D_MD5
][0] * 4 * lengths
[0] / lengths
[i
];
1373 c
[D_HMAC
][i
] = c
[D_HMAC
][0] * 4 * lengths
[0] / lengths
[i
];
1374 c
[D_SHA1
][i
] = c
[D_SHA1
][0] * 4 * lengths
[0] / lengths
[i
];
1375 c
[D_RMD160
][i
] = c
[D_RMD160
][0] * 4 * lengths
[0] / lengths
[i
];
1376 c
[D_SHA256
][i
] = c
[D_SHA256
][0] * 4 * lengths
[0] / lengths
[i
];
1377 c
[D_SHA512
][i
] = c
[D_SHA512
][0] * 4 * lengths
[0] / lengths
[i
];
1378 c
[D_WHIRLPOOL
][i
] = c
[D_WHIRLPOOL
][0] * 4 * lengths
[0] / lengths
[i
];
1380 for (i
= 1; i
< SIZE_NUM
; i
++) {
1383 l0
= (long)lengths
[i
- 1];
1384 l1
= (long)lengths
[i
];
1385 c
[D_RC4
][i
] = c
[D_RC4
][i
- 1] * l0
/ l1
;
1386 c
[D_CBC_DES
][i
] = c
[D_CBC_DES
][i
- 1] * l0
/ l1
;
1387 c
[D_EDE3_DES
][i
] = c
[D_EDE3_DES
][i
- 1] * l0
/ l1
;
1388 c
[D_CBC_IDEA
][i
] = c
[D_CBC_IDEA
][i
- 1] * l0
/ l1
;
1389 c
[D_CBC_SEED
][i
] = c
[D_CBC_SEED
][i
- 1] * l0
/ l1
;
1390 c
[D_CBC_RC2
][i
] = c
[D_CBC_RC2
][i
- 1] * l0
/ l1
;
1391 c
[D_CBC_RC5
][i
] = c
[D_CBC_RC5
][i
- 1] * l0
/ l1
;
1392 c
[D_CBC_BF
][i
] = c
[D_CBC_BF
][i
- 1] * l0
/ l1
;
1393 c
[D_CBC_CAST
][i
] = c
[D_CBC_CAST
][i
- 1] * l0
/ l1
;
1394 c
[D_CBC_128_AES
][i
] = c
[D_CBC_128_AES
][i
- 1] * l0
/ l1
;
1395 c
[D_CBC_192_AES
][i
] = c
[D_CBC_192_AES
][i
- 1] * l0
/ l1
;
1396 c
[D_CBC_256_AES
][i
] = c
[D_CBC_256_AES
][i
- 1] * l0
/ l1
;
1397 c
[D_CBC_128_CML
][i
] = c
[D_CBC_128_CML
][i
- 1] * l0
/ l1
;
1398 c
[D_CBC_192_CML
][i
] = c
[D_CBC_192_CML
][i
- 1] * l0
/ l1
;
1399 c
[D_CBC_256_CML
][i
] = c
[D_CBC_256_CML
][i
- 1] * l0
/ l1
;
1400 c
[D_IGE_128_AES
][i
] = c
[D_IGE_128_AES
][i
- 1] * l0
/ l1
;
1401 c
[D_IGE_192_AES
][i
] = c
[D_IGE_192_AES
][i
- 1] * l0
/ l1
;
1402 c
[D_IGE_256_AES
][i
] = c
[D_IGE_256_AES
][i
- 1] * l0
/ l1
;
1404 # ifndef OPENSSL_NO_RSA
1405 rsa_c
[R_RSA_512
][0] = count
/ 2000;
1406 rsa_c
[R_RSA_512
][1] = count
/ 400;
1407 for (i
= 1; i
< RSA_NUM
; i
++) {
1408 rsa_c
[i
][0] = rsa_c
[i
- 1][0] / 8;
1409 rsa_c
[i
][1] = rsa_c
[i
- 1][1] / 4;
1410 if ((rsa_doit
[i
] <= 1) && (rsa_c
[i
][0] == 0))
1413 if (rsa_c
[i
][0] == 0) {
1421 # ifndef OPENSSL_NO_DSA
1422 dsa_c
[R_DSA_512
][0] = count
/ 1000;
1423 dsa_c
[R_DSA_512
][1] = count
/ 1000 / 2;
1424 for (i
= 1; i
< DSA_NUM
; i
++) {
1425 dsa_c
[i
][0] = dsa_c
[i
- 1][0] / 4;
1426 dsa_c
[i
][1] = dsa_c
[i
- 1][1] / 4;
1427 if ((dsa_doit
[i
] <= 1) && (dsa_c
[i
][0] == 0))
1430 if (dsa_c
[i
] == 0) {
1438 # ifndef OPENSSL_NO_ECDSA
1439 ecdsa_c
[R_EC_P160
][0] = count
/ 1000;
1440 ecdsa_c
[R_EC_P160
][1] = count
/ 1000 / 2;
1441 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1442 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1443 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1444 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1447 if (ecdsa_c
[i
] == 0) {
1453 ecdsa_c
[R_EC_K163
][0] = count
/ 1000;
1454 ecdsa_c
[R_EC_K163
][1] = count
/ 1000 / 2;
1455 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1456 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1457 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1458 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1461 if (ecdsa_c
[i
] == 0) {
1467 ecdsa_c
[R_EC_B163
][0] = count
/ 1000;
1468 ecdsa_c
[R_EC_B163
][1] = count
/ 1000 / 2;
1469 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1470 ecdsa_c
[i
][0] = ecdsa_c
[i
- 1][0] / 2;
1471 ecdsa_c
[i
][1] = ecdsa_c
[i
- 1][1] / 2;
1472 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1475 if (ecdsa_c
[i
] == 0) {
1483 # ifndef OPENSSL_NO_ECDH
1484 ecdh_c
[R_EC_P160
][0] = count
/ 1000;
1485 ecdh_c
[R_EC_P160
][1] = count
/ 1000;
1486 for (i
= R_EC_P192
; i
<= R_EC_P521
; i
++) {
1487 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1488 ecdh_c
[i
][1] = ecdh_c
[i
- 1][1] / 2;
1489 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1492 if (ecdh_c
[i
] == 0) {
1498 ecdh_c
[R_EC_K163
][0] = count
/ 1000;
1499 ecdh_c
[R_EC_K163
][1] = count
/ 1000;
1500 for (i
= R_EC_K233
; i
<= R_EC_K571
; i
++) {
1501 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1502 ecdh_c
[i
][1] = ecdh_c
[i
- 1][1] / 2;
1503 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1506 if (ecdh_c
[i
] == 0) {
1512 ecdh_c
[R_EC_B163
][0] = count
/ 1000;
1513 ecdh_c
[R_EC_B163
][1] = count
/ 1000;
1514 for (i
= R_EC_B233
; i
<= R_EC_B571
; i
++) {
1515 ecdh_c
[i
][0] = ecdh_c
[i
- 1][0] / 2;
1516 ecdh_c
[i
][1] = ecdh_c
[i
- 1][1] / 2;
1517 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1520 if (ecdh_c
[i
] == 0) {
1528 # define COND(d) (count < (d))
1529 # define COUNT(d) (d)
1531 /* not worth fixing */
1532 # error "You cannot disable DES on systems without SIGALRM."
1533 # endif /* OPENSSL_NO_DES */
1535 # define COND(c) (run && count<0x7fffffff)
1536 # define COUNT(d) (count)
1538 signal(SIGALRM
, sig_done
);
1540 # endif /* SIGALRM */
1542 # ifndef OPENSSL_NO_MD2
1544 for (j
= 0; j
< SIZE_NUM
; j
++) {
1545 print_message(names
[D_MD2
], c
[D_MD2
][j
], lengths
[j
]);
1547 for (count
= 0, run
= 1; COND(c
[D_MD2
][j
]); count
++)
1548 EVP_Digest(buf
, (unsigned long)lengths
[j
], &(md2
[0]), NULL
,
1551 print_result(D_MD2
, j
, count
, d
);
1555 # ifndef OPENSSL_NO_MDC2
1557 for (j
= 0; j
< SIZE_NUM
; j
++) {
1558 print_message(names
[D_MDC2
], c
[D_MDC2
][j
], lengths
[j
]);
1560 for (count
= 0, run
= 1; COND(c
[D_MDC2
][j
]); count
++)
1561 EVP_Digest(buf
, (unsigned long)lengths
[j
], &(mdc2
[0]), NULL
,
1564 print_result(D_MDC2
, j
, count
, d
);
1569 # ifndef OPENSSL_NO_MD4
1571 for (j
= 0; j
< SIZE_NUM
; j
++) {
1572 print_message(names
[D_MD4
], c
[D_MD4
][j
], lengths
[j
]);
1574 for (count
= 0, run
= 1; COND(c
[D_MD4
][j
]); count
++)
1575 EVP_Digest(&(buf
[0]), (unsigned long)lengths
[j
], &(md4
[0]),
1576 NULL
, EVP_md4(), NULL
);
1578 print_result(D_MD4
, j
, count
, d
);
1583 # ifndef OPENSSL_NO_MD5
1585 for (j
= 0; j
< SIZE_NUM
; j
++) {
1586 print_message(names
[D_MD5
], c
[D_MD5
][j
], lengths
[j
]);
1588 for (count
= 0, run
= 1; COND(c
[D_MD5
][j
]); count
++)
1589 EVP_Digest(&(buf
[0]), (unsigned long)lengths
[j
], &(md5
[0]),
1590 NULL
, EVP_get_digestbyname("md5"), NULL
);
1592 print_result(D_MD5
, j
, count
, d
);
1597 # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1601 HMAC_CTX_init(&hctx
);
1602 HMAC_Init_ex(&hctx
, (unsigned char *)"This is a key...",
1603 16, EVP_md5(), NULL
);
1605 for (j
= 0; j
< SIZE_NUM
; j
++) {
1606 print_message(names
[D_HMAC
], c
[D_HMAC
][j
], lengths
[j
]);
1608 for (count
= 0, run
= 1; COND(c
[D_HMAC
][j
]); count
++) {
1609 HMAC_Init_ex(&hctx
, NULL
, 0, NULL
, NULL
);
1610 HMAC_Update(&hctx
, buf
, lengths
[j
]);
1611 HMAC_Final(&hctx
, &(hmac
[0]), NULL
);
1614 print_result(D_HMAC
, j
, count
, d
);
1616 HMAC_CTX_cleanup(&hctx
);
1619 # ifndef OPENSSL_NO_SHA
1621 for (j
= 0; j
< SIZE_NUM
; j
++) {
1622 print_message(names
[D_SHA1
], c
[D_SHA1
][j
], lengths
[j
]);
1624 for (count
= 0, run
= 1; COND(c
[D_SHA1
][j
]); count
++)
1625 EVP_Digest(buf
, (unsigned long)lengths
[j
], &(sha
[0]), NULL
,
1628 print_result(D_SHA1
, j
, count
, d
);
1631 # ifndef OPENSSL_NO_SHA256
1632 if (doit
[D_SHA256
]) {
1633 for (j
= 0; j
< SIZE_NUM
; j
++) {
1634 print_message(names
[D_SHA256
], c
[D_SHA256
][j
], lengths
[j
]);
1636 for (count
= 0, run
= 1; COND(c
[D_SHA256
][j
]); count
++)
1637 SHA256(buf
, lengths
[j
], sha256
);
1639 print_result(D_SHA256
, j
, count
, d
);
1644 # ifndef OPENSSL_NO_SHA512
1645 if (doit
[D_SHA512
]) {
1646 for (j
= 0; j
< SIZE_NUM
; j
++) {
1647 print_message(names
[D_SHA512
], c
[D_SHA512
][j
], lengths
[j
]);
1649 for (count
= 0, run
= 1; COND(c
[D_SHA512
][j
]); count
++)
1650 SHA512(buf
, lengths
[j
], sha512
);
1652 print_result(D_SHA512
, j
, count
, d
);
1658 # ifndef OPENSSL_NO_WHIRLPOOL
1659 if (doit
[D_WHIRLPOOL
]) {
1660 for (j
= 0; j
< SIZE_NUM
; j
++) {
1661 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][j
], lengths
[j
]);
1663 for (count
= 0, run
= 1; COND(c
[D_WHIRLPOOL
][j
]); count
++)
1664 WHIRLPOOL(buf
, lengths
[j
], whirlpool
);
1666 print_result(D_WHIRLPOOL
, j
, count
, d
);
1671 # ifndef OPENSSL_NO_RIPEMD
1672 if (doit
[D_RMD160
]) {
1673 for (j
= 0; j
< SIZE_NUM
; j
++) {
1674 print_message(names
[D_RMD160
], c
[D_RMD160
][j
], lengths
[j
]);
1676 for (count
= 0, run
= 1; COND(c
[D_RMD160
][j
]); count
++)
1677 EVP_Digest(buf
, (unsigned long)lengths
[j
], &(rmd160
[0]), NULL
,
1678 EVP_ripemd160(), NULL
);
1680 print_result(D_RMD160
, j
, count
, d
);
1684 # ifndef OPENSSL_NO_RC4
1686 for (j
= 0; j
< SIZE_NUM
; j
++) {
1687 print_message(names
[D_RC4
], c
[D_RC4
][j
], lengths
[j
]);
1689 for (count
= 0, run
= 1; COND(c
[D_RC4
][j
]); count
++)
1690 RC4(&rc4_ks
, (unsigned int)lengths
[j
], buf
, buf
);
1692 print_result(D_RC4
, j
, count
, d
);
1696 # ifndef OPENSSL_NO_DES
1697 if (doit
[D_CBC_DES
]) {
1698 for (j
= 0; j
< SIZE_NUM
; j
++) {
1699 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][j
], lengths
[j
]);
1701 for (count
= 0, run
= 1; COND(c
[D_CBC_DES
][j
]); count
++)
1702 DES_ncbc_encrypt(buf
, buf
, lengths
[j
], &sch
,
1703 &DES_iv
, DES_ENCRYPT
);
1705 print_result(D_CBC_DES
, j
, count
, d
);
1709 if (doit
[D_EDE3_DES
]) {
1710 for (j
= 0; j
< SIZE_NUM
; j
++) {
1711 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][j
], lengths
[j
]);
1713 for (count
= 0, run
= 1; COND(c
[D_EDE3_DES
][j
]); count
++)
1714 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[j
],
1716 &DES_iv
, DES_ENCRYPT
);
1718 print_result(D_EDE3_DES
, j
, count
, d
);
1722 # ifndef OPENSSL_NO_AES
1723 if (doit
[D_CBC_128_AES
]) {
1724 for (j
= 0; j
< SIZE_NUM
; j
++) {
1725 print_message(names
[D_CBC_128_AES
], c
[D_CBC_128_AES
][j
],
1728 for (count
= 0, run
= 1; COND(c
[D_CBC_128_AES
][j
]); count
++)
1729 AES_cbc_encrypt(buf
, buf
,
1730 (unsigned long)lengths
[j
], &aes_ks1
,
1733 print_result(D_CBC_128_AES
, j
, count
, d
);
1736 if (doit
[D_CBC_192_AES
]) {
1737 for (j
= 0; j
< SIZE_NUM
; j
++) {
1738 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][j
],
1741 for (count
= 0, run
= 1; COND(c
[D_CBC_192_AES
][j
]); count
++)
1742 AES_cbc_encrypt(buf
, buf
,
1743 (unsigned long)lengths
[j
], &aes_ks2
,
1746 print_result(D_CBC_192_AES
, j
, count
, d
);
1749 if (doit
[D_CBC_256_AES
]) {
1750 for (j
= 0; j
< SIZE_NUM
; j
++) {
1751 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][j
],
1754 for (count
= 0, run
= 1; COND(c
[D_CBC_256_AES
][j
]); count
++)
1755 AES_cbc_encrypt(buf
, buf
,
1756 (unsigned long)lengths
[j
], &aes_ks3
,
1759 print_result(D_CBC_256_AES
, j
, count
, d
);
1763 if (doit
[D_IGE_128_AES
]) {
1764 for (j
= 0; j
< SIZE_NUM
; j
++) {
1765 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][j
],
1768 for (count
= 0, run
= 1; COND(c
[D_IGE_128_AES
][j
]); count
++)
1769 AES_ige_encrypt(buf
, buf2
,
1770 (unsigned long)lengths
[j
], &aes_ks1
,
1773 print_result(D_IGE_128_AES
, j
, count
, d
);
1776 if (doit
[D_IGE_192_AES
]) {
1777 for (j
= 0; j
< SIZE_NUM
; j
++) {
1778 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][j
],
1781 for (count
= 0, run
= 1; COND(c
[D_IGE_192_AES
][j
]); count
++)
1782 AES_ige_encrypt(buf
, buf2
,
1783 (unsigned long)lengths
[j
], &aes_ks2
,
1786 print_result(D_IGE_192_AES
, j
, count
, d
);
1789 if (doit
[D_IGE_256_AES
]) {
1790 for (j
= 0; j
< SIZE_NUM
; j
++) {
1791 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][j
],
1794 for (count
= 0, run
= 1; COND(c
[D_IGE_256_AES
][j
]); count
++)
1795 AES_ige_encrypt(buf
, buf2
,
1796 (unsigned long)lengths
[j
], &aes_ks3
,
1799 print_result(D_IGE_256_AES
, j
, count
, d
);
1802 if (doit
[D_GHASH
]) {
1803 GCM128_CONTEXT
*ctx
=
1804 CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
1805 CRYPTO_gcm128_setiv(ctx
, (unsigned char *)"0123456789ab", 12);
1807 for (j
= 0; j
< SIZE_NUM
; j
++) {
1808 print_message(names
[D_GHASH
], c
[D_GHASH
][j
], lengths
[j
]);
1810 for (count
= 0, run
= 1; COND(c
[D_GHASH
][j
]); count
++)
1811 CRYPTO_gcm128_aad(ctx
, buf
, lengths
[j
]);
1813 print_result(D_GHASH
, j
, count
, d
);
1815 CRYPTO_gcm128_release(ctx
);
1818 # ifndef OPENSSL_NO_CAMELLIA
1819 if (doit
[D_CBC_128_CML
]) {
1820 for (j
= 0; j
< SIZE_NUM
; j
++) {
1821 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][j
],
1824 for (count
= 0, run
= 1; COND(c
[D_CBC_128_CML
][j
]); count
++)
1825 Camellia_cbc_encrypt(buf
, buf
,
1826 (unsigned long)lengths
[j
], &camellia_ks1
,
1827 iv
, CAMELLIA_ENCRYPT
);
1829 print_result(D_CBC_128_CML
, j
, count
, d
);
1832 if (doit
[D_CBC_192_CML
]) {
1833 for (j
= 0; j
< SIZE_NUM
; j
++) {
1834 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][j
],
1837 for (count
= 0, run
= 1; COND(c
[D_CBC_192_CML
][j
]); count
++)
1838 Camellia_cbc_encrypt(buf
, buf
,
1839 (unsigned long)lengths
[j
], &camellia_ks2
,
1840 iv
, CAMELLIA_ENCRYPT
);
1842 print_result(D_CBC_192_CML
, j
, count
, d
);
1845 if (doit
[D_CBC_256_CML
]) {
1846 for (j
= 0; j
< SIZE_NUM
; j
++) {
1847 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][j
],
1850 for (count
= 0, run
= 1; COND(c
[D_CBC_256_CML
][j
]); count
++)
1851 Camellia_cbc_encrypt(buf
, buf
,
1852 (unsigned long)lengths
[j
], &camellia_ks3
,
1853 iv
, CAMELLIA_ENCRYPT
);
1855 print_result(D_CBC_256_CML
, j
, count
, d
);
1859 # ifndef OPENSSL_NO_IDEA
1860 if (doit
[D_CBC_IDEA
]) {
1861 for (j
= 0; j
< SIZE_NUM
; j
++) {
1862 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][j
], lengths
[j
]);
1864 for (count
= 0, run
= 1; COND(c
[D_CBC_IDEA
][j
]); count
++)
1865 idea_cbc_encrypt(buf
, buf
,
1866 (unsigned long)lengths
[j
], &idea_ks
,
1869 print_result(D_CBC_IDEA
, j
, count
, d
);
1873 # ifndef OPENSSL_NO_SEED
1874 if (doit
[D_CBC_SEED
]) {
1875 for (j
= 0; j
< SIZE_NUM
; j
++) {
1876 print_message(names
[D_CBC_SEED
], c
[D_CBC_SEED
][j
], lengths
[j
]);
1878 for (count
= 0, run
= 1; COND(c
[D_CBC_SEED
][j
]); count
++)
1879 SEED_cbc_encrypt(buf
, buf
,
1880 (unsigned long)lengths
[j
], &seed_ks
, iv
, 1);
1882 print_result(D_CBC_SEED
, j
, count
, d
);
1886 # ifndef OPENSSL_NO_RC2
1887 if (doit
[D_CBC_RC2
]) {
1888 for (j
= 0; j
< SIZE_NUM
; j
++) {
1889 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][j
], lengths
[j
]);
1891 for (count
= 0, run
= 1; COND(c
[D_CBC_RC2
][j
]); count
++)
1892 RC2_cbc_encrypt(buf
, buf
,
1893 (unsigned long)lengths
[j
], &rc2_ks
,
1896 print_result(D_CBC_RC2
, j
, count
, d
);
1900 # ifndef OPENSSL_NO_RC5
1901 if (doit
[D_CBC_RC5
]) {
1902 for (j
= 0; j
< SIZE_NUM
; j
++) {
1903 print_message(names
[D_CBC_RC5
], c
[D_CBC_RC5
][j
], lengths
[j
]);
1905 for (count
= 0, run
= 1; COND(c
[D_CBC_RC5
][j
]); count
++)
1906 RC5_32_cbc_encrypt(buf
, buf
,
1907 (unsigned long)lengths
[j
], &rc5_ks
,
1910 print_result(D_CBC_RC5
, j
, count
, d
);
1914 # ifndef OPENSSL_NO_BF
1915 if (doit
[D_CBC_BF
]) {
1916 for (j
= 0; j
< SIZE_NUM
; j
++) {
1917 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][j
], lengths
[j
]);
1919 for (count
= 0, run
= 1; COND(c
[D_CBC_BF
][j
]); count
++)
1920 BF_cbc_encrypt(buf
, buf
,
1921 (unsigned long)lengths
[j
], &bf_ks
,
1924 print_result(D_CBC_BF
, j
, count
, d
);
1928 # ifndef OPENSSL_NO_CAST
1929 if (doit
[D_CBC_CAST
]) {
1930 for (j
= 0; j
< SIZE_NUM
; j
++) {
1931 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][j
], lengths
[j
]);
1933 for (count
= 0, run
= 1; COND(c
[D_CBC_CAST
][j
]); count
++)
1934 CAST_cbc_encrypt(buf
, buf
,
1935 (unsigned long)lengths
[j
], &cast_ks
,
1938 print_result(D_CBC_CAST
, j
, count
, d
);
1944 for (j
= 0; j
< SIZE_NUM
; j
++) {
1949 names
[D_EVP
] = OBJ_nid2ln(evp_cipher
->nid
);
1951 * -O3 -fschedule-insns messes up an optimization here!
1952 * names[D_EVP] somehow becomes NULL
1954 print_message(names
[D_EVP
], save_count
, lengths
[j
]);
1956 EVP_CIPHER_CTX_init(&ctx
);
1958 EVP_DecryptInit_ex(&ctx
, evp_cipher
, NULL
, key16
, iv
);
1960 EVP_EncryptInit_ex(&ctx
, evp_cipher
, NULL
, key16
, iv
);
1961 EVP_CIPHER_CTX_set_padding(&ctx
, 0);
1965 for (count
= 0, run
= 1;
1966 COND(save_count
* 4 * lengths
[0] / lengths
[j
]);
1968 EVP_DecryptUpdate(&ctx
, buf
, &outl
, buf
, lengths
[j
]);
1970 for (count
= 0, run
= 1;
1971 COND(save_count
* 4 * lengths
[0] / lengths
[j
]);
1973 EVP_EncryptUpdate(&ctx
, buf
, &outl
, buf
, lengths
[j
]);
1975 EVP_DecryptFinal_ex(&ctx
, buf
, &outl
);
1977 EVP_EncryptFinal_ex(&ctx
, buf
, &outl
);
1979 EVP_CIPHER_CTX_cleanup(&ctx
);
1982 names
[D_EVP
] = OBJ_nid2ln(evp_md
->type
);
1983 print_message(names
[D_EVP
], save_count
, lengths
[j
]);
1986 for (count
= 0, run
= 1;
1987 COND(save_count
* 4 * lengths
[0] / lengths
[j
]); count
++)
1988 EVP_Digest(buf
, lengths
[j
], &(md
[0]), NULL
, evp_md
, NULL
);
1992 print_result(D_EVP
, j
, count
, d
);
1996 RAND_pseudo_bytes(buf
, 36);
1997 # ifndef OPENSSL_NO_RSA
1998 for (j
= 0; j
< RSA_NUM
; j
++) {
2002 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, &rsa_num
, rsa_key
[j
]);
2005 "RSA sign failure. No RSA sign will be done.\n");
2006 ERR_print_errors(bio_err
);
2009 pkey_print_message("private", "rsa",
2010 rsa_c
[j
][0], rsa_bits
[j
], RSA_SECONDS
);
2011 /* RSA_blinding_on(rsa_key[j],NULL); */
2013 for (count
= 0, run
= 1; COND(rsa_c
[j
][0]); count
++) {
2014 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
,
2015 &rsa_num
, rsa_key
[j
]);
2017 BIO_printf(bio_err
, "RSA sign failure\n");
2018 ERR_print_errors(bio_err
);
2025 mr
? "+R1:%ld:%d:%.2f\n"
2026 : "%ld %d bit private RSA's in %.2fs\n",
2027 count
, rsa_bits
[j
], d
);
2028 rsa_results
[j
][0] = d
/ (double)count
;
2033 ret
= RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[j
]);
2036 "RSA verify failure. No RSA verify will be done.\n");
2037 ERR_print_errors(bio_err
);
2040 pkey_print_message("public", "rsa",
2041 rsa_c
[j
][1], rsa_bits
[j
], RSA_SECONDS
);
2043 for (count
= 0, run
= 1; COND(rsa_c
[j
][1]); count
++) {
2044 ret
= RSA_verify(NID_md5_sha1
, buf
, 36, buf2
,
2045 rsa_num
, rsa_key
[j
]);
2047 BIO_printf(bio_err
, "RSA verify failure\n");
2048 ERR_print_errors(bio_err
);
2055 mr
? "+R2:%ld:%d:%.2f\n"
2056 : "%ld %d bit public RSA's in %.2fs\n",
2057 count
, rsa_bits
[j
], d
);
2058 rsa_results
[j
][1] = d
/ (double)count
;
2062 if (rsa_count
<= 1) {
2063 /* if longer than 10s, don't do any more */
2064 for (j
++; j
< RSA_NUM
; j
++)
2070 RAND_pseudo_bytes(buf
, 20);
2071 # ifndef OPENSSL_NO_DSA
2072 if (RAND_status() != 1) {
2073 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2076 for (j
= 0; j
< DSA_NUM
; j
++) {
2083 /* DSA_generate_key(dsa_key[j]); */
2084 /* DSA_sign_setup(dsa_key[j],NULL); */
2085 ret
= DSA_sign(EVP_PKEY_DSA
, buf
, 20, buf2
, &kk
, dsa_key
[j
]);
2088 "DSA sign failure. No DSA sign will be done.\n");
2089 ERR_print_errors(bio_err
);
2092 pkey_print_message("sign", "dsa",
2093 dsa_c
[j
][0], dsa_bits
[j
], DSA_SECONDS
);
2095 for (count
= 0, run
= 1; COND(dsa_c
[j
][0]); count
++) {
2096 ret
= DSA_sign(EVP_PKEY_DSA
, buf
, 20, buf2
, &kk
, dsa_key
[j
]);
2098 BIO_printf(bio_err
, "DSA sign failure\n");
2099 ERR_print_errors(bio_err
);
2106 mr
? "+R3:%ld:%d:%.2f\n"
2107 : "%ld %d bit DSA signs in %.2fs\n",
2108 count
, dsa_bits
[j
], d
);
2109 dsa_results
[j
][0] = d
/ (double)count
;
2113 ret
= DSA_verify(EVP_PKEY_DSA
, buf
, 20, buf2
, kk
, dsa_key
[j
]);
2116 "DSA verify failure. No DSA verify will be done.\n");
2117 ERR_print_errors(bio_err
);
2120 pkey_print_message("verify", "dsa",
2121 dsa_c
[j
][1], dsa_bits
[j
], DSA_SECONDS
);
2123 for (count
= 0, run
= 1; COND(dsa_c
[j
][1]); count
++) {
2124 ret
= DSA_verify(EVP_PKEY_DSA
, buf
, 20, buf2
, kk
, dsa_key
[j
]);
2126 BIO_printf(bio_err
, "DSA verify failure\n");
2127 ERR_print_errors(bio_err
);
2134 mr
? "+R4:%ld:%d:%.2f\n"
2135 : "%ld %d bit DSA verify in %.2fs\n",
2136 count
, dsa_bits
[j
], d
);
2137 dsa_results
[j
][1] = d
/ (double)count
;
2140 if (rsa_count
<= 1) {
2141 /* if longer than 10s, don't do any more */
2142 for (j
++; j
< DSA_NUM
; j
++)
2150 # ifndef OPENSSL_NO_ECDSA
2151 if (RAND_status() != 1) {
2152 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2155 for (j
= 0; j
< EC_NUM
; j
++) {
2159 continue; /* Ignore Curve */
2160 ecdsa
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2161 if (ecdsa
[j
] == NULL
) {
2162 BIO_printf(bio_err
, "ECDSA failure.\n");
2163 ERR_print_errors(bio_err
);
2167 EC_KEY_precompute_mult(ecdsa
[j
], NULL
);
2169 /* Perform ECDSA signature test */
2170 EC_KEY_generate_key(ecdsa
[j
]);
2171 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
, &ecdsasiglen
, ecdsa
[j
]);
2174 "ECDSA sign failure. No ECDSA sign will be done.\n");
2175 ERR_print_errors(bio_err
);
2178 pkey_print_message("sign", "ecdsa",
2180 test_curves_bits
[j
], ECDSA_SECONDS
);
2183 for (count
= 0, run
= 1; COND(ecdsa_c
[j
][0]); count
++) {
2184 ret
= ECDSA_sign(0, buf
, 20,
2185 ecdsasig
, &ecdsasiglen
, ecdsa
[j
]);
2187 BIO_printf(bio_err
, "ECDSA sign failure\n");
2188 ERR_print_errors(bio_err
);
2196 mr
? "+R5:%ld:%d:%.2f\n" :
2197 "%ld %d bit ECDSA signs in %.2fs \n",
2198 count
, test_curves_bits
[j
], d
);
2199 ecdsa_results
[j
][0] = d
/ (double)count
;
2203 /* Perform ECDSA verification test */
2204 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[j
]);
2207 "ECDSA verify failure. No ECDSA verify will be done.\n");
2208 ERR_print_errors(bio_err
);
2211 pkey_print_message("verify", "ecdsa",
2213 test_curves_bits
[j
], ECDSA_SECONDS
);
2215 for (count
= 0, run
= 1; COND(ecdsa_c
[j
][1]); count
++) {
2217 ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
,
2220 BIO_printf(bio_err
, "ECDSA verify failure\n");
2221 ERR_print_errors(bio_err
);
2228 mr
? "+R6:%ld:%d:%.2f\n"
2229 : "%ld %d bit ECDSA verify in %.2fs\n",
2230 count
, test_curves_bits
[j
], d
);
2231 ecdsa_results
[j
][1] = d
/ (double)count
;
2234 if (rsa_count
<= 1) {
2235 /* if longer than 10s, don't do any more */
2236 for (j
++; j
< EC_NUM
; j
++)
2245 # ifndef OPENSSL_NO_ECDH
2246 if (RAND_status() != 1) {
2247 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2250 for (j
= 0; j
< EC_NUM
; j
++) {
2253 ecdh_a
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2254 ecdh_b
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2255 if ((ecdh_a
[j
] == NULL
) || (ecdh_b
[j
] == NULL
)) {
2256 BIO_printf(bio_err
, "ECDH failure.\n");
2257 ERR_print_errors(bio_err
);
2260 /* generate two ECDH key pairs */
2261 if (!EC_KEY_generate_key(ecdh_a
[j
]) ||
2262 !EC_KEY_generate_key(ecdh_b
[j
])) {
2263 BIO_printf(bio_err
, "ECDH key generation failure.\n");
2264 ERR_print_errors(bio_err
);
2268 * If field size is not more than 24 octets, then use SHA-1
2269 * hash of result; otherwise, use result (see section 4.8 of
2270 * draft-ietf-tls-ecc-03.txt).
2272 int field_size
, outlen
;
2273 void *(*kdf
) (const void *in
, size_t inlen
, void *out
,
2276 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a
[j
]));
2277 if (field_size
<= 24 * 8) {
2278 outlen
= KDF1_SHA1_len
;
2281 outlen
= (field_size
+ 7) / 8;
2285 ECDH_compute_key(secret_a
, outlen
,
2286 EC_KEY_get0_public_key(ecdh_b
[j
]),
2289 ECDH_compute_key(secret_b
, outlen
,
2290 EC_KEY_get0_public_key(ecdh_a
[j
]),
2292 if (secret_size_a
!= secret_size_b
)
2297 for (secret_idx
= 0; (secret_idx
< secret_size_a
)
2298 && (ecdh_checks
== 1); secret_idx
++) {
2299 if (secret_a
[secret_idx
] != secret_b
[secret_idx
])
2303 if (ecdh_checks
== 0) {
2304 BIO_printf(bio_err
, "ECDH computations don't match.\n");
2305 ERR_print_errors(bio_err
);
2309 pkey_print_message("", "ecdh",
2311 test_curves_bits
[j
], ECDH_SECONDS
);
2313 for (count
= 0, run
= 1; COND(ecdh_c
[j
][0]); count
++) {
2314 ECDH_compute_key(secret_a
, outlen
,
2315 EC_KEY_get0_public_key(ecdh_b
[j
]),
2320 mr
? "+R7:%ld:%d:%.2f\n" :
2321 "%ld %d-bit ECDH ops in %.2fs\n", count
,
2322 test_curves_bits
[j
], d
);
2323 ecdh_results
[j
][0] = d
/ (double)count
;
2328 if (rsa_count
<= 1) {
2329 /* if longer than 10s, don't do any more */
2330 for (j
++; j
< EC_NUM
; j
++)
2341 fprintf(stdout
, "%s\n", SSLeay_version(SSLEAY_VERSION
));
2342 fprintf(stdout
, "%s\n", SSLeay_version(SSLEAY_BUILT_ON
));
2344 printf("%s ", BN_options());
2345 # ifndef OPENSSL_NO_MD2
2346 printf("%s ", MD2_options());
2348 # ifndef OPENSSL_NO_RC4
2349 printf("%s ", RC4_options());
2351 # ifndef OPENSSL_NO_DES
2352 printf("%s ", DES_options());
2354 # ifndef OPENSSL_NO_AES
2355 printf("%s ", AES_options());
2357 # ifndef OPENSSL_NO_IDEA
2358 printf("%s ", idea_options());
2360 # ifndef OPENSSL_NO_BF
2361 printf("%s ", BF_options());
2363 fprintf(stdout
, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS
));
2368 fprintf(stdout
, "+H");
2371 "The 'numbers' are in 1000s of bytes per second processed.\n");
2372 fprintf(stdout
, "type ");
2374 for (j
= 0; j
< SIZE_NUM
; j
++)
2375 fprintf(stdout
, mr
? ":%d" : "%7d bytes", lengths
[j
]);
2376 fprintf(stdout
, "\n");
2379 for (k
= 0; k
< ALGOR_NUM
; k
++) {
2383 fprintf(stdout
, "+F:%d:%s", k
, names
[k
]);
2385 fprintf(stdout
, "%-13s", names
[k
]);
2386 for (j
= 0; j
< SIZE_NUM
; j
++) {
2387 if (results
[k
][j
] > 10000 && !mr
)
2388 fprintf(stdout
, " %11.2fk", results
[k
][j
] / 1e3
);
2390 fprintf(stdout
, mr
? ":%.2f" : " %11.2f ", results
[k
][j
]);
2392 fprintf(stdout
, "\n");
2394 # ifndef OPENSSL_NO_RSA
2396 for (k
= 0; k
< RSA_NUM
; k
++) {
2400 printf("%18ssign verify sign/s verify/s\n", " ");
2404 fprintf(stdout
, "+F2:%u:%u:%f:%f\n",
2405 k
, rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1]);
2407 fprintf(stdout
, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2408 rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1],
2409 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1]);
2412 # ifndef OPENSSL_NO_DSA
2414 for (k
= 0; k
< DSA_NUM
; k
++) {
2418 printf("%18ssign verify sign/s verify/s\n", " ");
2422 fprintf(stdout
, "+F3:%u:%u:%f:%f\n",
2423 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
2425 fprintf(stdout
, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2426 dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1],
2427 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1]);
2430 # ifndef OPENSSL_NO_ECDSA
2432 for (k
= 0; k
< EC_NUM
; k
++) {
2436 printf("%30ssign verify sign/s verify/s\n", " ");
2441 fprintf(stdout
, "+F4:%u:%u:%f:%f\n",
2442 k
, test_curves_bits
[k
],
2443 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
2446 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2447 test_curves_bits
[k
],
2448 test_curves_names
[k
],
2449 ecdsa_results
[k
][0], ecdsa_results
[k
][1],
2450 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1]);
2454 # ifndef OPENSSL_NO_ECDH
2456 for (k
= 0; k
< EC_NUM
; k
++) {
2460 printf("%30sop op/s\n", " ");
2464 fprintf(stdout
, "+F5:%u:%u:%f:%f\n",
2465 k
, test_curves_bits
[k
],
2466 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
2469 fprintf(stdout
, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2470 test_curves_bits
[k
],
2471 test_curves_names
[k
],
2472 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
2479 ERR_print_errors(bio_err
);
2484 # ifndef OPENSSL_NO_RSA
2485 for (i
= 0; i
< RSA_NUM
; i
++)
2486 if (rsa_key
[i
] != NULL
)
2487 RSA_free(rsa_key
[i
]);
2489 # ifndef OPENSSL_NO_DSA
2490 for (i
= 0; i
< DSA_NUM
; i
++)
2491 if (dsa_key
[i
] != NULL
)
2492 DSA_free(dsa_key
[i
]);
2495 # ifndef OPENSSL_NO_ECDSA
2496 for (i
= 0; i
< EC_NUM
; i
++)
2497 if (ecdsa
[i
] != NULL
)
2498 EC_KEY_free(ecdsa
[i
]);
2500 # ifndef OPENSSL_NO_ECDH
2501 for (i
= 0; i
< EC_NUM
; i
++) {
2502 if (ecdh_a
[i
] != NULL
)
2503 EC_KEY_free(ecdh_a
[i
]);
2504 if (ecdh_b
[i
] != NULL
)
2505 EC_KEY_free(ecdh_b
[i
]);
2513 static void print_message(const char *s
, long num
, int length
)
2517 mr
? "+DT:%s:%d:%d\n"
2518 : "Doing %s for %ds on %d size blocks: ", s
, SECONDS
, length
);
2519 (void)BIO_flush(bio_err
);
2523 mr
? "+DN:%s:%ld:%d\n"
2524 : "Doing %s %ld times on %d size blocks: ", s
, num
, length
);
2525 (void)BIO_flush(bio_err
);
2532 static void pkey_print_message(const char *str
, const char *str2
, long num
,
2537 mr
? "+DTP:%d:%s:%s:%d\n"
2538 : "Doing %d bit %s %s's for %ds: ", bits
, str
, str2
, tm
);
2539 (void)BIO_flush(bio_err
);
2543 mr
? "+DNP:%ld:%d:%s:%s\n"
2544 : "Doing %ld %d bit %s %s's: ", num
, bits
, str
, str2
);
2545 (void)BIO_flush(bio_err
);
2552 static void print_result(int alg
, int run_no
, int count
, double time_used
)
2555 mr
? "+R:%d:%s:%f\n"
2556 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
2557 results
[alg
][run_no
] = ((double)count
) / time_used
* lengths
[run_no
];
2561 static char *sstrsep(char **string
, const char *delim
)
2564 char *token
= *string
;
2569 memset(isdelim
, 0, sizeof isdelim
);
2573 isdelim
[(unsigned char)(*delim
)] = 1;
2577 while (!isdelim
[(unsigned char)(**string
)]) {
2589 static int do_multi(int multi
)
2594 static char sep
[] = ":";
2596 fds
= malloc(multi
* sizeof *fds
);
2597 for (n
= 0; n
< multi
; ++n
) {
2598 if (pipe(fd
) == -1) {
2599 fprintf(stderr
, "pipe failure\n");
2610 if (dup(fd
[1]) == -1) {
2611 fprintf(stderr
, "dup failed\n");
2620 printf("Forked child %d\n", n
);
2623 /* for now, assume the pipe is long enough to take all the output */
2624 for (n
= 0; n
< multi
; ++n
) {
2629 f
= fdopen(fds
[n
], "r");
2630 while (fgets(buf
, sizeof buf
, f
)) {
2631 p
= strchr(buf
, '\n');
2634 if (buf
[0] != '+') {
2635 fprintf(stderr
, "Don't understand line '%s' from child %d\n",
2639 printf("Got: %s from %d\n", buf
, n
);
2640 if (!strncmp(buf
, "+F:", 3)) {
2645 alg
= atoi(sstrsep(&p
, sep
));
2647 for (j
= 0; j
< SIZE_NUM
; ++j
)
2648 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
2649 } else if (!strncmp(buf
, "+F2:", 4)) {
2654 k
= atoi(sstrsep(&p
, sep
));
2657 d
= atof(sstrsep(&p
, sep
));
2659 rsa_results
[k
][0] = 1 / (1 / rsa_results
[k
][0] + 1 / d
);
2661 rsa_results
[k
][0] = d
;
2663 d
= atof(sstrsep(&p
, sep
));
2665 rsa_results
[k
][1] = 1 / (1 / rsa_results
[k
][1] + 1 / d
);
2667 rsa_results
[k
][1] = d
;
2669 # ifndef OPENSSL_NO_DSA
2670 else if (!strncmp(buf
, "+F3:", 4)) {
2675 k
= atoi(sstrsep(&p
, sep
));
2678 d
= atof(sstrsep(&p
, sep
));
2680 dsa_results
[k
][0] = 1 / (1 / dsa_results
[k
][0] + 1 / d
);
2682 dsa_results
[k
][0] = d
;
2684 d
= atof(sstrsep(&p
, sep
));
2686 dsa_results
[k
][1] = 1 / (1 / dsa_results
[k
][1] + 1 / d
);
2688 dsa_results
[k
][1] = d
;
2691 # ifndef OPENSSL_NO_ECDSA
2692 else if (!strncmp(buf
, "+F4:", 4)) {
2697 k
= atoi(sstrsep(&p
, sep
));
2700 d
= atof(sstrsep(&p
, sep
));
2702 ecdsa_results
[k
][0] =
2703 1 / (1 / ecdsa_results
[k
][0] + 1 / d
);
2705 ecdsa_results
[k
][0] = d
;
2707 d
= atof(sstrsep(&p
, sep
));
2709 ecdsa_results
[k
][1] =
2710 1 / (1 / ecdsa_results
[k
][1] + 1 / d
);
2712 ecdsa_results
[k
][1] = d
;
2716 # ifndef OPENSSL_NO_ECDH
2717 else if (!strncmp(buf
, "+F5:", 4)) {
2722 k
= atoi(sstrsep(&p
, sep
));
2725 d
= atof(sstrsep(&p
, sep
));
2727 ecdh_results
[k
][0] = 1 / (1 / ecdh_results
[k
][0] + 1 / d
);
2729 ecdh_results
[k
][0] = d
;
2734 else if (!strncmp(buf
, "+H:", 3)) {
2736 fprintf(stderr
, "Unknown type '%s' from child %d\n", buf
, n
);