1 /* $OpenBSD: speed.c,v 1.19 2016/08/22 04:33:07 deraadt Exp $ */
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
77 #define RSA_SECONDS 10
78 #define DSA_SECONDS 10
79 #define ECDSA_SECONDS 10
80 #define ECDH_SECONDS 10
92 #include <openssl/bn.h>
93 #include <openssl/crypto.h>
94 #include <openssl/err.h>
95 #include <openssl/evp.h>
96 #include <openssl/modes.h>
97 #include <openssl/objects.h>
98 #include <openssl/x509.h>
100 #ifndef OPENSSL_NO_AES
101 #include <openssl/aes.h>
103 #ifndef OPENSSL_NO_BF
104 #include <openssl/blowfish.h>
106 #ifndef OPENSSL_NO_CAST
107 #include <openssl/cast.h>
109 #ifndef OPENSSL_NO_CAMELLIA
110 #include <openssl/camellia.h>
112 #ifndef OPENSSL_NO_DES
113 #include <openssl/des.h>
115 #include <openssl/dsa.h>
116 #include <openssl/ecdh.h>
117 #include <openssl/ecdsa.h>
118 #ifndef OPENSSL_NO_HMAC
119 #include <openssl/hmac.h>
121 #ifndef OPENSSL_NO_IDEA
122 #include <openssl/idea.h>
124 #ifndef OPENSSL_NO_MD4
125 #include <openssl/md4.h>
127 #ifndef OPENSSL_NO_MD5
128 #include <openssl/md5.h>
130 #ifndef OPENSSL_NO_RC2
131 #include <openssl/rc2.h>
133 #ifndef OPENSSL_NO_RC4
134 #include <openssl/rc4.h>
136 #include <openssl/rsa.h>
137 #ifndef OPENSSL_NO_RIPEMD
138 #include <openssl/ripemd.h>
140 #ifndef OPENSSL_NO_SHA
141 #include <openssl/sha.h>
143 #ifndef OPENSSL_NO_WHIRLPOOL
144 #include <openssl/whrlpool.h>
147 #include "./testdsa.h"
148 #include "./testrsa.h"
150 #define BUFSIZE (1024*8+64)
154 static int usertime
= 1;
156 static double Time_F(int s
);
157 static void print_message(const char *s
, long num
, int length
);
159 pkey_print_message(const char *str
, const char *str2
,
160 long num
, int bits
, int sec
);
161 static void print_result(int alg
, int run_no
, int count
, double time_used
);
162 static int do_multi(int multi
);
170 #define MAX_ECDH_SIZE 256
172 static const char *names
[ALGOR_NUM
] = {
173 "md2", "md4", "md5", "hmac(md5)", "sha1", "rmd160",
174 "rc4", "des cbc", "des ede3", "idea cbc", "seed cbc",
175 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
176 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
177 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
178 "evp", "sha256", "sha512", "whirlpool",
179 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
180 "aes-128 gcm", "aes-256 gcm", "chacha20 poly1305",
182 static double results
[ALGOR_NUM
][SIZE_NUM
];
183 static int lengths
[SIZE_NUM
] = {16, 64, 256, 1024, 8 * 1024};
184 static double rsa_results
[RSA_NUM
][2];
185 static double dsa_results
[DSA_NUM
][2];
186 static double ecdsa_results
[EC_NUM
][2];
187 static double ecdh_results
[EC_NUM
][1];
189 static void sig_done(int sig
);
194 signal(SIGALRM
, sig_done
);
205 return app_tminterval(s
, usertime
);
209 static const int KDF1_SHA1_len
= 20;
211 KDF1_SHA1(const void *in
, size_t inlen
, void *out
, size_t * outlen
)
213 #ifndef OPENSSL_NO_SHA
214 if (*outlen
< SHA_DIGEST_LENGTH
)
217 *outlen
= SHA_DIGEST_LENGTH
;
218 return SHA1(in
, inlen
, out
);
221 #endif /* OPENSSL_NO_SHA */
225 speed_main(int argc
, char **argv
)
227 unsigned char *buf
= NULL
, *buf2
= NULL
;
229 long count
= 0, save_count
= 0;
233 unsigned char md
[EVP_MAX_MD_SIZE
];
234 #ifndef OPENSSL_NO_MD4
235 unsigned char md4
[MD4_DIGEST_LENGTH
];
237 #ifndef OPENSSL_NO_MD5
238 unsigned char md5
[MD5_DIGEST_LENGTH
];
239 unsigned char hmac
[MD5_DIGEST_LENGTH
];
241 #ifndef OPENSSL_NO_SHA
242 unsigned char sha
[SHA_DIGEST_LENGTH
];
243 #ifndef OPENSSL_NO_SHA256
244 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
246 #ifndef OPENSSL_NO_SHA512
247 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
250 #ifndef OPENSSL_NO_WHIRLPOOL
251 unsigned char whirlpool
[WHIRLPOOL_DIGEST_LENGTH
];
253 #ifndef OPENSSL_NO_RIPEMD
254 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
256 #ifndef OPENSSL_NO_RC4
259 #ifndef OPENSSL_NO_RC2
262 #ifndef OPENSSL_NO_IDEA
263 IDEA_KEY_SCHEDULE idea_ks
;
265 #ifndef OPENSSL_NO_BF
268 #ifndef OPENSSL_NO_CAST
271 static const unsigned char key16
[16] =
272 {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
273 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
274 #ifndef OPENSSL_NO_AES
275 static const unsigned char key24
[24] =
276 {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
277 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
278 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
279 static const unsigned char key32
[32] =
280 {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
281 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
282 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
283 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
285 #ifndef OPENSSL_NO_CAMELLIA
286 static const unsigned char ckey24
[24] =
287 {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
288 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
289 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
290 static const unsigned char ckey32
[32] =
291 {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
292 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
293 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
294 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
296 #ifndef OPENSSL_NO_AES
297 #define MAX_BLOCK_SIZE 128
299 #define MAX_BLOCK_SIZE 64
301 unsigned char DES_iv
[8];
302 unsigned char iv
[2 * MAX_BLOCK_SIZE
/ 8];
303 #ifndef OPENSSL_NO_DES
304 static DES_cblock key
= {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
305 static DES_cblock key2
= {0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
306 static DES_cblock key3
= {0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
307 DES_key_schedule sch
;
308 DES_key_schedule sch2
;
309 DES_key_schedule sch3
;
311 #ifndef OPENSSL_NO_AES
312 AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
314 #ifndef OPENSSL_NO_CAMELLIA
315 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
327 #define D_CBC_SEED 10
331 #define D_CBC_CAST 14
332 #define D_CBC_128_AES 15
333 #define D_CBC_192_AES 16
334 #define D_CBC_256_AES 17
335 #define D_CBC_128_CML 18
336 #define D_CBC_192_CML 19
337 #define D_CBC_256_CML 20
341 #define D_WHIRLPOOL 24
342 #define D_IGE_128_AES 25
343 #define D_IGE_192_AES 26
344 #define D_IGE_256_AES 27
346 #define D_AES_128_GCM 29
347 #define D_AES_256_GCM 30
348 #define D_CHACHA20_POLY1305 31
350 long c
[ALGOR_NUM
][SIZE_NUM
];
376 RSA
*rsa_key
[RSA_NUM
];
377 long rsa_c
[RSA_NUM
][2];
378 static unsigned int rsa_bits
[RSA_NUM
] = {512, 1024, 2048, 4096};
379 static unsigned char *rsa_data
[RSA_NUM
] =
380 {test512
, test1024
, test2048
, test4096
};
381 static int rsa_data_length
[RSA_NUM
] = {
382 sizeof(test512
), sizeof(test1024
),
383 sizeof(test2048
), sizeof(test4096
)};
384 DSA
*dsa_key
[DSA_NUM
];
385 long dsa_c
[DSA_NUM
][2];
386 static unsigned int dsa_bits
[DSA_NUM
] = {512, 1024, 2048};
387 #ifndef OPENSSL_NO_EC
389 * We only test over the following curves as they are representative,
390 * To add tests over more curves, simply add the curve NID and curve
391 * name to the following arrays and increase the EC_NUM value
394 static unsigned int test_curves
[EC_NUM
] =
398 NID_X9_62_prime192v1
,
400 NID_X9_62_prime256v1
,
415 static const char *test_curves_names
[EC_NUM
] =
436 static int test_curves_bits
[EC_NUM
] =
438 160, 192, 224, 256, 384, 521,
439 163, 233, 283, 409, 571,
440 163, 233, 283, 409, 571
445 unsigned char ecdsasig
[256];
446 unsigned int ecdsasiglen
;
447 EC_KEY
*ecdsa
[EC_NUM
];
448 long ecdsa_c
[EC_NUM
][2];
450 EC_KEY
*ecdh_a
[EC_NUM
], *ecdh_b
[EC_NUM
];
451 unsigned char secret_a
[MAX_ECDH_SIZE
], secret_b
[MAX_ECDH_SIZE
];
452 int secret_size_a
, secret_size_b
;
455 long ecdh_c
[EC_NUM
][2];
457 int rsa_doit
[RSA_NUM
];
458 int dsa_doit
[DSA_NUM
];
459 int ecdsa_doit
[EC_NUM
];
460 int ecdh_doit
[EC_NUM
];
463 const EVP_CIPHER
*evp_cipher
= NULL
;
464 const EVP_MD
*evp_md
= NULL
;
467 const char *errstr
= NULL
;
469 if (single_execution
) {
470 if (pledge("stdio proc", NULL
) == -1) {
478 memset(results
, 0, sizeof(results
));
479 memset(dsa_key
, 0, sizeof(dsa_key
));
480 for (i
= 0; i
< EC_NUM
; i
++)
482 for (i
= 0; i
< EC_NUM
; i
++) {
487 memset(rsa_key
, 0, sizeof(rsa_key
));
488 for (i
= 0; i
< RSA_NUM
; i
++)
491 if ((buf
= malloc(BUFSIZE
)) == NULL
) {
492 BIO_printf(bio_err
, "out of memory\n");
495 if ((buf2
= malloc(BUFSIZE
)) == NULL
) {
496 BIO_printf(bio_err
, "out of memory\n");
499 memset(c
, 0, sizeof(c
));
500 memset(DES_iv
, 0, sizeof(DES_iv
));
501 memset(iv
, 0, sizeof(iv
));
503 for (i
= 0; i
< ALGOR_NUM
; i
++)
505 for (i
= 0; i
< RSA_NUM
; i
++)
507 for (i
= 0; i
< DSA_NUM
; i
++)
509 for (i
= 0; i
< EC_NUM
; i
++)
511 for (i
= 0; i
< EC_NUM
; i
++)
519 if ((argc
> 0) && (strcmp(*argv
, "-elapsed") == 0)) {
521 j
--; /* Otherwise, -elapsed gets confused with an
523 } else if ((argc
> 0) && (strcmp(*argv
, "-evp") == 0)) {
527 BIO_printf(bio_err
, "no EVP given\n");
530 evp_cipher
= EVP_get_cipherbyname(*argv
);
532 evp_md
= EVP_get_digestbyname(*argv
);
534 if (!evp_cipher
&& !evp_md
) {
535 BIO_printf(bio_err
, "%s is an unknown cipher or digest\n", *argv
);
539 } else if (argc
> 0 && !strcmp(*argv
, "-decrypt")) {
541 j
--; /* Otherwise, -elapsed gets confused with an
544 else if ((argc
> 0) && (strcmp(*argv
, "-multi") == 0)) {
548 BIO_printf(bio_err
, "no multi count given\n");
551 multi
= strtonum(argv
[0], 1, INT_MAX
, &errstr
);
553 BIO_printf(bio_err
, "bad multi count: %s", errstr
);
556 j
--; /* Otherwise, -mr gets confused with an
559 else if (argc
> 0 && !strcmp(*argv
, "-mr")) {
561 j
--; /* Otherwise, -mr gets confused with an
564 #ifndef OPENSSL_NO_MD4
565 if (strcmp(*argv
, "md4") == 0)
569 #ifndef OPENSSL_NO_MD5
570 if (strcmp(*argv
, "md5") == 0)
574 #ifndef OPENSSL_NO_MD5
575 if (strcmp(*argv
, "hmac") == 0)
579 #ifndef OPENSSL_NO_SHA
580 if (strcmp(*argv
, "sha1") == 0)
582 else if (strcmp(*argv
, "sha") == 0)
587 #ifndef OPENSSL_NO_SHA256
588 if (strcmp(*argv
, "sha256") == 0)
592 #ifndef OPENSSL_NO_SHA512
593 if (strcmp(*argv
, "sha512") == 0)
598 #ifndef OPENSSL_NO_WHIRLPOOL
599 if (strcmp(*argv
, "whirlpool") == 0)
600 doit
[D_WHIRLPOOL
] = 1;
603 #ifndef OPENSSL_NO_RIPEMD
604 if (strcmp(*argv
, "ripemd") == 0)
606 else if (strcmp(*argv
, "rmd160") == 0)
608 else if (strcmp(*argv
, "ripemd160") == 0)
612 #ifndef OPENSSL_NO_RC4
613 if (strcmp(*argv
, "rc4") == 0)
617 #ifndef OPENSSL_NO_DES
618 if (strcmp(*argv
, "des-cbc") == 0)
620 else if (strcmp(*argv
, "des-ede3") == 0)
621 doit
[D_EDE3_DES
] = 1;
624 #ifndef OPENSSL_NO_AES
625 if (strcmp(*argv
, "aes-128-cbc") == 0)
626 doit
[D_CBC_128_AES
] = 1;
627 else if (strcmp(*argv
, "aes-192-cbc") == 0)
628 doit
[D_CBC_192_AES
] = 1;
629 else if (strcmp(*argv
, "aes-256-cbc") == 0)
630 doit
[D_CBC_256_AES
] = 1;
631 else if (strcmp(*argv
, "aes-128-ige") == 0)
632 doit
[D_IGE_128_AES
] = 1;
633 else if (strcmp(*argv
, "aes-192-ige") == 0)
634 doit
[D_IGE_192_AES
] = 1;
635 else if (strcmp(*argv
, "aes-256-ige") == 0)
636 doit
[D_IGE_256_AES
] = 1;
639 #ifndef OPENSSL_NO_CAMELLIA
640 if (strcmp(*argv
, "camellia-128-cbc") == 0)
641 doit
[D_CBC_128_CML
] = 1;
642 else if (strcmp(*argv
, "camellia-192-cbc") == 0)
643 doit
[D_CBC_192_CML
] = 1;
644 else if (strcmp(*argv
, "camellia-256-cbc") == 0)
645 doit
[D_CBC_256_CML
] = 1;
649 if (strcmp(*argv
, "openssl") == 0) {
650 RSA_set_default_method(RSA_PKCS1_SSLeay());
654 if (strcmp(*argv
, "dsa512") == 0)
655 dsa_doit
[R_DSA_512
] = 2;
656 else if (strcmp(*argv
, "dsa1024") == 0)
657 dsa_doit
[R_DSA_1024
] = 2;
658 else if (strcmp(*argv
, "dsa2048") == 0)
659 dsa_doit
[R_DSA_2048
] = 2;
660 else if (strcmp(*argv
, "rsa512") == 0)
661 rsa_doit
[R_RSA_512
] = 2;
662 else if (strcmp(*argv
, "rsa1024") == 0)
663 rsa_doit
[R_RSA_1024
] = 2;
664 else if (strcmp(*argv
, "rsa2048") == 0)
665 rsa_doit
[R_RSA_2048
] = 2;
666 else if (strcmp(*argv
, "rsa4096") == 0)
667 rsa_doit
[R_RSA_4096
] = 2;
669 #ifndef OPENSSL_NO_RC2
670 if (strcmp(*argv
, "rc2-cbc") == 0)
672 else if (strcmp(*argv
, "rc2") == 0)
676 #ifndef OPENSSL_NO_IDEA
677 if (strcmp(*argv
, "idea-cbc") == 0)
678 doit
[D_CBC_IDEA
] = 1;
679 else if (strcmp(*argv
, "idea") == 0)
680 doit
[D_CBC_IDEA
] = 1;
683 #ifndef OPENSSL_NO_BF
684 if (strcmp(*argv
, "bf-cbc") == 0)
686 else if (strcmp(*argv
, "blowfish") == 0)
688 else if (strcmp(*argv
, "bf") == 0)
692 #ifndef OPENSSL_NO_CAST
693 if (strcmp(*argv
, "cast-cbc") == 0)
694 doit
[D_CBC_CAST
] = 1;
695 else if (strcmp(*argv
, "cast") == 0)
696 doit
[D_CBC_CAST
] = 1;
697 else if (strcmp(*argv
, "cast5") == 0)
698 doit
[D_CBC_CAST
] = 1;
701 #ifndef OPENSSL_NO_DES
702 if (strcmp(*argv
, "des") == 0) {
704 doit
[D_EDE3_DES
] = 1;
707 #ifndef OPENSSL_NO_AES
708 if (strcmp(*argv
, "aes") == 0) {
709 doit
[D_CBC_128_AES
] = 1;
710 doit
[D_CBC_192_AES
] = 1;
711 doit
[D_CBC_256_AES
] = 1;
712 } else if (strcmp(*argv
, "ghash") == 0)
714 else if (strcmp(*argv
,"aes-128-gcm") == 0)
715 doit
[D_AES_128_GCM
]=1;
716 else if (strcmp(*argv
,"aes-256-gcm") == 0)
717 doit
[D_AES_256_GCM
]=1;
720 #ifndef OPENSSL_NO_CAMELLIA
721 if (strcmp(*argv
, "camellia") == 0) {
722 doit
[D_CBC_128_CML
] = 1;
723 doit
[D_CBC_192_CML
] = 1;
724 doit
[D_CBC_256_CML
] = 1;
727 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
728 if (strcmp(*argv
,"chacha20-poly1305") == 0)
729 doit
[D_CHACHA20_POLY1305
]=1;
732 if (strcmp(*argv
, "rsa") == 0) {
733 rsa_doit
[R_RSA_512
] = 1;
734 rsa_doit
[R_RSA_1024
] = 1;
735 rsa_doit
[R_RSA_2048
] = 1;
736 rsa_doit
[R_RSA_4096
] = 1;
738 if (strcmp(*argv
, "dsa") == 0) {
739 dsa_doit
[R_DSA_512
] = 1;
740 dsa_doit
[R_DSA_1024
] = 1;
741 dsa_doit
[R_DSA_2048
] = 1;
743 if (strcmp(*argv
, "ecdsap160") == 0)
744 ecdsa_doit
[R_EC_P160
] = 2;
745 else if (strcmp(*argv
, "ecdsap192") == 0)
746 ecdsa_doit
[R_EC_P192
] = 2;
747 else if (strcmp(*argv
, "ecdsap224") == 0)
748 ecdsa_doit
[R_EC_P224
] = 2;
749 else if (strcmp(*argv
, "ecdsap256") == 0)
750 ecdsa_doit
[R_EC_P256
] = 2;
751 else if (strcmp(*argv
, "ecdsap384") == 0)
752 ecdsa_doit
[R_EC_P384
] = 2;
753 else if (strcmp(*argv
, "ecdsap521") == 0)
754 ecdsa_doit
[R_EC_P521
] = 2;
755 else if (strcmp(*argv
, "ecdsak163") == 0)
756 ecdsa_doit
[R_EC_K163
] = 2;
757 else if (strcmp(*argv
, "ecdsak233") == 0)
758 ecdsa_doit
[R_EC_K233
] = 2;
759 else if (strcmp(*argv
, "ecdsak283") == 0)
760 ecdsa_doit
[R_EC_K283
] = 2;
761 else if (strcmp(*argv
, "ecdsak409") == 0)
762 ecdsa_doit
[R_EC_K409
] = 2;
763 else if (strcmp(*argv
, "ecdsak571") == 0)
764 ecdsa_doit
[R_EC_K571
] = 2;
765 else if (strcmp(*argv
, "ecdsab163") == 0)
766 ecdsa_doit
[R_EC_B163
] = 2;
767 else if (strcmp(*argv
, "ecdsab233") == 0)
768 ecdsa_doit
[R_EC_B233
] = 2;
769 else if (strcmp(*argv
, "ecdsab283") == 0)
770 ecdsa_doit
[R_EC_B283
] = 2;
771 else if (strcmp(*argv
, "ecdsab409") == 0)
772 ecdsa_doit
[R_EC_B409
] = 2;
773 else if (strcmp(*argv
, "ecdsab571") == 0)
774 ecdsa_doit
[R_EC_B571
] = 2;
775 else if (strcmp(*argv
, "ecdsa") == 0) {
776 for (i
= 0; i
< EC_NUM
; i
++)
779 if (strcmp(*argv
, "ecdhp160") == 0)
780 ecdh_doit
[R_EC_P160
] = 2;
781 else if (strcmp(*argv
, "ecdhp192") == 0)
782 ecdh_doit
[R_EC_P192
] = 2;
783 else if (strcmp(*argv
, "ecdhp224") == 0)
784 ecdh_doit
[R_EC_P224
] = 2;
785 else if (strcmp(*argv
, "ecdhp256") == 0)
786 ecdh_doit
[R_EC_P256
] = 2;
787 else if (strcmp(*argv
, "ecdhp384") == 0)
788 ecdh_doit
[R_EC_P384
] = 2;
789 else if (strcmp(*argv
, "ecdhp521") == 0)
790 ecdh_doit
[R_EC_P521
] = 2;
791 else if (strcmp(*argv
, "ecdhk163") == 0)
792 ecdh_doit
[R_EC_K163
] = 2;
793 else if (strcmp(*argv
, "ecdhk233") == 0)
794 ecdh_doit
[R_EC_K233
] = 2;
795 else if (strcmp(*argv
, "ecdhk283") == 0)
796 ecdh_doit
[R_EC_K283
] = 2;
797 else if (strcmp(*argv
, "ecdhk409") == 0)
798 ecdh_doit
[R_EC_K409
] = 2;
799 else if (strcmp(*argv
, "ecdhk571") == 0)
800 ecdh_doit
[R_EC_K571
] = 2;
801 else if (strcmp(*argv
, "ecdhb163") == 0)
802 ecdh_doit
[R_EC_B163
] = 2;
803 else if (strcmp(*argv
, "ecdhb233") == 0)
804 ecdh_doit
[R_EC_B233
] = 2;
805 else if (strcmp(*argv
, "ecdhb283") == 0)
806 ecdh_doit
[R_EC_B283
] = 2;
807 else if (strcmp(*argv
, "ecdhb409") == 0)
808 ecdh_doit
[R_EC_B409
] = 2;
809 else if (strcmp(*argv
, "ecdhb571") == 0)
810 ecdh_doit
[R_EC_B571
] = 2;
811 else if (strcmp(*argv
, "ecdh") == 0) {
812 for (i
= 0; i
< EC_NUM
; i
++)
816 BIO_printf(bio_err
, "Error: bad option or value\n");
817 BIO_printf(bio_err
, "\n");
818 BIO_printf(bio_err
, "Available values:\n");
819 #ifndef OPENSSL_NO_MD4
820 BIO_printf(bio_err
, "md4 ");
822 #ifndef OPENSSL_NO_MD5
823 BIO_printf(bio_err
, "md5 ");
824 #ifndef OPENSSL_NO_HMAC
825 BIO_printf(bio_err
, "hmac ");
828 #ifndef OPENSSL_NO_SHA1
829 BIO_printf(bio_err
, "sha1 ");
831 #ifndef OPENSSL_NO_SHA256
832 BIO_printf(bio_err
, "sha256 ");
834 #ifndef OPENSSL_NO_SHA512
835 BIO_printf(bio_err
, "sha512 ");
837 #ifndef OPENSSL_NO_WHIRLPOOL
838 BIO_printf(bio_err
, "whirlpool");
840 #ifndef OPENSSL_NO_RIPEMD160
841 BIO_printf(bio_err
, "rmd160");
843 #if !defined(OPENSSL_NO_MD2) || \
844 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
845 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
846 !defined(OPENSSL_NO_WHIRLPOOL)
847 BIO_printf(bio_err
, "\n");
850 #ifndef OPENSSL_NO_IDEA
851 BIO_printf(bio_err
, "idea-cbc ");
853 #ifndef OPENSSL_NO_RC2
854 BIO_printf(bio_err
, "rc2-cbc ");
856 #ifndef OPENSSL_NO_BF
857 BIO_printf(bio_err
, "bf-cbc ");
859 #ifndef OPENSSL_NO_DES
860 BIO_printf(bio_err
, "des-cbc des-ede3\n");
862 #ifndef OPENSSL_NO_AES
863 BIO_printf(bio_err
, "aes-128-cbc aes-192-cbc aes-256-cbc ");
864 BIO_printf(bio_err
, "aes-128-ige aes-192-ige aes-256-ige\n");
865 BIO_printf(bio_err
, "aes-128-gcm aes-256-gcm ");
867 #ifndef OPENSSL_NO_CAMELLIA
868 BIO_printf(bio_err
, "\n");
869 BIO_printf(bio_err
, "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
871 #ifndef OPENSSL_NO_RC4
872 BIO_printf(bio_err
, "rc4");
874 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
875 BIO_printf(bio_err
," chacha20-poly1305");
877 BIO_printf(bio_err
, "\n");
879 BIO_printf(bio_err
, "rsa512 rsa1024 rsa2048 rsa4096\n");
881 BIO_printf(bio_err
, "dsa512 dsa1024 dsa2048\n");
882 BIO_printf(bio_err
, "ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
883 BIO_printf(bio_err
, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
884 BIO_printf(bio_err
, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571 ecdsa\n");
885 BIO_printf(bio_err
, "ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
886 BIO_printf(bio_err
, "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
887 BIO_printf(bio_err
, "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571 ecdh\n");
889 #ifndef OPENSSL_NO_IDEA
890 BIO_printf(bio_err
, "idea ");
892 #ifndef OPENSSL_NO_RC2
893 BIO_printf(bio_err
, "rc2 ");
895 #ifndef OPENSSL_NO_DES
896 BIO_printf(bio_err
, "des ");
898 #ifndef OPENSSL_NO_AES
899 BIO_printf(bio_err
, "aes ");
901 #ifndef OPENSSL_NO_CAMELLIA
902 BIO_printf(bio_err
, "camellia ");
904 BIO_printf(bio_err
, "rsa ");
905 #ifndef OPENSSL_NO_BF
906 BIO_printf(bio_err
, "blowfish");
908 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
909 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
910 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
911 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
912 BIO_printf(bio_err
, "\n");
915 BIO_printf(bio_err
, "\n");
916 BIO_printf(bio_err
, "Available options:\n");
917 BIO_printf(bio_err
, "-elapsed measure time in real time instead of CPU user time.\n");
918 BIO_printf(bio_err
, "-evp e use EVP e.\n");
919 BIO_printf(bio_err
, "-decrypt time decryption instead of encryption (only EVP).\n");
920 BIO_printf(bio_err
, "-mr produce machine readable output.\n");
921 BIO_printf(bio_err
, "-multi n run n benchmarks in parallel.\n");
929 if (multi
&& do_multi(multi
))
933 for (i
= 0; i
< ALGOR_NUM
; i
++) {
937 for (i
= 0; i
< RSA_NUM
; i
++)
939 for (i
= 0; i
< DSA_NUM
; i
++)
941 for (i
= 0; i
< EC_NUM
; i
++)
943 for (i
= 0; i
< EC_NUM
; i
++)
946 for (i
= 0; i
< ALGOR_NUM
; i
++)
950 if (usertime
== 0 && !mr
)
951 BIO_printf(bio_err
, "You have chosen to measure elapsed time instead of user CPU time.\n");
953 for (i
= 0; i
< RSA_NUM
; i
++) {
954 const unsigned char *p
;
957 rsa_key
[i
] = d2i_RSAPrivateKey(NULL
, &p
, rsa_data_length
[i
]);
958 if (rsa_key
[i
] == NULL
) {
959 BIO_printf(bio_err
, "internal error loading RSA key number %d\n", i
);
964 dsa_key
[0] = get_dsa512();
965 dsa_key
[1] = get_dsa1024();
966 dsa_key
[2] = get_dsa2048();
968 #ifndef OPENSSL_NO_DES
969 DES_set_key_unchecked(&key
, &sch
);
970 DES_set_key_unchecked(&key2
, &sch2
);
971 DES_set_key_unchecked(&key3
, &sch3
);
973 #ifndef OPENSSL_NO_AES
974 AES_set_encrypt_key(key16
, 128, &aes_ks1
);
975 AES_set_encrypt_key(key24
, 192, &aes_ks2
);
976 AES_set_encrypt_key(key32
, 256, &aes_ks3
);
978 #ifndef OPENSSL_NO_CAMELLIA
979 Camellia_set_key(key16
, 128, &camellia_ks1
);
980 Camellia_set_key(ckey24
, 192, &camellia_ks2
);
981 Camellia_set_key(ckey32
, 256, &camellia_ks3
);
983 #ifndef OPENSSL_NO_IDEA
984 idea_set_encrypt_key(key16
, &idea_ks
);
986 #ifndef OPENSSL_NO_RC4
987 RC4_set_key(&rc4_ks
, 16, key16
);
989 #ifndef OPENSSL_NO_RC2
990 RC2_set_key(&rc2_ks
, 16, key16
, 128);
992 #ifndef OPENSSL_NO_BF
993 BF_set_key(&bf_ks
, 16, key16
);
995 #ifndef OPENSSL_NO_CAST
996 CAST_set_key(&cast_ks
, 16, key16
);
998 memset(rsa_c
, 0, sizeof(rsa_c
));
999 #define COND(c) (run && count<0x7fffffff)
1000 #define COUNT(d) (count)
1001 signal(SIGALRM
, sig_done
);
1003 #ifndef OPENSSL_NO_MD4
1005 for (j
= 0; j
< SIZE_NUM
; j
++) {
1006 print_message(names
[D_MD4
], c
[D_MD4
][j
], lengths
[j
]);
1008 for (count
= 0, run
= 1; COND(c
[D_MD4
][j
]); count
++)
1009 EVP_Digest(&(buf
[0]), (unsigned long) lengths
[j
], &(md4
[0]), NULL
, EVP_md4(), NULL
);
1011 print_result(D_MD4
, j
, count
, d
);
1016 #ifndef OPENSSL_NO_MD5
1018 for (j
= 0; j
< SIZE_NUM
; j
++) {
1019 print_message(names
[D_MD5
], c
[D_MD5
][j
], lengths
[j
]);
1021 for (count
= 0, run
= 1; COND(c
[D_MD5
][j
]); count
++)
1022 EVP_Digest(&(buf
[0]), (unsigned long) lengths
[j
], &(md5
[0]), NULL
, EVP_get_digestbyname("md5"), NULL
);
1024 print_result(D_MD5
, j
, count
, d
);
1029 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1033 HMAC_CTX_init(&hctx
);
1034 HMAC_Init_ex(&hctx
, (unsigned char *) "This is a key...",
1035 16, EVP_md5(), NULL
);
1037 for (j
= 0; j
< SIZE_NUM
; j
++) {
1038 print_message(names
[D_HMAC
], c
[D_HMAC
][j
], lengths
[j
]);
1040 for (count
= 0, run
= 1; COND(c
[D_HMAC
][j
]); count
++) {
1041 HMAC_Init_ex(&hctx
, NULL
, 0, NULL
, NULL
);
1042 HMAC_Update(&hctx
, buf
, lengths
[j
]);
1043 HMAC_Final(&hctx
, &(hmac
[0]), NULL
);
1046 print_result(D_HMAC
, j
, count
, d
);
1048 HMAC_CTX_cleanup(&hctx
);
1051 #ifndef OPENSSL_NO_SHA
1053 for (j
= 0; j
< SIZE_NUM
; j
++) {
1054 print_message(names
[D_SHA1
], c
[D_SHA1
][j
], lengths
[j
]);
1056 for (count
= 0, run
= 1; COND(c
[D_SHA1
][j
]); count
++)
1057 EVP_Digest(buf
, (unsigned long) lengths
[j
], &(sha
[0]), NULL
, EVP_sha1(), NULL
);
1059 print_result(D_SHA1
, j
, count
, d
);
1062 #ifndef OPENSSL_NO_SHA256
1063 if (doit
[D_SHA256
]) {
1064 for (j
= 0; j
< SIZE_NUM
; j
++) {
1065 print_message(names
[D_SHA256
], c
[D_SHA256
][j
], lengths
[j
]);
1067 for (count
= 0, run
= 1; COND(c
[D_SHA256
][j
]); count
++)
1068 SHA256(buf
, lengths
[j
], sha256
);
1070 print_result(D_SHA256
, j
, count
, d
);
1075 #ifndef OPENSSL_NO_SHA512
1076 if (doit
[D_SHA512
]) {
1077 for (j
= 0; j
< SIZE_NUM
; j
++) {
1078 print_message(names
[D_SHA512
], c
[D_SHA512
][j
], lengths
[j
]);
1080 for (count
= 0, run
= 1; COND(c
[D_SHA512
][j
]); count
++)
1081 SHA512(buf
, lengths
[j
], sha512
);
1083 print_result(D_SHA512
, j
, count
, d
);
1089 #ifndef OPENSSL_NO_WHIRLPOOL
1090 if (doit
[D_WHIRLPOOL
]) {
1091 for (j
= 0; j
< SIZE_NUM
; j
++) {
1092 print_message(names
[D_WHIRLPOOL
], c
[D_WHIRLPOOL
][j
], lengths
[j
]);
1094 for (count
= 0, run
= 1; COND(c
[D_WHIRLPOOL
][j
]); count
++)
1095 WHIRLPOOL(buf
, lengths
[j
], whirlpool
);
1097 print_result(D_WHIRLPOOL
, j
, count
, d
);
1102 #ifndef OPENSSL_NO_RIPEMD
1103 if (doit
[D_RMD160
]) {
1104 for (j
= 0; j
< SIZE_NUM
; j
++) {
1105 print_message(names
[D_RMD160
], c
[D_RMD160
][j
], lengths
[j
]);
1107 for (count
= 0, run
= 1; COND(c
[D_RMD160
][j
]); count
++)
1108 EVP_Digest(buf
, (unsigned long) lengths
[j
], &(rmd160
[0]), NULL
, EVP_ripemd160(), NULL
);
1110 print_result(D_RMD160
, j
, count
, d
);
1114 #ifndef OPENSSL_NO_RC4
1116 for (j
= 0; j
< SIZE_NUM
; j
++) {
1117 print_message(names
[D_RC4
], c
[D_RC4
][j
], lengths
[j
]);
1119 for (count
= 0, run
= 1; COND(c
[D_RC4
][j
]); count
++)
1120 RC4(&rc4_ks
, (unsigned int) lengths
[j
],
1123 print_result(D_RC4
, j
, count
, d
);
1127 #ifndef OPENSSL_NO_DES
1128 if (doit
[D_CBC_DES
]) {
1129 for (j
= 0; j
< SIZE_NUM
; j
++) {
1130 print_message(names
[D_CBC_DES
], c
[D_CBC_DES
][j
], lengths
[j
]);
1132 for (count
= 0, run
= 1; COND(c
[D_CBC_DES
][j
]); count
++)
1133 DES_ncbc_encrypt(buf
, buf
, lengths
[j
], &sch
,
1134 &DES_iv
, DES_ENCRYPT
);
1136 print_result(D_CBC_DES
, j
, count
, d
);
1139 if (doit
[D_EDE3_DES
]) {
1140 for (j
= 0; j
< SIZE_NUM
; j
++) {
1141 print_message(names
[D_EDE3_DES
], c
[D_EDE3_DES
][j
], lengths
[j
]);
1143 for (count
= 0, run
= 1; COND(c
[D_EDE3_DES
][j
]); count
++)
1144 DES_ede3_cbc_encrypt(buf
, buf
, lengths
[j
],
1146 &DES_iv
, DES_ENCRYPT
);
1148 print_result(D_EDE3_DES
, j
, count
, d
);
1152 #ifndef OPENSSL_NO_AES
1153 if (doit
[D_CBC_128_AES
]) {
1154 for (j
= 0; j
< SIZE_NUM
; j
++) {
1155 print_message(names
[D_CBC_128_AES
], c
[D_CBC_128_AES
][j
], lengths
[j
]);
1157 for (count
= 0, run
= 1; COND(c
[D_CBC_128_AES
][j
]); count
++)
1158 AES_cbc_encrypt(buf
, buf
,
1159 (unsigned long) lengths
[j
], &aes_ks1
,
1162 print_result(D_CBC_128_AES
, j
, count
, d
);
1165 if (doit
[D_CBC_192_AES
]) {
1166 for (j
= 0; j
< SIZE_NUM
; j
++) {
1167 print_message(names
[D_CBC_192_AES
], c
[D_CBC_192_AES
][j
], lengths
[j
]);
1169 for (count
= 0, run
= 1; COND(c
[D_CBC_192_AES
][j
]); count
++)
1170 AES_cbc_encrypt(buf
, buf
,
1171 (unsigned long) lengths
[j
], &aes_ks2
,
1174 print_result(D_CBC_192_AES
, j
, count
, d
);
1177 if (doit
[D_CBC_256_AES
]) {
1178 for (j
= 0; j
< SIZE_NUM
; j
++) {
1179 print_message(names
[D_CBC_256_AES
], c
[D_CBC_256_AES
][j
], lengths
[j
]);
1181 for (count
= 0, run
= 1; COND(c
[D_CBC_256_AES
][j
]); count
++)
1182 AES_cbc_encrypt(buf
, buf
,
1183 (unsigned long) lengths
[j
], &aes_ks3
,
1186 print_result(D_CBC_256_AES
, j
, count
, d
);
1189 if (doit
[D_IGE_128_AES
]) {
1190 for (j
= 0; j
< SIZE_NUM
; j
++) {
1191 print_message(names
[D_IGE_128_AES
], c
[D_IGE_128_AES
][j
], lengths
[j
]);
1193 for (count
= 0, run
= 1; COND(c
[D_IGE_128_AES
][j
]); count
++)
1194 AES_ige_encrypt(buf
, buf2
,
1195 (unsigned long) lengths
[j
], &aes_ks1
,
1198 print_result(D_IGE_128_AES
, j
, count
, d
);
1201 if (doit
[D_IGE_192_AES
]) {
1202 for (j
= 0; j
< SIZE_NUM
; j
++) {
1203 print_message(names
[D_IGE_192_AES
], c
[D_IGE_192_AES
][j
], lengths
[j
]);
1205 for (count
= 0, run
= 1; COND(c
[D_IGE_192_AES
][j
]); count
++)
1206 AES_ige_encrypt(buf
, buf2
,
1207 (unsigned long) lengths
[j
], &aes_ks2
,
1210 print_result(D_IGE_192_AES
, j
, count
, d
);
1213 if (doit
[D_IGE_256_AES
]) {
1214 for (j
= 0; j
< SIZE_NUM
; j
++) {
1215 print_message(names
[D_IGE_256_AES
], c
[D_IGE_256_AES
][j
], lengths
[j
]);
1217 for (count
= 0, run
= 1; COND(c
[D_IGE_256_AES
][j
]); count
++)
1218 AES_ige_encrypt(buf
, buf2
,
1219 (unsigned long) lengths
[j
], &aes_ks3
,
1222 print_result(D_IGE_256_AES
, j
, count
, d
);
1225 if (doit
[D_GHASH
]) {
1226 GCM128_CONTEXT
*ctx
= CRYPTO_gcm128_new(&aes_ks1
, (block128_f
) AES_encrypt
);
1227 CRYPTO_gcm128_setiv(ctx
, (unsigned char *) "0123456789ab", 12);
1229 for (j
= 0; j
< SIZE_NUM
; j
++) {
1230 print_message(names
[D_GHASH
], c
[D_GHASH
][j
], lengths
[j
]);
1232 for (count
= 0, run
= 1; COND(c
[D_GHASH
][j
]); count
++)
1233 CRYPTO_gcm128_aad(ctx
, buf
, lengths
[j
]);
1235 print_result(D_GHASH
, j
, count
, d
);
1237 CRYPTO_gcm128_release(ctx
);
1239 if (doit
[D_AES_128_GCM
]) {
1240 const EVP_AEAD
*aead
= EVP_aead_aes_128_gcm();
1241 static const unsigned char nonce
[32] = {0};
1242 size_t buf_len
, nonce_len
;
1245 EVP_AEAD_CTX_init(&ctx
, aead
, key32
, EVP_AEAD_key_length(aead
),
1246 EVP_AEAD_DEFAULT_TAG_LENGTH
, NULL
);
1247 nonce_len
= EVP_AEAD_nonce_length(aead
);
1249 for (j
= 0; j
< SIZE_NUM
; j
++) {
1250 print_message(names
[D_AES_128_GCM
],c
[D_AES_128_GCM
][j
],lengths
[j
]);
1252 for (count
= 0, run
= 1; COND(c
[D_AES_128_GCM
][j
]); count
++)
1253 EVP_AEAD_CTX_seal(&ctx
, buf
, &buf_len
, BUFSIZE
, nonce
,
1254 nonce_len
, buf
, lengths
[j
], NULL
, 0);
1256 print_result(D_AES_128_GCM
,j
,count
,d
);
1258 EVP_AEAD_CTX_cleanup(&ctx
);
1261 if (doit
[D_AES_256_GCM
]) {
1262 const EVP_AEAD
*aead
= EVP_aead_aes_256_gcm();
1263 static const unsigned char nonce
[32] = {0};
1264 size_t buf_len
, nonce_len
;
1267 EVP_AEAD_CTX_init(&ctx
, aead
, key32
, EVP_AEAD_key_length(aead
),
1268 EVP_AEAD_DEFAULT_TAG_LENGTH
, NULL
);
1269 nonce_len
= EVP_AEAD_nonce_length(aead
);
1271 for (j
= 0; j
< SIZE_NUM
; j
++) {
1272 print_message(names
[D_AES_256_GCM
],c
[D_AES_256_GCM
][j
],lengths
[j
]);
1274 for (count
= 0, run
= 1; COND(c
[D_AES_256_GCM
][j
]); count
++)
1275 EVP_AEAD_CTX_seal(&ctx
, buf
, &buf_len
, BUFSIZE
, nonce
,
1276 nonce_len
, buf
, lengths
[j
], NULL
, 0);
1278 print_result(D_AES_256_GCM
, j
, count
, d
);
1280 EVP_AEAD_CTX_cleanup(&ctx
);
1283 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1284 if (doit
[D_CHACHA20_POLY1305
]) {
1285 const EVP_AEAD
*aead
= EVP_aead_chacha20_poly1305();
1286 static const unsigned char nonce
[32] = {0};
1287 size_t buf_len
, nonce_len
;
1290 EVP_AEAD_CTX_init(&ctx
, aead
, key32
, EVP_AEAD_key_length(aead
),
1291 EVP_AEAD_DEFAULT_TAG_LENGTH
, NULL
);
1292 nonce_len
= EVP_AEAD_nonce_length(aead
);
1294 for (j
= 0; j
< SIZE_NUM
; j
++) {
1295 print_message(names
[D_CHACHA20_POLY1305
],
1296 c
[D_CHACHA20_POLY1305
][j
], lengths
[j
]);
1298 for (count
= 0, run
= 1; COND(c
[D_CHACHA20_POLY1305
][j
]); count
++)
1299 EVP_AEAD_CTX_seal(&ctx
, buf
, &buf_len
, BUFSIZE
, nonce
,
1300 nonce_len
, buf
, lengths
[j
], NULL
, 0);
1302 print_result(D_CHACHA20_POLY1305
, j
, count
, d
);
1304 EVP_AEAD_CTX_cleanup(&ctx
);
1307 #ifndef OPENSSL_NO_CAMELLIA
1308 if (doit
[D_CBC_128_CML
]) {
1309 for (j
= 0; j
< SIZE_NUM
; j
++) {
1310 print_message(names
[D_CBC_128_CML
], c
[D_CBC_128_CML
][j
], lengths
[j
]);
1312 for (count
= 0, run
= 1; COND(c
[D_CBC_128_CML
][j
]); count
++)
1313 Camellia_cbc_encrypt(buf
, buf
,
1314 (unsigned long) lengths
[j
], &camellia_ks1
,
1315 iv
, CAMELLIA_ENCRYPT
);
1317 print_result(D_CBC_128_CML
, j
, count
, d
);
1320 if (doit
[D_CBC_192_CML
]) {
1321 for (j
= 0; j
< SIZE_NUM
; j
++) {
1322 print_message(names
[D_CBC_192_CML
], c
[D_CBC_192_CML
][j
], lengths
[j
]);
1324 for (count
= 0, run
= 1; COND(c
[D_CBC_192_CML
][j
]); count
++)
1325 Camellia_cbc_encrypt(buf
, buf
,
1326 (unsigned long) lengths
[j
], &camellia_ks2
,
1327 iv
, CAMELLIA_ENCRYPT
);
1329 print_result(D_CBC_192_CML
, j
, count
, d
);
1332 if (doit
[D_CBC_256_CML
]) {
1333 for (j
= 0; j
< SIZE_NUM
; j
++) {
1334 print_message(names
[D_CBC_256_CML
], c
[D_CBC_256_CML
][j
], lengths
[j
]);
1336 for (count
= 0, run
= 1; COND(c
[D_CBC_256_CML
][j
]); count
++)
1337 Camellia_cbc_encrypt(buf
, buf
,
1338 (unsigned long) lengths
[j
], &camellia_ks3
,
1339 iv
, CAMELLIA_ENCRYPT
);
1341 print_result(D_CBC_256_CML
, j
, count
, d
);
1345 #ifndef OPENSSL_NO_IDEA
1346 if (doit
[D_CBC_IDEA
]) {
1347 for (j
= 0; j
< SIZE_NUM
; j
++) {
1348 print_message(names
[D_CBC_IDEA
], c
[D_CBC_IDEA
][j
], lengths
[j
]);
1350 for (count
= 0, run
= 1; COND(c
[D_CBC_IDEA
][j
]); count
++)
1351 idea_cbc_encrypt(buf
, buf
,
1352 (unsigned long) lengths
[j
], &idea_ks
,
1355 print_result(D_CBC_IDEA
, j
, count
, d
);
1359 #ifndef OPENSSL_NO_RC2
1360 if (doit
[D_CBC_RC2
]) {
1361 for (j
= 0; j
< SIZE_NUM
; j
++) {
1362 print_message(names
[D_CBC_RC2
], c
[D_CBC_RC2
][j
], lengths
[j
]);
1364 for (count
= 0, run
= 1; COND(c
[D_CBC_RC2
][j
]); count
++)
1365 RC2_cbc_encrypt(buf
, buf
,
1366 (unsigned long) lengths
[j
], &rc2_ks
,
1369 print_result(D_CBC_RC2
, j
, count
, d
);
1373 #ifndef OPENSSL_NO_BF
1374 if (doit
[D_CBC_BF
]) {
1375 for (j
= 0; j
< SIZE_NUM
; j
++) {
1376 print_message(names
[D_CBC_BF
], c
[D_CBC_BF
][j
], lengths
[j
]);
1378 for (count
= 0, run
= 1; COND(c
[D_CBC_BF
][j
]); count
++)
1379 BF_cbc_encrypt(buf
, buf
,
1380 (unsigned long) lengths
[j
], &bf_ks
,
1383 print_result(D_CBC_BF
, j
, count
, d
);
1387 #ifndef OPENSSL_NO_CAST
1388 if (doit
[D_CBC_CAST
]) {
1389 for (j
= 0; j
< SIZE_NUM
; j
++) {
1390 print_message(names
[D_CBC_CAST
], c
[D_CBC_CAST
][j
], lengths
[j
]);
1392 for (count
= 0, run
= 1; COND(c
[D_CBC_CAST
][j
]); count
++)
1393 CAST_cbc_encrypt(buf
, buf
,
1394 (unsigned long) lengths
[j
], &cast_ks
,
1397 print_result(D_CBC_CAST
, j
, count
, d
);
1403 for (j
= 0; j
< SIZE_NUM
; j
++) {
1408 names
[D_EVP
] = OBJ_nid2ln(evp_cipher
->nid
);
1410 * -O3 -fschedule-insns messes up an
1411 * optimization here! names[D_EVP] somehow
1414 print_message(names
[D_EVP
], save_count
,
1417 EVP_CIPHER_CTX_init(&ctx
);
1419 EVP_DecryptInit_ex(&ctx
, evp_cipher
, NULL
, key16
, iv
);
1421 EVP_EncryptInit_ex(&ctx
, evp_cipher
, NULL
, key16
, iv
);
1422 EVP_CIPHER_CTX_set_padding(&ctx
, 0);
1426 for (count
= 0, run
= 1; COND(save_count
* 4 * lengths
[0] / lengths
[j
]); count
++)
1427 EVP_DecryptUpdate(&ctx
, buf
, &outl
, buf
, lengths
[j
]);
1429 for (count
= 0, run
= 1; COND(save_count
* 4 * lengths
[0] / lengths
[j
]); count
++)
1430 EVP_EncryptUpdate(&ctx
, buf
, &outl
, buf
, lengths
[j
]);
1432 EVP_DecryptFinal_ex(&ctx
, buf
, &outl
);
1434 EVP_EncryptFinal_ex(&ctx
, buf
, &outl
);
1436 EVP_CIPHER_CTX_cleanup(&ctx
);
1439 names
[D_EVP
] = OBJ_nid2ln(evp_md
->type
);
1440 print_message(names
[D_EVP
], save_count
,
1444 for (count
= 0, run
= 1; COND(save_count
* 4 * lengths
[0] / lengths
[j
]); count
++)
1445 EVP_Digest(buf
, lengths
[j
], &(md
[0]), NULL
, evp_md
, NULL
);
1449 print_result(D_EVP
, j
, count
, d
);
1452 arc4random_buf(buf
, 36);
1453 for (j
= 0; j
< RSA_NUM
; j
++) {
1457 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
, &rsa_num
, rsa_key
[j
]);
1459 BIO_printf(bio_err
, "RSA sign failure. No RSA sign will be done.\n");
1460 ERR_print_errors(bio_err
);
1463 pkey_print_message("private", "rsa",
1464 rsa_c
[j
][0], rsa_bits
[j
],
1466 /* RSA_blinding_on(rsa_key[j],NULL); */
1468 for (count
= 0, run
= 1; COND(rsa_c
[j
][0]); count
++) {
1469 ret
= RSA_sign(NID_md5_sha1
, buf
, 36, buf2
,
1470 &rsa_num
, rsa_key
[j
]);
1473 "RSA sign failure\n");
1474 ERR_print_errors(bio_err
);
1480 BIO_printf(bio_err
, mr
? "+R1:%ld:%d:%.2f\n"
1481 : "%ld %d bit private RSA's in %.2fs\n",
1482 count
, rsa_bits
[j
], d
);
1483 rsa_results
[j
][0] = d
/ (double) count
;
1487 ret
= RSA_verify(NID_md5_sha1
, buf
, 36, buf2
, rsa_num
, rsa_key
[j
]);
1489 BIO_printf(bio_err
, "RSA verify failure. No RSA verify will be done.\n");
1490 ERR_print_errors(bio_err
);
1493 pkey_print_message("public", "rsa",
1494 rsa_c
[j
][1], rsa_bits
[j
],
1497 for (count
= 0, run
= 1; COND(rsa_c
[j
][1]); count
++) {
1498 ret
= RSA_verify(NID_md5_sha1
, buf
, 36, buf2
,
1499 rsa_num
, rsa_key
[j
]);
1502 "RSA verify failure\n");
1503 ERR_print_errors(bio_err
);
1509 BIO_printf(bio_err
, mr
? "+R2:%ld:%d:%.2f\n"
1510 : "%ld %d bit public RSA's in %.2fs\n",
1511 count
, rsa_bits
[j
], d
);
1512 rsa_results
[j
][1] = d
/ (double) count
;
1515 if (rsa_count
<= 1) {
1516 /* if longer than 10s, don't do any more */
1517 for (j
++; j
< RSA_NUM
; j
++)
1522 arc4random_buf(buf
, 20);
1523 for (j
= 0; j
< DSA_NUM
; j
++) {
1529 /* DSA_generate_key(dsa_key[j]); */
1530 /* DSA_sign_setup(dsa_key[j],NULL); */
1531 ret
= DSA_sign(EVP_PKEY_DSA
, buf
, 20, buf2
,
1534 BIO_printf(bio_err
, "DSA sign failure. No DSA sign will be done.\n");
1535 ERR_print_errors(bio_err
);
1538 pkey_print_message("sign", "dsa",
1539 dsa_c
[j
][0], dsa_bits
[j
],
1542 for (count
= 0, run
= 1; COND(dsa_c
[j
][0]); count
++) {
1543 ret
= DSA_sign(EVP_PKEY_DSA
, buf
, 20, buf2
,
1547 "DSA sign failure\n");
1548 ERR_print_errors(bio_err
);
1554 BIO_printf(bio_err
, mr
? "+R3:%ld:%d:%.2f\n"
1555 : "%ld %d bit DSA signs in %.2fs\n",
1556 count
, dsa_bits
[j
], d
);
1557 dsa_results
[j
][0] = d
/ (double) count
;
1561 ret
= DSA_verify(EVP_PKEY_DSA
, buf
, 20, buf2
,
1564 BIO_printf(bio_err
, "DSA verify failure. No DSA verify will be done.\n");
1565 ERR_print_errors(bio_err
);
1568 pkey_print_message("verify", "dsa",
1569 dsa_c
[j
][1], dsa_bits
[j
],
1572 for (count
= 0, run
= 1; COND(dsa_c
[j
][1]); count
++) {
1573 ret
= DSA_verify(EVP_PKEY_DSA
, buf
, 20, buf2
,
1577 "DSA verify failure\n");
1578 ERR_print_errors(bio_err
);
1584 BIO_printf(bio_err
, mr
? "+R4:%ld:%d:%.2f\n"
1585 : "%ld %d bit DSA verify in %.2fs\n",
1586 count
, dsa_bits
[j
], d
);
1587 dsa_results
[j
][1] = d
/ (double) count
;
1590 if (rsa_count
<= 1) {
1591 /* if longer than 10s, don't do any more */
1592 for (j
++; j
< DSA_NUM
; j
++)
1597 for (j
= 0; j
< EC_NUM
; j
++) {
1601 continue; /* Ignore Curve */
1602 ecdsa
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
1603 if (ecdsa
[j
] == NULL
) {
1604 BIO_printf(bio_err
, "ECDSA failure.\n");
1605 ERR_print_errors(bio_err
);
1608 EC_KEY_precompute_mult(ecdsa
[j
], NULL
);
1610 /* Perform ECDSA signature test */
1611 EC_KEY_generate_key(ecdsa
[j
]);
1612 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
,
1613 &ecdsasiglen
, ecdsa
[j
]);
1615 BIO_printf(bio_err
, "ECDSA sign failure. No ECDSA sign will be done.\n");
1616 ERR_print_errors(bio_err
);
1619 pkey_print_message("sign", "ecdsa",
1621 test_curves_bits
[j
],
1625 for (count
= 0, run
= 1; COND(ecdsa_c
[j
][0]);
1627 ret
= ECDSA_sign(0, buf
, 20,
1628 ecdsasig
, &ecdsasiglen
,
1631 BIO_printf(bio_err
, "ECDSA sign failure\n");
1632 ERR_print_errors(bio_err
);
1639 BIO_printf(bio_err
, mr
? "+R5:%ld:%d:%.2f\n" :
1640 "%ld %d bit ECDSA signs in %.2fs \n",
1641 count
, test_curves_bits
[j
], d
);
1642 ecdsa_results
[j
][0] = d
/ (double) count
;
1646 /* Perform ECDSA verification test */
1647 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
,
1648 ecdsasiglen
, ecdsa
[j
]);
1650 BIO_printf(bio_err
, "ECDSA verify failure. No ECDSA verify will be done.\n");
1651 ERR_print_errors(bio_err
);
1654 pkey_print_message("verify", "ecdsa",
1656 test_curves_bits
[j
],
1659 for (count
= 0, run
= 1; COND(ecdsa_c
[j
][1]); count
++) {
1660 ret
= ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[j
]);
1662 BIO_printf(bio_err
, "ECDSA verify failure\n");
1663 ERR_print_errors(bio_err
);
1669 BIO_printf(bio_err
, mr
? "+R6:%ld:%d:%.2f\n"
1670 : "%ld %d bit ECDSA verify in %.2fs\n",
1671 count
, test_curves_bits
[j
], d
);
1672 ecdsa_results
[j
][1] = d
/ (double) count
;
1675 if (rsa_count
<= 1) {
1676 /* if longer than 10s, don't do any more */
1677 for (j
++; j
< EC_NUM
; j
++)
1683 for (j
= 0; j
< EC_NUM
; j
++) {
1686 ecdh_a
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
1687 ecdh_b
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
1688 if ((ecdh_a
[j
] == NULL
) || (ecdh_b
[j
] == NULL
)) {
1689 BIO_printf(bio_err
, "ECDH failure.\n");
1690 ERR_print_errors(bio_err
);
1693 /* generate two ECDH key pairs */
1694 if (!EC_KEY_generate_key(ecdh_a
[j
]) ||
1695 !EC_KEY_generate_key(ecdh_b
[j
])) {
1696 BIO_printf(bio_err
, "ECDH key generation failure.\n");
1697 ERR_print_errors(bio_err
);
1701 * If field size is not more than 24 octets,
1702 * then use SHA-1 hash of result; otherwise,
1703 * use result (see section 4.8 of
1704 * draft-ietf-tls-ecc-03.txt).
1706 int field_size
, outlen
;
1707 void *(*kdf
) (const void *in
, size_t inlen
, void *out
, size_t * xoutlen
);
1708 field_size
= EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a
[j
]));
1709 if (field_size
<= 24 * 8) {
1710 outlen
= KDF1_SHA1_len
;
1713 outlen
= (field_size
+ 7) / 8;
1716 secret_size_a
= ECDH_compute_key(secret_a
, outlen
,
1717 EC_KEY_get0_public_key(ecdh_b
[j
]),
1719 secret_size_b
= ECDH_compute_key(secret_b
, outlen
,
1720 EC_KEY_get0_public_key(ecdh_a
[j
]),
1722 if (secret_size_a
!= secret_size_b
)
1727 for (secret_idx
= 0;
1728 (secret_idx
< secret_size_a
)
1729 && (ecdh_checks
== 1);
1731 if (secret_a
[secret_idx
] != secret_b
[secret_idx
])
1735 if (ecdh_checks
== 0) {
1737 "ECDH computations don't match.\n");
1738 ERR_print_errors(bio_err
);
1741 pkey_print_message("", "ecdh",
1743 test_curves_bits
[j
],
1746 for (count
= 0, run
= 1;
1747 COND(ecdh_c
[j
][0]); count
++) {
1748 ECDH_compute_key(secret_a
,
1750 EC_KEY_get0_public_key(ecdh_b
[j
]),
1754 BIO_printf(bio_err
, mr
1755 ? "+R7:%ld:%d:%.2f\n"
1756 : "%ld %d-bit ECDH ops in %.2fs\n",
1757 count
, test_curves_bits
[j
], d
);
1758 ecdh_results
[j
][0] = d
/ (double) count
;
1765 if (rsa_count
<= 1) {
1766 /* if longer than 10s, don't do any more */
1767 for (j
++; j
< EC_NUM
; j
++)
1773 fprintf(stdout
, "%s\n", SSLeay_version(SSLEAY_VERSION
));
1774 fprintf(stdout
, "%s\n", SSLeay_version(SSLEAY_BUILT_ON
));
1776 printf("%s ", BN_options());
1777 #ifndef OPENSSL_NO_RC4
1778 printf("%s ", RC4_options());
1780 #ifndef OPENSSL_NO_DES
1781 printf("%s ", DES_options());
1783 #ifndef OPENSSL_NO_AES
1784 printf("%s ", AES_options());
1786 #ifndef OPENSSL_NO_IDEA
1787 printf("%s ", idea_options());
1789 #ifndef OPENSSL_NO_BF
1790 printf("%s ", BF_options());
1792 fprintf(stdout
, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS
));
1796 fprintf(stdout
, "+H");
1798 fprintf(stdout
, "The 'numbers' are in 1000s of bytes per second processed.\n");
1799 fprintf(stdout
, "type ");
1801 for (j
= 0; j
< SIZE_NUM
; j
++)
1802 fprintf(stdout
, mr
? ":%d" : "%7d bytes", lengths
[j
]);
1803 fprintf(stdout
, "\n");
1805 for (k
= 0; k
< ALGOR_NUM
; k
++) {
1809 fprintf(stdout
, "+F:%d:%s", k
, names
[k
]);
1811 fprintf(stdout
, "%-13s", names
[k
]);
1812 for (j
= 0; j
< SIZE_NUM
; j
++) {
1813 if (results
[k
][j
] > 10000 && !mr
)
1814 fprintf(stdout
, " %11.2fk", results
[k
][j
] / 1e3
);
1816 fprintf(stdout
, mr
? ":%.2f" : " %11.2f ", results
[k
][j
]);
1818 fprintf(stdout
, "\n");
1821 for (k
= 0; k
< RSA_NUM
; k
++) {
1825 printf("%18ssign verify sign/s verify/s\n", " ");
1829 fprintf(stdout
, "+F2:%u:%u:%f:%f\n",
1830 k
, rsa_bits
[k
], rsa_results
[k
][0],
1833 fprintf(stdout
, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1834 rsa_bits
[k
], rsa_results
[k
][0], rsa_results
[k
][1],
1835 1.0 / rsa_results
[k
][0], 1.0 / rsa_results
[k
][1]);
1838 for (k
= 0; k
< DSA_NUM
; k
++) {
1842 printf("%18ssign verify sign/s verify/s\n", " ");
1846 fprintf(stdout
, "+F3:%u:%u:%f:%f\n",
1847 k
, dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1]);
1849 fprintf(stdout
, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1850 dsa_bits
[k
], dsa_results
[k
][0], dsa_results
[k
][1],
1851 1.0 / dsa_results
[k
][0], 1.0 / dsa_results
[k
][1]);
1854 for (k
= 0; k
< EC_NUM
; k
++) {
1858 printf("%30ssign verify sign/s verify/s\n", " ");
1862 fprintf(stdout
, "+F4:%u:%u:%f:%f\n",
1863 k
, test_curves_bits
[k
],
1864 ecdsa_results
[k
][0], ecdsa_results
[k
][1]);
1867 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
1868 test_curves_bits
[k
],
1869 test_curves_names
[k
],
1870 ecdsa_results
[k
][0], ecdsa_results
[k
][1],
1871 1.0 / ecdsa_results
[k
][0], 1.0 / ecdsa_results
[k
][1]);
1876 for (k
= 0; k
< EC_NUM
; k
++) {
1880 printf("%30sop op/s\n", " ");
1884 fprintf(stdout
, "+F5:%u:%u:%f:%f\n",
1885 k
, test_curves_bits
[k
],
1886 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
1889 fprintf(stdout
, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
1890 test_curves_bits
[k
],
1891 test_curves_names
[k
],
1892 ecdh_results
[k
][0], 1.0 / ecdh_results
[k
][0]);
1898 ERR_print_errors(bio_err
);
1901 for (i
= 0; i
< RSA_NUM
; i
++)
1902 if (rsa_key
[i
] != NULL
)
1903 RSA_free(rsa_key
[i
]);
1904 for (i
= 0; i
< DSA_NUM
; i
++)
1905 if (dsa_key
[i
] != NULL
)
1906 DSA_free(dsa_key
[i
]);
1908 for (i
= 0; i
< EC_NUM
; i
++)
1909 if (ecdsa
[i
] != NULL
)
1910 EC_KEY_free(ecdsa
[i
]);
1911 for (i
= 0; i
< EC_NUM
; i
++) {
1912 if (ecdh_a
[i
] != NULL
)
1913 EC_KEY_free(ecdh_a
[i
]);
1914 if (ecdh_b
[i
] != NULL
)
1915 EC_KEY_free(ecdh_b
[i
]);
1923 print_message(const char *s
, long num
, int length
)
1925 BIO_printf(bio_err
, mr
? "+DT:%s:%d:%d\n"
1926 : "Doing %s for %ds on %d size blocks: ", s
, SECONDS
, length
);
1927 (void) BIO_flush(bio_err
);
1932 pkey_print_message(const char *str
, const char *str2
, long num
,
1935 BIO_printf(bio_err
, mr
? "+DTP:%d:%s:%s:%d\n"
1936 : "Doing %d bit %s %s's for %ds: ", bits
, str
, str2
, tm
);
1937 (void) BIO_flush(bio_err
);
1942 print_result(int alg
, int run_no
, int count
, double time_used
)
1944 BIO_printf(bio_err
, mr
? "+R:%d:%s:%f\n"
1945 : "%d %s's in %.2fs\n", count
, names
[alg
], time_used
);
1946 results
[alg
][run_no
] = ((double) count
) / time_used
* lengths
[run_no
];
1950 sstrsep(char **string
, const char *delim
)
1953 char *token
= *string
;
1958 memset(isdelim
, 0, sizeof isdelim
);
1962 isdelim
[(unsigned char) (*delim
)] = 1;
1966 while (!isdelim
[(unsigned char) (**string
)]) {
1983 static char sep
[] = ":";
1984 const char *errstr
= NULL
;
1986 fds
= reallocarray(NULL
, multi
, sizeof *fds
);
1988 fprintf(stderr
, "reallocarray failure\n");
1991 for (n
= 0; n
< multi
; ++n
) {
1992 if (pipe(fd
) == -1) {
1993 fprintf(stderr
, "pipe failure\n");
2004 if (dup(fd
[1]) == -1) {
2005 fprintf(stderr
, "dup failed\n");
2014 printf("Forked child %d\n", n
);
2017 /* for now, assume the pipe is long enough to take all the output */
2018 for (n
= 0; n
< multi
; ++n
) {
2023 f
= fdopen(fds
[n
], "r");
2024 while (fgets(buf
, sizeof buf
, f
)) {
2025 p
= strchr(buf
, '\n');
2028 if (buf
[0] != '+') {
2029 fprintf(stderr
, "Don't understand line '%s' from child %d\n",
2033 printf("Got: %s from %d\n", buf
, n
);
2034 if (!strncmp(buf
, "+F:", 3)) {
2039 alg
= strtonum(sstrsep(&p
, sep
),
2040 0, ALGOR_NUM
- 1, &errstr
);
2042 for (j
= 0; j
< SIZE_NUM
; ++j
)
2043 results
[alg
][j
] += atof(sstrsep(&p
, sep
));
2044 } else if (!strncmp(buf
, "+F2:", 4)) {
2049 k
= strtonum(sstrsep(&p
, sep
),
2050 0, ALGOR_NUM
- 1, &errstr
);
2053 d
= atof(sstrsep(&p
, sep
));
2055 rsa_results
[k
][0] = 1 / (1 / rsa_results
[k
][0] + 1 / d
);
2057 rsa_results
[k
][0] = d
;
2059 d
= atof(sstrsep(&p
, sep
));
2061 rsa_results
[k
][1] = 1 / (1 / rsa_results
[k
][1] + 1 / d
);
2063 rsa_results
[k
][1] = d
;
2064 } else if (!strncmp(buf
, "+F2:", 4)) {
2069 k
= strtonum(sstrsep(&p
, sep
),
2070 0, ALGOR_NUM
- 1, &errstr
);
2073 d
= atof(sstrsep(&p
, sep
));
2075 rsa_results
[k
][0] = 1 / (1 / rsa_results
[k
][0] + 1 / d
);
2077 rsa_results
[k
][0] = d
;
2079 d
= atof(sstrsep(&p
, sep
));
2081 rsa_results
[k
][1] = 1 / (1 / rsa_results
[k
][1] + 1 / d
);
2083 rsa_results
[k
][1] = d
;
2085 else if (!strncmp(buf
, "+F3:", 4)) {
2090 k
= strtonum(sstrsep(&p
, sep
),
2091 0, ALGOR_NUM
- 1, &errstr
);
2094 d
= atof(sstrsep(&p
, sep
));
2096 dsa_results
[k
][0] = 1 / (1 / dsa_results
[k
][0] + 1 / d
);
2098 dsa_results
[k
][0] = d
;
2100 d
= atof(sstrsep(&p
, sep
));
2102 dsa_results
[k
][1] = 1 / (1 / dsa_results
[k
][1] + 1 / d
);
2104 dsa_results
[k
][1] = d
;
2106 else if (!strncmp(buf
, "+F4:", 4)) {
2111 k
= strtonum(sstrsep(&p
, sep
),
2112 0, ALGOR_NUM
- 1, &errstr
);
2115 d
= atof(sstrsep(&p
, sep
));
2117 ecdsa_results
[k
][0] = 1 / (1 / ecdsa_results
[k
][0] + 1 / d
);
2119 ecdsa_results
[k
][0] = d
;
2121 d
= atof(sstrsep(&p
, sep
));
2123 ecdsa_results
[k
][1] = 1 / (1 / ecdsa_results
[k
][1] + 1 / d
);
2125 ecdsa_results
[k
][1] = d
;
2128 else if (!strncmp(buf
, "+F5:", 4)) {
2133 k
= strtonum(sstrsep(&p
, sep
),
2134 0, ALGOR_NUM
- 1, &errstr
);
2137 d
= atof(sstrsep(&p
, sep
));
2139 ecdh_results
[k
][0] = 1 / (1 / ecdh_results
[k
][0] + 1 / d
);
2141 ecdh_results
[k
][0] = d
;
2145 else if (!strncmp(buf
, "+H:", 3)) {
2147 fprintf(stderr
, "Unknown type '%s' from child %d\n", buf
, n
);