xref: /dragonfly/crypto/libressl/apps/openssl/speed.c (revision cca6fc52)
1 /* $OpenBSD: speed.c,v 1.23 2018/07/13 18:36:56 cheloha Exp $ */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3  * All rights reserved.
4  *
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.
8  *
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).
15  *
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.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
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)"
40  *
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
51  * SUCH DAMAGE.
52  *
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.]
57  */
58 /* ====================================================================
59  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60  *
61  * Portions of the attached software ("Contribution") are developed by
62  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63  *
64  * The Contribution is licensed pursuant to the OpenSSL open source
65  * license provided above.
66  *
67  * The ECDH and ECDSA speed test software is originally written by
68  * Sumit Gupta of Sun Microsystems Laboratories.
69  *
70  */
71 
72 /* most of this code has been pilfered from my libdes speed.c program */
73 
74 #ifndef OPENSSL_NO_SPEED
75 
76 #define SECONDS		3
77 #define RSA_SECONDS	10
78 #define DSA_SECONDS	10
79 #define ECDSA_SECONDS   10
80 #define ECDH_SECONDS    10
81 
82 #include <math.h>
83 #include <signal.h>
84 #include <stdio.h>
85 #include <stdlib.h>
86 #include <limits.h>
87 #include <string.h>
88 #include <unistd.h>
89 
90 #include "apps.h"
91 
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>
99 
100 #ifndef OPENSSL_NO_AES
101 #include <openssl/aes.h>
102 #endif
103 #ifndef OPENSSL_NO_BF
104 #include <openssl/blowfish.h>
105 #endif
106 #ifndef OPENSSL_NO_CAST
107 #include <openssl/cast.h>
108 #endif
109 #ifndef OPENSSL_NO_CAMELLIA
110 #include <openssl/camellia.h>
111 #endif
112 #ifndef OPENSSL_NO_DES
113 #include <openssl/des.h>
114 #endif
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>
120 #endif
121 #ifndef OPENSSL_NO_IDEA
122 #include <openssl/idea.h>
123 #endif
124 #ifndef OPENSSL_NO_MD4
125 #include <openssl/md4.h>
126 #endif
127 #ifndef OPENSSL_NO_MD5
128 #include <openssl/md5.h>
129 #endif
130 #ifndef OPENSSL_NO_RC2
131 #include <openssl/rc2.h>
132 #endif
133 #ifndef OPENSSL_NO_RC4
134 #include <openssl/rc4.h>
135 #endif
136 #include <openssl/rsa.h>
137 #ifndef OPENSSL_NO_RIPEMD
138 #include <openssl/ripemd.h>
139 #endif
140 #ifndef OPENSSL_NO_SHA
141 #include <openssl/sha.h>
142 #endif
143 #ifndef OPENSSL_NO_WHIRLPOOL
144 #include <openssl/whrlpool.h>
145 #endif
146 
147 #include "./testdsa.h"
148 #include "./testrsa.h"
149 
150 #define BUFSIZE	(1024*8+64)
151 int run = 0;
152 
153 static int mr = 0;
154 static int usertime = 1;
155 
156 static double Time_F(int s);
157 static void print_message(const char *s, long num, int length);
158 static void
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 #ifndef _WIN32
163 static int do_multi(int multi);
164 #else
165 void speed_signal(int sigcatch, void (*func)(int sigraised));
166 unsigned int speed_alarm(unsigned int seconds);
167 void speed_alarm_free(int run);
168 #define SIGALRM		14
169 #define signal(sigcatch, func)	speed_signal((sigcatch), (func))
170 #define alarm(seconds)		speed_alarm((seconds))
171 #endif
172 
173 #define ALGOR_NUM	32
174 #define SIZE_NUM	5
175 #define RSA_NUM		4
176 #define DSA_NUM		3
177 
178 #define EC_NUM       16
179 #define MAX_ECDH_SIZE 256
180 
181 static const char *names[ALGOR_NUM] = {
182 	"md2", "md4", "md5", "hmac(md5)", "sha1", "rmd160",
183 	"rc4", "des cbc", "des ede3", "idea cbc", "seed cbc",
184 	"rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
185 	"aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
186 	"camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
187 	"evp", "sha256", "sha512", "whirlpool",
188 	"aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
189 	"aes-128 gcm", "aes-256 gcm", "chacha20 poly1305",
190 };
191 static double results[ALGOR_NUM][SIZE_NUM];
192 static int lengths[SIZE_NUM] = {16, 64, 256, 1024, 8 * 1024};
193 static double rsa_results[RSA_NUM][2];
194 static double dsa_results[DSA_NUM][2];
195 static double ecdsa_results[EC_NUM][2];
196 static double ecdh_results[EC_NUM][1];
197 
198 static void sig_done(int sig);
199 
200 static void
201 sig_done(int sig)
202 {
203 	signal(SIGALRM, sig_done);
204 	run = 0;
205 }
206 
207 #define START	TM_RESET
208 #define STOP	TM_GET
209 
210 
211 static double
212 Time_F(int s)
213 {
214 	if (usertime)
215 		return app_timer_user(s);
216 	else
217 		return app_timer_real(s);
218 }
219 
220 
221 static const int KDF1_SHA1_len = 20;
222 static void *
223 KDF1_SHA1(const void *in, size_t inlen, void *out, size_t * outlen)
224 {
225 #ifndef OPENSSL_NO_SHA
226 	if (*outlen < SHA_DIGEST_LENGTH)
227 		return NULL;
228 	else
229 		*outlen = SHA_DIGEST_LENGTH;
230 	return SHA1(in, inlen, out);
231 #else
232 	return NULL;
233 #endif				/* OPENSSL_NO_SHA */
234 }
235 
236 int
237 speed_main(int argc, char **argv)
238 {
239 	unsigned char *buf = NULL, *buf2 = NULL;
240 	int mret = 1;
241 	long count = 0, save_count = 0;
242 	int i, j, k;
243 	long rsa_count;
244 	unsigned rsa_num;
245 	unsigned char md[EVP_MAX_MD_SIZE];
246 #ifndef OPENSSL_NO_MD4
247 	unsigned char md4[MD4_DIGEST_LENGTH];
248 #endif
249 #ifndef OPENSSL_NO_MD5
250 	unsigned char md5[MD5_DIGEST_LENGTH];
251 	unsigned char hmac[MD5_DIGEST_LENGTH];
252 #endif
253 #ifndef OPENSSL_NO_SHA
254 	unsigned char sha[SHA_DIGEST_LENGTH];
255 #ifndef OPENSSL_NO_SHA256
256 	unsigned char sha256[SHA256_DIGEST_LENGTH];
257 #endif
258 #ifndef OPENSSL_NO_SHA512
259 	unsigned char sha512[SHA512_DIGEST_LENGTH];
260 #endif
261 #endif
262 #ifndef OPENSSL_NO_WHIRLPOOL
263 	unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
264 #endif
265 #ifndef OPENSSL_NO_RIPEMD
266 	unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
267 #endif
268 #ifndef OPENSSL_NO_RC4
269 	RC4_KEY rc4_ks;
270 #endif
271 #ifndef OPENSSL_NO_RC2
272 	RC2_KEY rc2_ks;
273 #endif
274 #ifndef OPENSSL_NO_IDEA
275 	IDEA_KEY_SCHEDULE idea_ks;
276 #endif
277 #ifndef OPENSSL_NO_BF
278 	BF_KEY bf_ks;
279 #endif
280 #ifndef OPENSSL_NO_CAST
281 	CAST_KEY cast_ks;
282 #endif
283 	static const unsigned char key16[16] =
284 	{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
285 	0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
286 #ifndef OPENSSL_NO_AES
287 	static const unsigned char key24[24] =
288 	{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
289 		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
290 	0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
291 	static const unsigned char key32[32] =
292 	{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
293 		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
294 		0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
295 	0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
296 #endif
297 #ifndef OPENSSL_NO_CAMELLIA
298 	static const unsigned char ckey24[24] =
299 	{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
300 		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
301 	0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
302 	static const unsigned char ckey32[32] =
303 	{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
304 		0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
305 		0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
306 	0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
307 #endif
308 #ifndef OPENSSL_NO_AES
309 #define MAX_BLOCK_SIZE 128
310 #else
311 #define MAX_BLOCK_SIZE 64
312 #endif
313 	unsigned char DES_iv[8];
314 	unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
315 #ifndef OPENSSL_NO_DES
316 	static DES_cblock key = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
317 	static DES_cblock key2 = {0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
318 	static DES_cblock key3 = {0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
319 	DES_key_schedule sch;
320 	DES_key_schedule sch2;
321 	DES_key_schedule sch3;
322 #endif
323 #ifndef OPENSSL_NO_AES
324 	AES_KEY aes_ks1, aes_ks2, aes_ks3;
325 #endif
326 #ifndef OPENSSL_NO_CAMELLIA
327 	CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
328 #endif
329 #define	D_MD2		0
330 #define	D_MD4		1
331 #define	D_MD5		2
332 #define	D_HMAC		3
333 #define	D_SHA1		4
334 #define D_RMD160	5
335 #define	D_RC4		6
336 #define	D_CBC_DES	7
337 #define	D_EDE3_DES	8
338 #define	D_CBC_IDEA	9
339 #define	D_CBC_SEED	10
340 #define	D_CBC_RC2	11
341 #define	D_CBC_RC5	12
342 #define	D_CBC_BF	13
343 #define	D_CBC_CAST	14
344 #define D_CBC_128_AES	15
345 #define D_CBC_192_AES	16
346 #define D_CBC_256_AES	17
347 #define D_CBC_128_CML   18
348 #define D_CBC_192_CML   19
349 #define D_CBC_256_CML   20
350 #define D_EVP		21
351 #define D_SHA256	22
352 #define D_SHA512	23
353 #define D_WHIRLPOOL	24
354 #define D_IGE_128_AES   25
355 #define D_IGE_192_AES   26
356 #define D_IGE_256_AES   27
357 #define D_GHASH		28
358 #define D_AES_128_GCM	29
359 #define D_AES_256_GCM	30
360 #define D_CHACHA20_POLY1305	31
361 	double d = 0.0;
362 	long c[ALGOR_NUM][SIZE_NUM];
363 #define	R_DSA_512	0
364 #define	R_DSA_1024	1
365 #define	R_DSA_2048	2
366 #define	R_RSA_512	0
367 #define	R_RSA_1024	1
368 #define	R_RSA_2048	2
369 #define	R_RSA_4096	3
370 
371 #define R_EC_P160    0
372 #define R_EC_P192    1
373 #define R_EC_P224    2
374 #define R_EC_P256    3
375 #define R_EC_P384    4
376 #define R_EC_P521    5
377 #define R_EC_K163    6
378 #define R_EC_K233    7
379 #define R_EC_K283    8
380 #define R_EC_K409    9
381 #define R_EC_K571    10
382 #define R_EC_B163    11
383 #define R_EC_B233    12
384 #define R_EC_B283    13
385 #define R_EC_B409    14
386 #define R_EC_B571    15
387 
388 	RSA *rsa_key[RSA_NUM];
389 	long rsa_c[RSA_NUM][2];
390 	static unsigned int rsa_bits[RSA_NUM] = {512, 1024, 2048, 4096};
391 	static unsigned char *rsa_data[RSA_NUM] =
392 	{test512, test1024, test2048, test4096};
393 	static int rsa_data_length[RSA_NUM] = {
394 		sizeof(test512), sizeof(test1024),
395 	sizeof(test2048), sizeof(test4096)};
396 	DSA *dsa_key[DSA_NUM];
397 	long dsa_c[DSA_NUM][2];
398 	static unsigned int dsa_bits[DSA_NUM] = {512, 1024, 2048};
399 #ifndef OPENSSL_NO_EC
400 	/*
401 	 * We only test over the following curves as they are representative,
402 	 * To add tests over more curves, simply add the curve NID and curve
403 	 * name to the following arrays and increase the EC_NUM value
404 	 * accordingly.
405 	 */
406 	static unsigned int test_curves[EC_NUM] =
407 	{
408 		/* Prime Curves */
409 		NID_secp160r1,
410 		NID_X9_62_prime192v1,
411 		NID_secp224r1,
412 		NID_X9_62_prime256v1,
413 		NID_secp384r1,
414 		NID_secp521r1,
415 		/* Binary Curves */
416 		NID_sect163k1,
417 		NID_sect233k1,
418 		NID_sect283k1,
419 		NID_sect409k1,
420 		NID_sect571k1,
421 		NID_sect163r2,
422 		NID_sect233r1,
423 		NID_sect283r1,
424 		NID_sect409r1,
425 		NID_sect571r1
426 	};
427 	static const char *test_curves_names[EC_NUM] =
428 	{
429 		/* Prime Curves */
430 		"secp160r1",
431 		"nistp192",
432 		"nistp224",
433 		"nistp256",
434 		"nistp384",
435 		"nistp521",
436 		/* Binary Curves */
437 		"nistk163",
438 		"nistk233",
439 		"nistk283",
440 		"nistk409",
441 		"nistk571",
442 		"nistb163",
443 		"nistb233",
444 		"nistb283",
445 		"nistb409",
446 		"nistb571"
447 	};
448 	static int test_curves_bits[EC_NUM] =
449 	{
450 		160, 192, 224, 256, 384, 521,
451 		163, 233, 283, 409, 571,
452 		163, 233, 283, 409, 571
453 	};
454 
455 #endif
456 
457 	unsigned char ecdsasig[256];
458 	unsigned int ecdsasiglen;
459 	EC_KEY *ecdsa[EC_NUM];
460 	long ecdsa_c[EC_NUM][2];
461 
462 	EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
463 	unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
464 	int secret_size_a, secret_size_b;
465 	int ecdh_checks = 0;
466 	int secret_idx = 0;
467 	long ecdh_c[EC_NUM][2];
468 
469 	int rsa_doit[RSA_NUM];
470 	int dsa_doit[DSA_NUM];
471 	int ecdsa_doit[EC_NUM];
472 	int ecdh_doit[EC_NUM];
473 	int doit[ALGOR_NUM];
474 	int pr_header = 0;
475 	const EVP_CIPHER *evp_cipher = NULL;
476 	const EVP_MD *evp_md = NULL;
477 	int decrypt = 0;
478 #ifndef _WIN32
479 	int multi = 0;
480 	const char *errstr = NULL;
481 #endif
482 
483 	if (single_execution) {
484 		if (pledge("stdio proc", NULL) == -1) {
485 			perror("pledge");
486 			exit(1);
487 		}
488 	}
489 
490 	usertime = -1;
491 
492 	memset(results, 0, sizeof(results));
493 	memset(dsa_key, 0, sizeof(dsa_key));
494 	for (i = 0; i < EC_NUM; i++)
495 		ecdsa[i] = NULL;
496 	for (i = 0; i < EC_NUM; i++) {
497 		ecdh_a[i] = NULL;
498 		ecdh_b[i] = NULL;
499 	}
500 
501 	memset(rsa_key, 0, sizeof(rsa_key));
502 	for (i = 0; i < RSA_NUM; i++)
503 		rsa_key[i] = NULL;
504 
505 	if ((buf = malloc(BUFSIZE)) == NULL) {
506 		BIO_printf(bio_err, "out of memory\n");
507 		goto end;
508 	}
509 	if ((buf2 = malloc(BUFSIZE)) == NULL) {
510 		BIO_printf(bio_err, "out of memory\n");
511 		goto end;
512 	}
513 	memset(c, 0, sizeof(c));
514 	memset(DES_iv, 0, sizeof(DES_iv));
515 	memset(iv, 0, sizeof(iv));
516 
517 	for (i = 0; i < ALGOR_NUM; i++)
518 		doit[i] = 0;
519 	for (i = 0; i < RSA_NUM; i++)
520 		rsa_doit[i] = 0;
521 	for (i = 0; i < DSA_NUM; i++)
522 		dsa_doit[i] = 0;
523 	for (i = 0; i < EC_NUM; i++)
524 		ecdsa_doit[i] = 0;
525 	for (i = 0; i < EC_NUM; i++)
526 		ecdh_doit[i] = 0;
527 
528 
529 	j = 0;
530 	argc--;
531 	argv++;
532 	while (argc) {
533 		if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
534 			usertime = 0;
535 			j--;	/* Otherwise, -elapsed gets confused with an
536 				 * algorithm. */
537 		} else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
538 			argc--;
539 			argv++;
540 			if (argc == 0) {
541 				BIO_printf(bio_err, "no EVP given\n");
542 				goto end;
543 			}
544 			evp_cipher = EVP_get_cipherbyname(*argv);
545 			if (!evp_cipher) {
546 				evp_md = EVP_get_digestbyname(*argv);
547 			}
548 			if (!evp_cipher && !evp_md) {
549 				BIO_printf(bio_err, "%s is an unknown cipher or digest\n", *argv);
550 				goto end;
551 			}
552 			doit[D_EVP] = 1;
553 		} else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
554 			decrypt = 1;
555 			j--;	/* Otherwise, -decrypt gets confused with an
556 				 * algorithm. */
557 		}
558 #ifndef _WIN32
559 		else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
560 			argc--;
561 			argv++;
562 			if (argc == 0) {
563 				BIO_printf(bio_err, "no multi count given\n");
564 				goto end;
565 			}
566 			multi = strtonum(argv[0], 1, INT_MAX, &errstr);
567 			if (errstr) {
568 				BIO_printf(bio_err, "bad multi count: %s", errstr);
569 				goto end;
570 			}
571 			j--;	/* Otherwise, -multi gets confused with an
572 				 * algorithm. */
573 		}
574 #endif
575 		else if (argc > 0 && !strcmp(*argv, "-mr")) {
576 			mr = 1;
577 			j--;	/* Otherwise, -mr gets confused with an
578 				 * algorithm. */
579 		} else
580 #ifndef OPENSSL_NO_MD4
581 		if (strcmp(*argv, "md4") == 0)
582 			doit[D_MD4] = 1;
583 		else
584 #endif
585 #ifndef OPENSSL_NO_MD5
586 		if (strcmp(*argv, "md5") == 0)
587 			doit[D_MD5] = 1;
588 		else
589 #endif
590 #ifndef OPENSSL_NO_MD5
591 		if (strcmp(*argv, "hmac") == 0)
592 			doit[D_HMAC] = 1;
593 		else
594 #endif
595 #ifndef OPENSSL_NO_SHA
596 		if (strcmp(*argv, "sha1") == 0)
597 			doit[D_SHA1] = 1;
598 		else if (strcmp(*argv, "sha") == 0)
599 			doit[D_SHA1] = 1,
600 			    doit[D_SHA256] = 1,
601 			    doit[D_SHA512] = 1;
602 		else
603 #ifndef OPENSSL_NO_SHA256
604 		if (strcmp(*argv, "sha256") == 0)
605 			doit[D_SHA256] = 1;
606 		else
607 #endif
608 #ifndef OPENSSL_NO_SHA512
609 		if (strcmp(*argv, "sha512") == 0)
610 			doit[D_SHA512] = 1;
611 		else
612 #endif
613 #endif
614 #ifndef OPENSSL_NO_WHIRLPOOL
615 		if (strcmp(*argv, "whirlpool") == 0)
616 			doit[D_WHIRLPOOL] = 1;
617 		else
618 #endif
619 #ifndef OPENSSL_NO_RIPEMD
620 		if (strcmp(*argv, "ripemd") == 0)
621 			doit[D_RMD160] = 1;
622 		else if (strcmp(*argv, "rmd160") == 0)
623 			doit[D_RMD160] = 1;
624 		else if (strcmp(*argv, "ripemd160") == 0)
625 			doit[D_RMD160] = 1;
626 		else
627 #endif
628 #ifndef OPENSSL_NO_RC4
629 		if (strcmp(*argv, "rc4") == 0)
630 			doit[D_RC4] = 1;
631 		else
632 #endif
633 #ifndef OPENSSL_NO_DES
634 		if (strcmp(*argv, "des-cbc") == 0)
635 			doit[D_CBC_DES] = 1;
636 		else if (strcmp(*argv, "des-ede3") == 0)
637 			doit[D_EDE3_DES] = 1;
638 		else
639 #endif
640 #ifndef OPENSSL_NO_AES
641 		if (strcmp(*argv, "aes-128-cbc") == 0)
642 			doit[D_CBC_128_AES] = 1;
643 		else if (strcmp(*argv, "aes-192-cbc") == 0)
644 			doit[D_CBC_192_AES] = 1;
645 		else if (strcmp(*argv, "aes-256-cbc") == 0)
646 			doit[D_CBC_256_AES] = 1;
647 		else if (strcmp(*argv, "aes-128-ige") == 0)
648 			doit[D_IGE_128_AES] = 1;
649 		else if (strcmp(*argv, "aes-192-ige") == 0)
650 			doit[D_IGE_192_AES] = 1;
651 		else if (strcmp(*argv, "aes-256-ige") == 0)
652 			doit[D_IGE_256_AES] = 1;
653 		else
654 #endif
655 #ifndef OPENSSL_NO_CAMELLIA
656 		if (strcmp(*argv, "camellia-128-cbc") == 0)
657 			doit[D_CBC_128_CML] = 1;
658 		else if (strcmp(*argv, "camellia-192-cbc") == 0)
659 			doit[D_CBC_192_CML] = 1;
660 		else if (strcmp(*argv, "camellia-256-cbc") == 0)
661 			doit[D_CBC_256_CML] = 1;
662 		else
663 #endif
664 #ifndef RSA_NULL
665 		if (strcmp(*argv, "openssl") == 0) {
666 			RSA_set_default_method(RSA_PKCS1_SSLeay());
667 			j--;
668 		} else
669 #endif
670 		if (strcmp(*argv, "dsa512") == 0)
671 			dsa_doit[R_DSA_512] = 2;
672 		else if (strcmp(*argv, "dsa1024") == 0)
673 			dsa_doit[R_DSA_1024] = 2;
674 		else if (strcmp(*argv, "dsa2048") == 0)
675 			dsa_doit[R_DSA_2048] = 2;
676 		else if (strcmp(*argv, "rsa512") == 0)
677 			rsa_doit[R_RSA_512] = 2;
678 		else if (strcmp(*argv, "rsa1024") == 0)
679 			rsa_doit[R_RSA_1024] = 2;
680 		else if (strcmp(*argv, "rsa2048") == 0)
681 			rsa_doit[R_RSA_2048] = 2;
682 		else if (strcmp(*argv, "rsa4096") == 0)
683 			rsa_doit[R_RSA_4096] = 2;
684 		else
685 #ifndef OPENSSL_NO_RC2
686 		if (strcmp(*argv, "rc2-cbc") == 0)
687 			doit[D_CBC_RC2] = 1;
688 		else if (strcmp(*argv, "rc2") == 0)
689 			doit[D_CBC_RC2] = 1;
690 		else
691 #endif
692 #ifndef OPENSSL_NO_IDEA
693 		if (strcmp(*argv, "idea-cbc") == 0)
694 			doit[D_CBC_IDEA] = 1;
695 		else if (strcmp(*argv, "idea") == 0)
696 			doit[D_CBC_IDEA] = 1;
697 		else
698 #endif
699 #ifndef OPENSSL_NO_BF
700 		if (strcmp(*argv, "bf-cbc") == 0)
701 			doit[D_CBC_BF] = 1;
702 		else if (strcmp(*argv, "blowfish") == 0)
703 			doit[D_CBC_BF] = 1;
704 		else if (strcmp(*argv, "bf") == 0)
705 			doit[D_CBC_BF] = 1;
706 		else
707 #endif
708 #ifndef OPENSSL_NO_CAST
709 		if (strcmp(*argv, "cast-cbc") == 0)
710 			doit[D_CBC_CAST] = 1;
711 		else if (strcmp(*argv, "cast") == 0)
712 			doit[D_CBC_CAST] = 1;
713 		else if (strcmp(*argv, "cast5") == 0)
714 			doit[D_CBC_CAST] = 1;
715 		else
716 #endif
717 #ifndef OPENSSL_NO_DES
718 		if (strcmp(*argv, "des") == 0) {
719 			doit[D_CBC_DES] = 1;
720 			doit[D_EDE3_DES] = 1;
721 		} else
722 #endif
723 #ifndef OPENSSL_NO_AES
724 		if (strcmp(*argv, "aes") == 0) {
725 			doit[D_CBC_128_AES] = 1;
726 			doit[D_CBC_192_AES] = 1;
727 			doit[D_CBC_256_AES] = 1;
728 		} else if (strcmp(*argv, "ghash") == 0)
729 			doit[D_GHASH] = 1;
730 		else if (strcmp(*argv,"aes-128-gcm") == 0)
731 			doit[D_AES_128_GCM]=1;
732 		else if (strcmp(*argv,"aes-256-gcm") == 0)
733 			doit[D_AES_256_GCM]=1;
734 		else
735 #endif
736 #ifndef OPENSSL_NO_CAMELLIA
737 		if (strcmp(*argv, "camellia") == 0) {
738 			doit[D_CBC_128_CML] = 1;
739 			doit[D_CBC_192_CML] = 1;
740 			doit[D_CBC_256_CML] = 1;
741 		} else
742 #endif
743 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
744 		if (strcmp(*argv,"chacha20-poly1305") == 0)
745 			doit[D_CHACHA20_POLY1305]=1;
746 		else
747 #endif
748 		if (strcmp(*argv, "rsa") == 0) {
749 			rsa_doit[R_RSA_512] = 1;
750 			rsa_doit[R_RSA_1024] = 1;
751 			rsa_doit[R_RSA_2048] = 1;
752 			rsa_doit[R_RSA_4096] = 1;
753 		} else
754 		if (strcmp(*argv, "dsa") == 0) {
755 			dsa_doit[R_DSA_512] = 1;
756 			dsa_doit[R_DSA_1024] = 1;
757 			dsa_doit[R_DSA_2048] = 1;
758 		} else
759 		if (strcmp(*argv, "ecdsap160") == 0)
760 			ecdsa_doit[R_EC_P160] = 2;
761 		else if (strcmp(*argv, "ecdsap192") == 0)
762 			ecdsa_doit[R_EC_P192] = 2;
763 		else if (strcmp(*argv, "ecdsap224") == 0)
764 			ecdsa_doit[R_EC_P224] = 2;
765 		else if (strcmp(*argv, "ecdsap256") == 0)
766 			ecdsa_doit[R_EC_P256] = 2;
767 		else if (strcmp(*argv, "ecdsap384") == 0)
768 			ecdsa_doit[R_EC_P384] = 2;
769 		else if (strcmp(*argv, "ecdsap521") == 0)
770 			ecdsa_doit[R_EC_P521] = 2;
771 		else if (strcmp(*argv, "ecdsak163") == 0)
772 			ecdsa_doit[R_EC_K163] = 2;
773 		else if (strcmp(*argv, "ecdsak233") == 0)
774 			ecdsa_doit[R_EC_K233] = 2;
775 		else if (strcmp(*argv, "ecdsak283") == 0)
776 			ecdsa_doit[R_EC_K283] = 2;
777 		else if (strcmp(*argv, "ecdsak409") == 0)
778 			ecdsa_doit[R_EC_K409] = 2;
779 		else if (strcmp(*argv, "ecdsak571") == 0)
780 			ecdsa_doit[R_EC_K571] = 2;
781 		else if (strcmp(*argv, "ecdsab163") == 0)
782 			ecdsa_doit[R_EC_B163] = 2;
783 		else if (strcmp(*argv, "ecdsab233") == 0)
784 			ecdsa_doit[R_EC_B233] = 2;
785 		else if (strcmp(*argv, "ecdsab283") == 0)
786 			ecdsa_doit[R_EC_B283] = 2;
787 		else if (strcmp(*argv, "ecdsab409") == 0)
788 			ecdsa_doit[R_EC_B409] = 2;
789 		else if (strcmp(*argv, "ecdsab571") == 0)
790 			ecdsa_doit[R_EC_B571] = 2;
791 		else if (strcmp(*argv, "ecdsa") == 0) {
792 			for (i = 0; i < EC_NUM; i++)
793 				ecdsa_doit[i] = 1;
794 		} else
795 		if (strcmp(*argv, "ecdhp160") == 0)
796 			ecdh_doit[R_EC_P160] = 2;
797 		else if (strcmp(*argv, "ecdhp192") == 0)
798 			ecdh_doit[R_EC_P192] = 2;
799 		else if (strcmp(*argv, "ecdhp224") == 0)
800 			ecdh_doit[R_EC_P224] = 2;
801 		else if (strcmp(*argv, "ecdhp256") == 0)
802 			ecdh_doit[R_EC_P256] = 2;
803 		else if (strcmp(*argv, "ecdhp384") == 0)
804 			ecdh_doit[R_EC_P384] = 2;
805 		else if (strcmp(*argv, "ecdhp521") == 0)
806 			ecdh_doit[R_EC_P521] = 2;
807 		else if (strcmp(*argv, "ecdhk163") == 0)
808 			ecdh_doit[R_EC_K163] = 2;
809 		else if (strcmp(*argv, "ecdhk233") == 0)
810 			ecdh_doit[R_EC_K233] = 2;
811 		else if (strcmp(*argv, "ecdhk283") == 0)
812 			ecdh_doit[R_EC_K283] = 2;
813 		else if (strcmp(*argv, "ecdhk409") == 0)
814 			ecdh_doit[R_EC_K409] = 2;
815 		else if (strcmp(*argv, "ecdhk571") == 0)
816 			ecdh_doit[R_EC_K571] = 2;
817 		else if (strcmp(*argv, "ecdhb163") == 0)
818 			ecdh_doit[R_EC_B163] = 2;
819 		else if (strcmp(*argv, "ecdhb233") == 0)
820 			ecdh_doit[R_EC_B233] = 2;
821 		else if (strcmp(*argv, "ecdhb283") == 0)
822 			ecdh_doit[R_EC_B283] = 2;
823 		else if (strcmp(*argv, "ecdhb409") == 0)
824 			ecdh_doit[R_EC_B409] = 2;
825 		else if (strcmp(*argv, "ecdhb571") == 0)
826 			ecdh_doit[R_EC_B571] = 2;
827 		else if (strcmp(*argv, "ecdh") == 0) {
828 			for (i = 0; i < EC_NUM; i++)
829 				ecdh_doit[i] = 1;
830 		} else
831 		{
832 			BIO_printf(bio_err, "Error: bad option or value\n");
833 			BIO_printf(bio_err, "\n");
834 			BIO_printf(bio_err, "Available values:\n");
835 #ifndef OPENSSL_NO_MD4
836 			BIO_printf(bio_err, "md4      ");
837 #endif
838 #ifndef OPENSSL_NO_MD5
839 			BIO_printf(bio_err, "md5      ");
840 #ifndef OPENSSL_NO_HMAC
841 			BIO_printf(bio_err, "hmac     ");
842 #endif
843 #endif
844 #ifndef OPENSSL_NO_SHA1
845 			BIO_printf(bio_err, "sha1     ");
846 #endif
847 #ifndef OPENSSL_NO_SHA256
848 			BIO_printf(bio_err, "sha256   ");
849 #endif
850 #ifndef OPENSSL_NO_SHA512
851 			BIO_printf(bio_err, "sha512   ");
852 #endif
853 #ifndef OPENSSL_NO_WHIRLPOOL
854 			BIO_printf(bio_err, "whirlpool");
855 #endif
856 #ifndef OPENSSL_NO_RIPEMD160
857 			BIO_printf(bio_err, "rmd160");
858 #endif
859 #if !defined(OPENSSL_NO_MD2) || \
860     !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
861     !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
862     !defined(OPENSSL_NO_WHIRLPOOL)
863 			BIO_printf(bio_err, "\n");
864 #endif
865 
866 #ifndef OPENSSL_NO_IDEA
867 			BIO_printf(bio_err, "idea-cbc ");
868 #endif
869 #ifndef OPENSSL_NO_RC2
870 			BIO_printf(bio_err, "rc2-cbc  ");
871 #endif
872 #ifndef OPENSSL_NO_BF
873 			BIO_printf(bio_err, "bf-cbc   ");
874 #endif
875 #ifndef OPENSSL_NO_DES
876 			BIO_printf(bio_err, "des-cbc  des-ede3\n");
877 #endif
878 #ifndef OPENSSL_NO_AES
879 			BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
880 			BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige\n");
881 			BIO_printf(bio_err, "aes-128-gcm aes-256-gcm ");
882 #endif
883 #ifndef OPENSSL_NO_CAMELLIA
884 			BIO_printf(bio_err, "\n");
885 			BIO_printf(bio_err, "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
886 #endif
887 #ifndef OPENSSL_NO_RC4
888 			BIO_printf(bio_err, "rc4");
889 #endif
890 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
891 			BIO_printf(bio_err," chacha20-poly1305");
892 #endif
893 			BIO_printf(bio_err, "\n");
894 
895 			BIO_printf(bio_err, "rsa512   rsa1024  rsa2048  rsa4096\n");
896 
897 			BIO_printf(bio_err, "dsa512   dsa1024  dsa2048\n");
898 			BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
899 			BIO_printf(bio_err, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
900 			BIO_printf(bio_err, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571 ecdsa\n");
901 			BIO_printf(bio_err, "ecdhp160  ecdhp192  ecdhp224  ecdhp256  ecdhp384  ecdhp521\n");
902 			BIO_printf(bio_err, "ecdhk163  ecdhk233  ecdhk283  ecdhk409  ecdhk571\n");
903 			BIO_printf(bio_err, "ecdhb163  ecdhb233  ecdhb283  ecdhb409  ecdhb571  ecdh\n");
904 
905 #ifndef OPENSSL_NO_IDEA
906 			BIO_printf(bio_err, "idea     ");
907 #endif
908 #ifndef OPENSSL_NO_RC2
909 			BIO_printf(bio_err, "rc2      ");
910 #endif
911 #ifndef OPENSSL_NO_DES
912 			BIO_printf(bio_err, "des      ");
913 #endif
914 #ifndef OPENSSL_NO_AES
915 			BIO_printf(bio_err, "aes      ");
916 #endif
917 #ifndef OPENSSL_NO_CAMELLIA
918 			BIO_printf(bio_err, "camellia ");
919 #endif
920 			BIO_printf(bio_err, "rsa      ");
921 #ifndef OPENSSL_NO_BF
922 			BIO_printf(bio_err, "blowfish");
923 #endif
924 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
925     !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
926     !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
927     !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
928 			BIO_printf(bio_err, "\n");
929 #endif
930 
931 			BIO_printf(bio_err, "\n");
932 			BIO_printf(bio_err, "Available options:\n");
933 			BIO_printf(bio_err, "-elapsed        measure time in real time instead of CPU user time.\n");
934 			BIO_printf(bio_err, "-evp e          use EVP e.\n");
935 			BIO_printf(bio_err, "-decrypt        time decryption instead of encryption (only EVP).\n");
936 			BIO_printf(bio_err, "-mr             produce machine readable output.\n");
937 #ifndef _WIN32
938 			BIO_printf(bio_err, "-multi n        run n benchmarks in parallel.\n");
939 #endif
940 			goto end;
941 		}
942 		argc--;
943 		argv++;
944 		j++;
945 	}
946 
947 #ifndef _WIN32
948 	if (multi && do_multi(multi))
949 		goto show_res;
950 #endif
951 
952 	if (j == 0) {
953 		for (i = 0; i < ALGOR_NUM; i++) {
954 			if (i != D_EVP)
955 				doit[i] = 1;
956 		}
957 		for (i = 0; i < RSA_NUM; i++)
958 			rsa_doit[i] = 1;
959 		for (i = 0; i < DSA_NUM; i++)
960 			dsa_doit[i] = 1;
961 		for (i = 0; i < EC_NUM; i++)
962 			ecdsa_doit[i] = 1;
963 		for (i = 0; i < EC_NUM; i++)
964 			ecdh_doit[i] = 1;
965 	}
966 	for (i = 0; i < ALGOR_NUM; i++)
967 		if (doit[i])
968 			pr_header++;
969 
970 	if (usertime == 0 && !mr)
971 		BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
972 
973 	for (i = 0; i < RSA_NUM; i++) {
974 		const unsigned char *p;
975 
976 		p = rsa_data[i];
977 		rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
978 		if (rsa_key[i] == NULL) {
979 			BIO_printf(bio_err, "internal error loading RSA key number %d\n", i);
980 			goto end;
981 		}
982 	}
983 
984 	dsa_key[0] = get_dsa512();
985 	dsa_key[1] = get_dsa1024();
986 	dsa_key[2] = get_dsa2048();
987 
988 #ifndef OPENSSL_NO_DES
989 	DES_set_key_unchecked(&key, &sch);
990 	DES_set_key_unchecked(&key2, &sch2);
991 	DES_set_key_unchecked(&key3, &sch3);
992 #endif
993 #ifndef OPENSSL_NO_AES
994 	AES_set_encrypt_key(key16, 128, &aes_ks1);
995 	AES_set_encrypt_key(key24, 192, &aes_ks2);
996 	AES_set_encrypt_key(key32, 256, &aes_ks3);
997 #endif
998 #ifndef OPENSSL_NO_CAMELLIA
999 	Camellia_set_key(key16, 128, &camellia_ks1);
1000 	Camellia_set_key(ckey24, 192, &camellia_ks2);
1001 	Camellia_set_key(ckey32, 256, &camellia_ks3);
1002 #endif
1003 #ifndef OPENSSL_NO_IDEA
1004 	idea_set_encrypt_key(key16, &idea_ks);
1005 #endif
1006 #ifndef OPENSSL_NO_RC4
1007 	RC4_set_key(&rc4_ks, 16, key16);
1008 #endif
1009 #ifndef OPENSSL_NO_RC2
1010 	RC2_set_key(&rc2_ks, 16, key16, 128);
1011 #endif
1012 #ifndef OPENSSL_NO_BF
1013 	BF_set_key(&bf_ks, 16, key16);
1014 #endif
1015 #ifndef OPENSSL_NO_CAST
1016 	CAST_set_key(&cast_ks, 16, key16);
1017 #endif
1018 	memset(rsa_c, 0, sizeof(rsa_c));
1019 #define COND(c)	(run && count<0x7fffffff)
1020 #define COUNT(d) (count)
1021 	signal(SIGALRM, sig_done);
1022 
1023 #ifndef OPENSSL_NO_MD4
1024 	if (doit[D_MD4]) {
1025 		for (j = 0; j < SIZE_NUM; j++) {
1026 			print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1027 			Time_F(START);
1028 			for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1029 				EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md4[0]), NULL, EVP_md4(), NULL);
1030 			d = Time_F(STOP);
1031 			print_result(D_MD4, j, count, d);
1032 		}
1033 	}
1034 #endif
1035 
1036 #ifndef OPENSSL_NO_MD5
1037 	if (doit[D_MD5]) {
1038 		for (j = 0; j < SIZE_NUM; j++) {
1039 			print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1040 			Time_F(START);
1041 			for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1042 				EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md5[0]), NULL, EVP_get_digestbyname("md5"), NULL);
1043 			d = Time_F(STOP);
1044 			print_result(D_MD5, j, count, d);
1045 		}
1046 	}
1047 #endif
1048 
1049 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1050 	if (doit[D_HMAC]) {
1051 		HMAC_CTX hctx;
1052 
1053 		HMAC_CTX_init(&hctx);
1054 		HMAC_Init_ex(&hctx, (unsigned char *) "This is a key...",
1055 		    16, EVP_md5(), NULL);
1056 
1057 		for (j = 0; j < SIZE_NUM; j++) {
1058 			print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1059 			Time_F(START);
1060 			for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1061 				HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1062 				HMAC_Update(&hctx, buf, lengths[j]);
1063 				HMAC_Final(&hctx, &(hmac[0]), NULL);
1064 			}
1065 			d = Time_F(STOP);
1066 			print_result(D_HMAC, j, count, d);
1067 		}
1068 		HMAC_CTX_cleanup(&hctx);
1069 	}
1070 #endif
1071 #ifndef OPENSSL_NO_SHA
1072 	if (doit[D_SHA1]) {
1073 		for (j = 0; j < SIZE_NUM; j++) {
1074 			print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1075 			Time_F(START);
1076 			for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1077 				EVP_Digest(buf, (unsigned long) lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL);
1078 			d = Time_F(STOP);
1079 			print_result(D_SHA1, j, count, d);
1080 		}
1081 	}
1082 #ifndef OPENSSL_NO_SHA256
1083 	if (doit[D_SHA256]) {
1084 		for (j = 0; j < SIZE_NUM; j++) {
1085 			print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1086 			Time_F(START);
1087 			for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1088 				SHA256(buf, lengths[j], sha256);
1089 			d = Time_F(STOP);
1090 			print_result(D_SHA256, j, count, d);
1091 		}
1092 	}
1093 #endif
1094 
1095 #ifndef OPENSSL_NO_SHA512
1096 	if (doit[D_SHA512]) {
1097 		for (j = 0; j < SIZE_NUM; j++) {
1098 			print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1099 			Time_F(START);
1100 			for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1101 				SHA512(buf, lengths[j], sha512);
1102 			d = Time_F(STOP);
1103 			print_result(D_SHA512, j, count, d);
1104 		}
1105 	}
1106 #endif
1107 #endif
1108 
1109 #ifndef OPENSSL_NO_WHIRLPOOL
1110 	if (doit[D_WHIRLPOOL]) {
1111 		for (j = 0; j < SIZE_NUM; j++) {
1112 			print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1113 			Time_F(START);
1114 			for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1115 				WHIRLPOOL(buf, lengths[j], whirlpool);
1116 			d = Time_F(STOP);
1117 			print_result(D_WHIRLPOOL, j, count, d);
1118 		}
1119 	}
1120 #endif
1121 
1122 #ifndef OPENSSL_NO_RIPEMD
1123 	if (doit[D_RMD160]) {
1124 		for (j = 0; j < SIZE_NUM; j++) {
1125 			print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1126 			Time_F(START);
1127 			for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1128 				EVP_Digest(buf, (unsigned long) lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL);
1129 			d = Time_F(STOP);
1130 			print_result(D_RMD160, j, count, d);
1131 		}
1132 	}
1133 #endif
1134 #ifndef OPENSSL_NO_RC4
1135 	if (doit[D_RC4]) {
1136 		for (j = 0; j < SIZE_NUM; j++) {
1137 			print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1138 			Time_F(START);
1139 			for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1140 				RC4(&rc4_ks, (unsigned int) lengths[j],
1141 				    buf, buf);
1142 			d = Time_F(STOP);
1143 			print_result(D_RC4, j, count, d);
1144 		}
1145 	}
1146 #endif
1147 #ifndef OPENSSL_NO_DES
1148 	if (doit[D_CBC_DES]) {
1149 		for (j = 0; j < SIZE_NUM; j++) {
1150 			print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1151 			Time_F(START);
1152 			for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1153 				DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1154 				    &DES_iv, DES_ENCRYPT);
1155 			d = Time_F(STOP);
1156 			print_result(D_CBC_DES, j, count, d);
1157 		}
1158 	}
1159 	if (doit[D_EDE3_DES]) {
1160 		for (j = 0; j < SIZE_NUM; j++) {
1161 			print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1162 			Time_F(START);
1163 			for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1164 				DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1165 				    &sch, &sch2, &sch3,
1166 				    &DES_iv, DES_ENCRYPT);
1167 			d = Time_F(STOP);
1168 			print_result(D_EDE3_DES, j, count, d);
1169 		}
1170 	}
1171 #endif
1172 #ifndef OPENSSL_NO_AES
1173 	if (doit[D_CBC_128_AES]) {
1174 		for (j = 0; j < SIZE_NUM; j++) {
1175 			print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]);
1176 			Time_F(START);
1177 			for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1178 				AES_cbc_encrypt(buf, buf,
1179 				    (unsigned long) lengths[j], &aes_ks1,
1180 				    iv, AES_ENCRYPT);
1181 			d = Time_F(STOP);
1182 			print_result(D_CBC_128_AES, j, count, d);
1183 		}
1184 	}
1185 	if (doit[D_CBC_192_AES]) {
1186 		for (j = 0; j < SIZE_NUM; j++) {
1187 			print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]);
1188 			Time_F(START);
1189 			for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1190 				AES_cbc_encrypt(buf, buf,
1191 				    (unsigned long) lengths[j], &aes_ks2,
1192 				    iv, AES_ENCRYPT);
1193 			d = Time_F(STOP);
1194 			print_result(D_CBC_192_AES, j, count, d);
1195 		}
1196 	}
1197 	if (doit[D_CBC_256_AES]) {
1198 		for (j = 0; j < SIZE_NUM; j++) {
1199 			print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]);
1200 			Time_F(START);
1201 			for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1202 				AES_cbc_encrypt(buf, buf,
1203 				    (unsigned long) lengths[j], &aes_ks3,
1204 				    iv, AES_ENCRYPT);
1205 			d = Time_F(STOP);
1206 			print_result(D_CBC_256_AES, j, count, d);
1207 		}
1208 	}
1209 	if (doit[D_IGE_128_AES]) {
1210 		for (j = 0; j < SIZE_NUM; j++) {
1211 			print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]);
1212 			Time_F(START);
1213 			for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1214 				AES_ige_encrypt(buf, buf2,
1215 				    (unsigned long) lengths[j], &aes_ks1,
1216 				    iv, AES_ENCRYPT);
1217 			d = Time_F(STOP);
1218 			print_result(D_IGE_128_AES, j, count, d);
1219 		}
1220 	}
1221 	if (doit[D_IGE_192_AES]) {
1222 		for (j = 0; j < SIZE_NUM; j++) {
1223 			print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]);
1224 			Time_F(START);
1225 			for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1226 				AES_ige_encrypt(buf, buf2,
1227 				    (unsigned long) lengths[j], &aes_ks2,
1228 				    iv, AES_ENCRYPT);
1229 			d = Time_F(STOP);
1230 			print_result(D_IGE_192_AES, j, count, d);
1231 		}
1232 	}
1233 	if (doit[D_IGE_256_AES]) {
1234 		for (j = 0; j < SIZE_NUM; j++) {
1235 			print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]);
1236 			Time_F(START);
1237 			for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1238 				AES_ige_encrypt(buf, buf2,
1239 				    (unsigned long) lengths[j], &aes_ks3,
1240 				    iv, AES_ENCRYPT);
1241 			d = Time_F(STOP);
1242 			print_result(D_IGE_256_AES, j, count, d);
1243 		}
1244 	}
1245 	if (doit[D_GHASH]) {
1246 		GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1247 		CRYPTO_gcm128_setiv(ctx, (unsigned char *) "0123456789ab", 12);
1248 
1249 		for (j = 0; j < SIZE_NUM; j++) {
1250 			print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1251 			Time_F(START);
1252 			for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1253 				CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1254 			d = Time_F(STOP);
1255 			print_result(D_GHASH, j, count, d);
1256 		}
1257 		CRYPTO_gcm128_release(ctx);
1258 	}
1259 	if (doit[D_AES_128_GCM]) {
1260 		const EVP_AEAD *aead = EVP_aead_aes_128_gcm();
1261 		static const unsigned char nonce[32] = {0};
1262 		size_t buf_len, nonce_len;
1263 		EVP_AEAD_CTX ctx;
1264 
1265 		EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1266 		    EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1267 		nonce_len = EVP_AEAD_nonce_length(aead);
1268 
1269 		for (j = 0; j < SIZE_NUM; j++) {
1270 			print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
1271 			Time_F(START);
1272 			for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++)
1273 				EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1274 				    nonce_len, buf, lengths[j], NULL, 0);
1275 			d=Time_F(STOP);
1276 			print_result(D_AES_128_GCM,j,count,d);
1277 		}
1278 		EVP_AEAD_CTX_cleanup(&ctx);
1279 	}
1280 
1281 	if (doit[D_AES_256_GCM]) {
1282 		const EVP_AEAD *aead = EVP_aead_aes_256_gcm();
1283 		static const unsigned char nonce[32] = {0};
1284 		size_t buf_len, nonce_len;
1285 		EVP_AEAD_CTX ctx;
1286 
1287 		EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1288 		EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1289 		nonce_len = EVP_AEAD_nonce_length(aead);
1290 
1291 		for (j = 0; j < SIZE_NUM; j++) {
1292 			print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
1293 			Time_F(START);
1294 			for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++)
1295 				EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1296 				    nonce_len, buf, lengths[j], NULL, 0);
1297 			d=Time_F(STOP);
1298 			print_result(D_AES_256_GCM, j, count, d);
1299 		}
1300 		EVP_AEAD_CTX_cleanup(&ctx);
1301 	}
1302 #endif
1303 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1304 	if (doit[D_CHACHA20_POLY1305]) {
1305 		const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
1306 		static const unsigned char nonce[32] = {0};
1307 		size_t buf_len, nonce_len;
1308 		EVP_AEAD_CTX ctx;
1309 
1310 		EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1311 		    EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1312 		nonce_len = EVP_AEAD_nonce_length(aead);
1313 
1314 		for (j = 0; j < SIZE_NUM; j++) {
1315 			print_message(names[D_CHACHA20_POLY1305],
1316 			    c[D_CHACHA20_POLY1305][j], lengths[j]);
1317 			Time_F(START);
1318 			for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++)
1319 				EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1320 				    nonce_len, buf, lengths[j], NULL, 0);
1321 			d=Time_F(STOP);
1322 			print_result(D_CHACHA20_POLY1305, j, count, d);
1323 		}
1324 		EVP_AEAD_CTX_cleanup(&ctx);
1325 	}
1326 #endif
1327 #ifndef OPENSSL_NO_CAMELLIA
1328 	if (doit[D_CBC_128_CML]) {
1329 		for (j = 0; j < SIZE_NUM; j++) {
1330 			print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]);
1331 			Time_F(START);
1332 			for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1333 				Camellia_cbc_encrypt(buf, buf,
1334 				    (unsigned long) lengths[j], &camellia_ks1,
1335 				    iv, CAMELLIA_ENCRYPT);
1336 			d = Time_F(STOP);
1337 			print_result(D_CBC_128_CML, j, count, d);
1338 		}
1339 	}
1340 	if (doit[D_CBC_192_CML]) {
1341 		for (j = 0; j < SIZE_NUM; j++) {
1342 			print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]);
1343 			Time_F(START);
1344 			for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1345 				Camellia_cbc_encrypt(buf, buf,
1346 				    (unsigned long) lengths[j], &camellia_ks2,
1347 				    iv, CAMELLIA_ENCRYPT);
1348 			d = Time_F(STOP);
1349 			print_result(D_CBC_192_CML, j, count, d);
1350 		}
1351 	}
1352 	if (doit[D_CBC_256_CML]) {
1353 		for (j = 0; j < SIZE_NUM; j++) {
1354 			print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]);
1355 			Time_F(START);
1356 			for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1357 				Camellia_cbc_encrypt(buf, buf,
1358 				    (unsigned long) lengths[j], &camellia_ks3,
1359 				    iv, CAMELLIA_ENCRYPT);
1360 			d = Time_F(STOP);
1361 			print_result(D_CBC_256_CML, j, count, d);
1362 		}
1363 	}
1364 #endif
1365 #ifndef OPENSSL_NO_IDEA
1366 	if (doit[D_CBC_IDEA]) {
1367 		for (j = 0; j < SIZE_NUM; j++) {
1368 			print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1369 			Time_F(START);
1370 			for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1371 				idea_cbc_encrypt(buf, buf,
1372 				    (unsigned long) lengths[j], &idea_ks,
1373 				    iv, IDEA_ENCRYPT);
1374 			d = Time_F(STOP);
1375 			print_result(D_CBC_IDEA, j, count, d);
1376 		}
1377 	}
1378 #endif
1379 #ifndef OPENSSL_NO_RC2
1380 	if (doit[D_CBC_RC2]) {
1381 		for (j = 0; j < SIZE_NUM; j++) {
1382 			print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1383 			Time_F(START);
1384 			for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1385 				RC2_cbc_encrypt(buf, buf,
1386 				    (unsigned long) lengths[j], &rc2_ks,
1387 				    iv, RC2_ENCRYPT);
1388 			d = Time_F(STOP);
1389 			print_result(D_CBC_RC2, j, count, d);
1390 		}
1391 	}
1392 #endif
1393 #ifndef OPENSSL_NO_BF
1394 	if (doit[D_CBC_BF]) {
1395 		for (j = 0; j < SIZE_NUM; j++) {
1396 			print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1397 			Time_F(START);
1398 			for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1399 				BF_cbc_encrypt(buf, buf,
1400 				    (unsigned long) lengths[j], &bf_ks,
1401 				    iv, BF_ENCRYPT);
1402 			d = Time_F(STOP);
1403 			print_result(D_CBC_BF, j, count, d);
1404 		}
1405 	}
1406 #endif
1407 #ifndef OPENSSL_NO_CAST
1408 	if (doit[D_CBC_CAST]) {
1409 		for (j = 0; j < SIZE_NUM; j++) {
1410 			print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1411 			Time_F(START);
1412 			for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1413 				CAST_cbc_encrypt(buf, buf,
1414 				    (unsigned long) lengths[j], &cast_ks,
1415 				    iv, CAST_ENCRYPT);
1416 			d = Time_F(STOP);
1417 			print_result(D_CBC_CAST, j, count, d);
1418 		}
1419 	}
1420 #endif
1421 
1422 	if (doit[D_EVP]) {
1423 		for (j = 0; j < SIZE_NUM; j++) {
1424 			if (evp_cipher) {
1425 				EVP_CIPHER_CTX ctx;
1426 				int outl;
1427 
1428 				names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1429 				/*
1430 				 * -O3 -fschedule-insns messes up an
1431 				 * optimization here!  names[D_EVP] somehow
1432 				 * becomes NULL
1433 				 */
1434 				print_message(names[D_EVP], save_count,
1435 				    lengths[j]);
1436 
1437 				EVP_CIPHER_CTX_init(&ctx);
1438 				if (decrypt)
1439 					EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1440 				else
1441 					EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1442 				EVP_CIPHER_CTX_set_padding(&ctx, 0);
1443 
1444 				Time_F(START);
1445 				if (decrypt)
1446 					for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1447 						EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1448 				else
1449 					for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1450 						EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1451 				if (decrypt)
1452 					EVP_DecryptFinal_ex(&ctx, buf, &outl);
1453 				else
1454 					EVP_EncryptFinal_ex(&ctx, buf, &outl);
1455 				d = Time_F(STOP);
1456 				EVP_CIPHER_CTX_cleanup(&ctx);
1457 			}
1458 			if (evp_md) {
1459 				names[D_EVP] = OBJ_nid2ln(evp_md->type);
1460 				print_message(names[D_EVP], save_count,
1461 				    lengths[j]);
1462 
1463 				Time_F(START);
1464 				for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1465 					EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1466 
1467 				d = Time_F(STOP);
1468 			}
1469 			print_result(D_EVP, j, count, d);
1470 		}
1471 	}
1472 	arc4random_buf(buf, 36);
1473 	for (j = 0; j < RSA_NUM; j++) {
1474 		int ret;
1475 		if (!rsa_doit[j])
1476 			continue;
1477 		ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1478 		if (ret == 0) {
1479 			BIO_printf(bio_err, "RSA sign failure.  No RSA sign will be done.\n");
1480 			ERR_print_errors(bio_err);
1481 			rsa_count = 1;
1482 		} else {
1483 			pkey_print_message("private", "rsa",
1484 			    rsa_c[j][0], rsa_bits[j],
1485 			    RSA_SECONDS);
1486 /*			RSA_blinding_on(rsa_key[j],NULL); */
1487 			Time_F(START);
1488 			for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1489 				ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1490 				    &rsa_num, rsa_key[j]);
1491 				if (ret == 0) {
1492 					BIO_printf(bio_err,
1493 					    "RSA sign failure\n");
1494 					ERR_print_errors(bio_err);
1495 					count = 1;
1496 					break;
1497 				}
1498 			}
1499 			d = Time_F(STOP);
1500 			BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
1501 			    : "%ld %d bit private RSA's in %.2fs\n",
1502 			    count, rsa_bits[j], d);
1503 			rsa_results[j][0] = d / (double) count;
1504 			rsa_count = count;
1505 		}
1506 
1507 		ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1508 		if (ret <= 0) {
1509 			BIO_printf(bio_err, "RSA verify failure.  No RSA verify will be done.\n");
1510 			ERR_print_errors(bio_err);
1511 			rsa_doit[j] = 0;
1512 		} else {
1513 			pkey_print_message("public", "rsa",
1514 			    rsa_c[j][1], rsa_bits[j],
1515 			    RSA_SECONDS);
1516 			Time_F(START);
1517 			for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1518 				ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1519 				    rsa_num, rsa_key[j]);
1520 				if (ret <= 0) {
1521 					BIO_printf(bio_err,
1522 					    "RSA verify failure\n");
1523 					ERR_print_errors(bio_err);
1524 					count = 1;
1525 					break;
1526 				}
1527 			}
1528 			d = Time_F(STOP);
1529 			BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
1530 			    : "%ld %d bit public RSA's in %.2fs\n",
1531 			    count, rsa_bits[j], d);
1532 			rsa_results[j][1] = d / (double) count;
1533 		}
1534 
1535 		if (rsa_count <= 1) {
1536 			/* if longer than 10s, don't do any more */
1537 			for (j++; j < RSA_NUM; j++)
1538 				rsa_doit[j] = 0;
1539 		}
1540 	}
1541 
1542 	arc4random_buf(buf, 20);
1543 	for (j = 0; j < DSA_NUM; j++) {
1544 		unsigned int kk;
1545 		int ret;
1546 
1547 		if (!dsa_doit[j])
1548 			continue;
1549 /*		DSA_generate_key(dsa_key[j]); */
1550 /*		DSA_sign_setup(dsa_key[j],NULL); */
1551 		ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1552 		    &kk, dsa_key[j]);
1553 		if (ret == 0) {
1554 			BIO_printf(bio_err, "DSA sign failure.  No DSA sign will be done.\n");
1555 			ERR_print_errors(bio_err);
1556 			rsa_count = 1;
1557 		} else {
1558 			pkey_print_message("sign", "dsa",
1559 			    dsa_c[j][0], dsa_bits[j],
1560 			    DSA_SECONDS);
1561 			Time_F(START);
1562 			for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1563 				ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1564 				    &kk, dsa_key[j]);
1565 				if (ret == 0) {
1566 					BIO_printf(bio_err,
1567 					    "DSA sign failure\n");
1568 					ERR_print_errors(bio_err);
1569 					count = 1;
1570 					break;
1571 				}
1572 			}
1573 			d = Time_F(STOP);
1574 			BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n"
1575 			    : "%ld %d bit DSA signs in %.2fs\n",
1576 			    count, dsa_bits[j], d);
1577 			dsa_results[j][0] = d / (double) count;
1578 			rsa_count = count;
1579 		}
1580 
1581 		ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1582 		    kk, dsa_key[j]);
1583 		if (ret <= 0) {
1584 			BIO_printf(bio_err, "DSA verify failure.  No DSA verify will be done.\n");
1585 			ERR_print_errors(bio_err);
1586 			dsa_doit[j] = 0;
1587 		} else {
1588 			pkey_print_message("verify", "dsa",
1589 			    dsa_c[j][1], dsa_bits[j],
1590 			    DSA_SECONDS);
1591 			Time_F(START);
1592 			for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1593 				ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1594 				    kk, dsa_key[j]);
1595 				if (ret <= 0) {
1596 					BIO_printf(bio_err,
1597 					    "DSA verify failure\n");
1598 					ERR_print_errors(bio_err);
1599 					count = 1;
1600 					break;
1601 				}
1602 			}
1603 			d = Time_F(STOP);
1604 			BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n"
1605 			    : "%ld %d bit DSA verify in %.2fs\n",
1606 			    count, dsa_bits[j], d);
1607 			dsa_results[j][1] = d / (double) count;
1608 		}
1609 
1610 		if (rsa_count <= 1) {
1611 			/* if longer than 10s, don't do any more */
1612 			for (j++; j < DSA_NUM; j++)
1613 				dsa_doit[j] = 0;
1614 		}
1615 	}
1616 
1617 	for (j = 0; j < EC_NUM; j++) {
1618 		int ret;
1619 
1620 		if (!ecdsa_doit[j])
1621 			continue;	/* Ignore Curve */
1622 		ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1623 		if (ecdsa[j] == NULL) {
1624 			BIO_printf(bio_err, "ECDSA failure.\n");
1625 			ERR_print_errors(bio_err);
1626 			rsa_count = 1;
1627 		} else {
1628 			EC_KEY_precompute_mult(ecdsa[j], NULL);
1629 
1630 			/* Perform ECDSA signature test */
1631 			EC_KEY_generate_key(ecdsa[j]);
1632 			ret = ECDSA_sign(0, buf, 20, ecdsasig,
1633 			    &ecdsasiglen, ecdsa[j]);
1634 			if (ret == 0) {
1635 				BIO_printf(bio_err, "ECDSA sign failure.  No ECDSA sign will be done.\n");
1636 				ERR_print_errors(bio_err);
1637 				rsa_count = 1;
1638 			} else {
1639 				pkey_print_message("sign", "ecdsa",
1640 				    ecdsa_c[j][0],
1641 				    test_curves_bits[j],
1642 				    ECDSA_SECONDS);
1643 
1644 				Time_F(START);
1645 				for (count = 0, run = 1; COND(ecdsa_c[j][0]);
1646 				    count++) {
1647 					ret = ECDSA_sign(0, buf, 20,
1648 					    ecdsasig, &ecdsasiglen,
1649 					    ecdsa[j]);
1650 					if (ret == 0) {
1651 						BIO_printf(bio_err, "ECDSA sign failure\n");
1652 						ERR_print_errors(bio_err);
1653 						count = 1;
1654 						break;
1655 					}
1656 				}
1657 				d = Time_F(STOP);
1658 
1659 				BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
1660 				    "%ld %d bit ECDSA signs in %.2fs \n",
1661 				    count, test_curves_bits[j], d);
1662 				ecdsa_results[j][0] = d / (double) count;
1663 				rsa_count = count;
1664 			}
1665 
1666 			/* Perform ECDSA verification test */
1667 			ret = ECDSA_verify(0, buf, 20, ecdsasig,
1668 			    ecdsasiglen, ecdsa[j]);
1669 			if (ret != 1) {
1670 				BIO_printf(bio_err, "ECDSA verify failure.  No ECDSA verify will be done.\n");
1671 				ERR_print_errors(bio_err);
1672 				ecdsa_doit[j] = 0;
1673 			} else {
1674 				pkey_print_message("verify", "ecdsa",
1675 				    ecdsa_c[j][1],
1676 				    test_curves_bits[j],
1677 				    ECDSA_SECONDS);
1678 				Time_F(START);
1679 				for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1680 					ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1681 					if (ret != 1) {
1682 						BIO_printf(bio_err, "ECDSA verify failure\n");
1683 						ERR_print_errors(bio_err);
1684 						count = 1;
1685 						break;
1686 					}
1687 				}
1688 				d = Time_F(STOP);
1689 				BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n"
1690 				    : "%ld %d bit ECDSA verify in %.2fs\n",
1691 				    count, test_curves_bits[j], d);
1692 				ecdsa_results[j][1] = d / (double) count;
1693 			}
1694 
1695 			if (rsa_count <= 1) {
1696 				/* if longer than 10s, don't do any more */
1697 				for (j++; j < EC_NUM; j++)
1698 					ecdsa_doit[j] = 0;
1699 			}
1700 		}
1701 	}
1702 
1703 	for (j = 0; j < EC_NUM; j++) {
1704 		if (!ecdh_doit[j])
1705 			continue;
1706 		ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1707 		ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1708 		if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1709 			BIO_printf(bio_err, "ECDH failure.\n");
1710 			ERR_print_errors(bio_err);
1711 			rsa_count = 1;
1712 		} else {
1713 			/* generate two ECDH key pairs */
1714 			if (!EC_KEY_generate_key(ecdh_a[j]) ||
1715 			    !EC_KEY_generate_key(ecdh_b[j])) {
1716 				BIO_printf(bio_err, "ECDH key generation failure.\n");
1717 				ERR_print_errors(bio_err);
1718 				rsa_count = 1;
1719 			} else {
1720 				/*
1721 				 * If field size is not more than 24 octets,
1722 				 * then use SHA-1 hash of result; otherwise,
1723 				 * use result (see section 4.8 of
1724 				 * draft-ietf-tls-ecc-03.txt).
1725 				 */
1726 				int field_size, outlen;
1727 				void *(*kdf) (const void *in, size_t inlen, void *out, size_t * xoutlen);
1728 				field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1729 				if (field_size <= 24 * 8) {
1730 					outlen = KDF1_SHA1_len;
1731 					kdf = KDF1_SHA1;
1732 				} else {
1733 					outlen = (field_size + 7) / 8;
1734 					kdf = NULL;
1735 				}
1736 				secret_size_a = ECDH_compute_key(secret_a, outlen,
1737 				    EC_KEY_get0_public_key(ecdh_b[j]),
1738 				    ecdh_a[j], kdf);
1739 				secret_size_b = ECDH_compute_key(secret_b, outlen,
1740 				    EC_KEY_get0_public_key(ecdh_a[j]),
1741 				    ecdh_b[j], kdf);
1742 				if (secret_size_a != secret_size_b)
1743 					ecdh_checks = 0;
1744 				else
1745 					ecdh_checks = 1;
1746 
1747 				for (secret_idx = 0;
1748 				    (secret_idx < secret_size_a)
1749 				    && (ecdh_checks == 1);
1750 				    secret_idx++) {
1751 					if (secret_a[secret_idx] != secret_b[secret_idx])
1752 						ecdh_checks = 0;
1753 				}
1754 
1755 				if (ecdh_checks == 0) {
1756 					BIO_printf(bio_err,
1757 					    "ECDH computations don't match.\n");
1758 					ERR_print_errors(bio_err);
1759 					rsa_count = 1;
1760 				} else {
1761 					pkey_print_message("", "ecdh",
1762 					    ecdh_c[j][0],
1763 					    test_curves_bits[j],
1764 					    ECDH_SECONDS);
1765 					Time_F(START);
1766 					for (count = 0, run = 1;
1767 					     COND(ecdh_c[j][0]); count++) {
1768 						ECDH_compute_key(secret_a,
1769 						    outlen,
1770 						    EC_KEY_get0_public_key(ecdh_b[j]),
1771 						    ecdh_a[j], kdf);
1772 					}
1773 					d = Time_F(STOP);
1774 					BIO_printf(bio_err, mr
1775 					    ? "+R7:%ld:%d:%.2f\n"
1776 					    : "%ld %d-bit ECDH ops in %.2fs\n",
1777 					    count, test_curves_bits[j], d);
1778 					ecdh_results[j][0] = d / (double) count;
1779 					rsa_count = count;
1780 				}
1781 			}
1782 		}
1783 
1784 
1785 		if (rsa_count <= 1) {
1786 			/* if longer than 10s, don't do any more */
1787 			for (j++; j < EC_NUM; j++)
1788 				ecdh_doit[j] = 0;
1789 		}
1790 	}
1791 #ifndef _WIN32
1792 show_res:
1793 #endif
1794 	if (!mr) {
1795 		fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
1796 		fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
1797 		printf("options:");
1798 		printf("%s ", BN_options());
1799 #ifndef OPENSSL_NO_RC4
1800 		printf("%s ", RC4_options());
1801 #endif
1802 #ifndef OPENSSL_NO_DES
1803 		printf("%s ", DES_options());
1804 #endif
1805 #ifndef OPENSSL_NO_AES
1806 		printf("%s ", AES_options());
1807 #endif
1808 #ifndef OPENSSL_NO_IDEA
1809 		printf("%s ", idea_options());
1810 #endif
1811 #ifndef OPENSSL_NO_BF
1812 		printf("%s ", BF_options());
1813 #endif
1814 		fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
1815 	}
1816 	if (pr_header) {
1817 		if (mr)
1818 			fprintf(stdout, "+H");
1819 		else {
1820 			fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n");
1821 			fprintf(stdout, "type        ");
1822 		}
1823 		for (j = 0; j < SIZE_NUM; j++)
1824 			fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
1825 		fprintf(stdout, "\n");
1826 	}
1827 	for (k = 0; k < ALGOR_NUM; k++) {
1828 		if (!doit[k])
1829 			continue;
1830 		if (mr)
1831 			fprintf(stdout, "+F:%d:%s", k, names[k]);
1832 		else
1833 			fprintf(stdout, "%-13s", names[k]);
1834 		for (j = 0; j < SIZE_NUM; j++) {
1835 			if (results[k][j] > 10000 && !mr)
1836 				fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
1837 			else
1838 				fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
1839 		}
1840 		fprintf(stdout, "\n");
1841 	}
1842 	j = 1;
1843 	for (k = 0; k < RSA_NUM; k++) {
1844 		if (!rsa_doit[k])
1845 			continue;
1846 		if (j && !mr) {
1847 			printf("%18ssign    verify    sign/s verify/s\n", " ");
1848 			j = 0;
1849 		}
1850 		if (mr)
1851 			fprintf(stdout, "+F2:%u:%u:%f:%f\n",
1852 			    k, rsa_bits[k], rsa_results[k][0],
1853 			    rsa_results[k][1]);
1854 		else
1855 			fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1856 			    rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1857 			    1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
1858 	}
1859 	j = 1;
1860 	for (k = 0; k < DSA_NUM; k++) {
1861 		if (!dsa_doit[k])
1862 			continue;
1863 		if (j && !mr) {
1864 			printf("%18ssign    verify    sign/s verify/s\n", " ");
1865 			j = 0;
1866 		}
1867 		if (mr)
1868 			fprintf(stdout, "+F3:%u:%u:%f:%f\n",
1869 			    k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
1870 		else
1871 			fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1872 			    dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1873 			    1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
1874 	}
1875 	j = 1;
1876 	for (k = 0; k < EC_NUM; k++) {
1877 		if (!ecdsa_doit[k])
1878 			continue;
1879 		if (j && !mr) {
1880 			printf("%30ssign    verify    sign/s verify/s\n", " ");
1881 			j = 0;
1882 		}
1883 		if (mr)
1884 			fprintf(stdout, "+F4:%u:%u:%f:%f\n",
1885 			    k, test_curves_bits[k],
1886 			    ecdsa_results[k][0], ecdsa_results[k][1]);
1887 		else
1888 			fprintf(stdout,
1889 			    "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
1890 			    test_curves_bits[k],
1891 			    test_curves_names[k],
1892 			    ecdsa_results[k][0], ecdsa_results[k][1],
1893 			    1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
1894 	}
1895 
1896 
1897 	j = 1;
1898 	for (k = 0; k < EC_NUM; k++) {
1899 		if (!ecdh_doit[k])
1900 			continue;
1901 		if (j && !mr) {
1902 			printf("%30sop      op/s\n", " ");
1903 			j = 0;
1904 		}
1905 		if (mr)
1906 			fprintf(stdout, "+F5:%u:%u:%f:%f\n",
1907 			    k, test_curves_bits[k],
1908 			    ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1909 
1910 		else
1911 			fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
1912 			    test_curves_bits[k],
1913 			    test_curves_names[k],
1914 			    ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1915 	}
1916 
1917 	mret = 0;
1918 
1919  end:
1920 	ERR_print_errors(bio_err);
1921 	free(buf);
1922 	free(buf2);
1923 	for (i = 0; i < RSA_NUM; i++)
1924 		if (rsa_key[i] != NULL)
1925 			RSA_free(rsa_key[i]);
1926 	for (i = 0; i < DSA_NUM; i++)
1927 		if (dsa_key[i] != NULL)
1928 			DSA_free(dsa_key[i]);
1929 
1930 	for (i = 0; i < EC_NUM; i++)
1931 		if (ecdsa[i] != NULL)
1932 			EC_KEY_free(ecdsa[i]);
1933 	for (i = 0; i < EC_NUM; i++) {
1934 		if (ecdh_a[i] != NULL)
1935 			EC_KEY_free(ecdh_a[i]);
1936 		if (ecdh_b[i] != NULL)
1937 			EC_KEY_free(ecdh_b[i]);
1938 	}
1939 
1940 
1941 	return (mret);
1942 }
1943 
1944 static void
1945 print_message(const char *s, long num, int length)
1946 {
1947 	BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
1948 	    : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
1949 	(void) BIO_flush(bio_err);
1950 	alarm(SECONDS);
1951 }
1952 
1953 static void
1954 pkey_print_message(const char *str, const char *str2, long num,
1955     int bits, int tm)
1956 {
1957 	BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n"
1958 	    : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
1959 	(void) BIO_flush(bio_err);
1960 	alarm(tm);
1961 }
1962 
1963 static void
1964 print_result(int alg, int run_no, int count, double time_used)
1965 {
1966 #ifdef _WIN32
1967 	speed_alarm_free(run);
1968 #endif
1969 	BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
1970 	    : "%d %s's in %.2fs\n", count, names[alg], time_used);
1971 	results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
1972 }
1973 
1974 #ifndef _WIN32
1975 static char *
1976 sstrsep(char **string, const char *delim)
1977 {
1978 	char isdelim[256];
1979 	char *token = *string;
1980 
1981 	if (**string == 0)
1982 		return NULL;
1983 
1984 	memset(isdelim, 0, sizeof isdelim);
1985 	isdelim[0] = 1;
1986 
1987 	while (*delim) {
1988 		isdelim[(unsigned char) (*delim)] = 1;
1989 		delim++;
1990 	}
1991 
1992 	while (!isdelim[(unsigned char) (**string)]) {
1993 		(*string)++;
1994 	}
1995 
1996 	if (**string) {
1997 		**string = 0;
1998 		(*string)++;
1999 	}
2000 	return token;
2001 }
2002 
2003 static int
2004 do_multi(int multi)
2005 {
2006 	int n;
2007 	int fd[2];
2008 	int *fds;
2009 	static char sep[] = ":";
2010 	const char *errstr = NULL;
2011 
2012 	fds = reallocarray(NULL, multi, sizeof *fds);
2013 	if (fds == NULL) {
2014 		fprintf(stderr, "reallocarray failure\n");
2015 		exit(1);
2016 	}
2017 	for (n = 0; n < multi; ++n) {
2018 		if (pipe(fd) == -1) {
2019 			fprintf(stderr, "pipe failure\n");
2020 			exit(1);
2021 		}
2022 		fflush(stdout);
2023 		fflush(stderr);
2024 		if (fork()) {
2025 			close(fd[1]);
2026 			fds[n] = fd[0];
2027 		} else {
2028 			close(fd[0]);
2029 			close(1);
2030 			if (dup(fd[1]) == -1) {
2031 				fprintf(stderr, "dup failed\n");
2032 				exit(1);
2033 			}
2034 			close(fd[1]);
2035 			mr = 1;
2036 			usertime = 0;
2037 			free(fds);
2038 			return 0;
2039 		}
2040 		printf("Forked child %d\n", n);
2041 	}
2042 
2043 	/* for now, assume the pipe is long enough to take all the output */
2044 	for (n = 0; n < multi; ++n) {
2045 		FILE *f;
2046 		char buf[1024];
2047 		char *p;
2048 
2049 		f = fdopen(fds[n], "r");
2050 		while (fgets(buf, sizeof buf, f)) {
2051 			p = strchr(buf, '\n');
2052 			if (p)
2053 				*p = '\0';
2054 			if (buf[0] != '+') {
2055 				fprintf(stderr, "Don't understand line '%s' from child %d\n",
2056 				    buf, n);
2057 				continue;
2058 			}
2059 			printf("Got: %s from %d\n", buf, n);
2060 			if (!strncmp(buf, "+F:", 3)) {
2061 				int alg;
2062 				int j;
2063 
2064 				p = buf + 3;
2065 				alg = strtonum(sstrsep(&p, sep),
2066 				    0, ALGOR_NUM - 1, &errstr);
2067 				sstrsep(&p, sep);
2068 				for (j = 0; j < SIZE_NUM; ++j)
2069 					results[alg][j] += atof(sstrsep(&p, sep));
2070 			} else if (!strncmp(buf, "+F2:", 4)) {
2071 				int k;
2072 				double d;
2073 
2074 				p = buf + 4;
2075 				k = strtonum(sstrsep(&p, sep),
2076 				    0, ALGOR_NUM - 1, &errstr);
2077 				sstrsep(&p, sep);
2078 
2079 				d = atof(sstrsep(&p, sep));
2080 				if (n)
2081 					rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2082 				else
2083 					rsa_results[k][0] = d;
2084 
2085 				d = atof(sstrsep(&p, sep));
2086 				if (n)
2087 					rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2088 				else
2089 					rsa_results[k][1] = d;
2090 			} else if (!strncmp(buf, "+F2:", 4)) {
2091 				int k;
2092 				double d;
2093 
2094 				p = buf + 4;
2095 				k = strtonum(sstrsep(&p, sep),
2096 				    0, ALGOR_NUM - 1, &errstr);
2097 				sstrsep(&p, sep);
2098 
2099 				d = atof(sstrsep(&p, sep));
2100 				if (n)
2101 					rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2102 				else
2103 					rsa_results[k][0] = d;
2104 
2105 				d = atof(sstrsep(&p, sep));
2106 				if (n)
2107 					rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2108 				else
2109 					rsa_results[k][1] = d;
2110 			}
2111 			else if (!strncmp(buf, "+F3:", 4)) {
2112 				int k;
2113 				double d;
2114 
2115 				p = buf + 4;
2116 				k = strtonum(sstrsep(&p, sep),
2117 				    0, ALGOR_NUM - 1, &errstr);
2118 				sstrsep(&p, sep);
2119 
2120 				d = atof(sstrsep(&p, sep));
2121 				if (n)
2122 					dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2123 				else
2124 					dsa_results[k][0] = d;
2125 
2126 				d = atof(sstrsep(&p, sep));
2127 				if (n)
2128 					dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2129 				else
2130 					dsa_results[k][1] = d;
2131 			}
2132 			else if (!strncmp(buf, "+F4:", 4)) {
2133 				int k;
2134 				double d;
2135 
2136 				p = buf + 4;
2137 				k = strtonum(sstrsep(&p, sep),
2138 				    0, ALGOR_NUM - 1, &errstr);
2139 				sstrsep(&p, sep);
2140 
2141 				d = atof(sstrsep(&p, sep));
2142 				if (n)
2143 					ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
2144 				else
2145 					ecdsa_results[k][0] = d;
2146 
2147 				d = atof(sstrsep(&p, sep));
2148 				if (n)
2149 					ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
2150 				else
2151 					ecdsa_results[k][1] = d;
2152 			}
2153 
2154 			else if (!strncmp(buf, "+F5:", 4)) {
2155 				int k;
2156 				double d;
2157 
2158 				p = buf + 4;
2159 				k = strtonum(sstrsep(&p, sep),
2160 				    0, ALGOR_NUM - 1, &errstr);
2161 				sstrsep(&p, sep);
2162 
2163 				d = atof(sstrsep(&p, sep));
2164 				if (n)
2165 					ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2166 				else
2167 					ecdh_results[k][0] = d;
2168 
2169 			}
2170 
2171 			else if (!strncmp(buf, "+H:", 3)) {
2172 			} else
2173 				fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2174 		}
2175 
2176 		fclose(f);
2177 	}
2178 	free(fds);
2179 	return 1;
2180 }
2181 #endif
2182 #endif
2183