GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/openssl/speed.c Lines: 485 1135 42.7 %
Date: 2017-11-13 Branches: 276 667 41.4 %

Line Branch Exec Source
1
/* $OpenBSD: speed.c,v 1.20 2017/10/07 06:16:54 guenther 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
static int do_multi(int multi);
163
164
#define ALGOR_NUM	32
165
#define SIZE_NUM	5
166
#define RSA_NUM		4
167
#define DSA_NUM		3
168
169
#define EC_NUM       16
170
#define MAX_ECDH_SIZE 256
171
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",
181
};
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];
188
189
static void sig_done(int sig);
190
191
static void
192
sig_done(int sig)
193
{
194
112
	signal(SIGALRM, sig_done);
195
56
	run = 0;
196
56
}
197
198
#define START	0
199
#define STOP	1
200
201
202
static double
203
Time_F(int s)
204
{
205
224
	return app_tminterval(s, usertime);
206
}
207
208
209
static const int KDF1_SHA1_len = 20;
210
static void *
211
KDF1_SHA1(const void *in, size_t inlen, void *out, size_t * outlen)
212
{
213
#ifndef OPENSSL_NO_SHA
214
	if (*outlen < SHA_DIGEST_LENGTH)
215
		return NULL;
216
	else
217
		*outlen = SHA_DIGEST_LENGTH;
218
	return SHA1(in, inlen, out);
219
#else
220
	return NULL;
221
#endif				/* OPENSSL_NO_SHA */
222
}
223
224
int
225
speed_main(int argc, char **argv)
226
{
227
	unsigned char *buf = NULL, *buf2 = NULL;
228
	int mret = 1;
229
	long count = 0, save_count = 0;
230
	int i, j, k;
231
	long rsa_count;
232
32
	unsigned rsa_num;
233
16
	unsigned char md[EVP_MAX_MD_SIZE];
234
#ifndef OPENSSL_NO_MD4
235
16
	unsigned char md4[MD4_DIGEST_LENGTH];
236
#endif
237
#ifndef OPENSSL_NO_MD5
238
16
	unsigned char md5[MD5_DIGEST_LENGTH];
239
16
	unsigned char hmac[MD5_DIGEST_LENGTH];
240
#endif
241
#ifndef OPENSSL_NO_SHA
242
16
	unsigned char sha[SHA_DIGEST_LENGTH];
243
#ifndef OPENSSL_NO_SHA256
244
16
	unsigned char sha256[SHA256_DIGEST_LENGTH];
245
#endif
246
#ifndef OPENSSL_NO_SHA512
247
16
	unsigned char sha512[SHA512_DIGEST_LENGTH];
248
#endif
249
#endif
250
#ifndef OPENSSL_NO_WHIRLPOOL
251
16
	unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
252
#endif
253
#ifndef OPENSSL_NO_RIPEMD
254
16
	unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
255
#endif
256
#ifndef OPENSSL_NO_RC4
257
16
	RC4_KEY rc4_ks;
258
#endif
259
#ifndef OPENSSL_NO_RC2
260
16
	RC2_KEY rc2_ks;
261
#endif
262
#ifndef OPENSSL_NO_IDEA
263
16
	IDEA_KEY_SCHEDULE idea_ks;
264
#endif
265
#ifndef OPENSSL_NO_BF
266
16
	BF_KEY bf_ks;
267
#endif
268
#ifndef OPENSSL_NO_CAST
269
16
	CAST_KEY cast_ks;
270
#endif
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};
284
#endif
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};
295
#endif
296
#ifndef OPENSSL_NO_AES
297
#define MAX_BLOCK_SIZE 128
298
#else
299
#define MAX_BLOCK_SIZE 64
300
#endif
301
16
	unsigned char DES_iv[8];
302
16
	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
16
	DES_key_schedule sch;
308
16
	DES_key_schedule sch2;
309
16
	DES_key_schedule sch3;
310
#endif
311
#ifndef OPENSSL_NO_AES
312
16
	AES_KEY aes_ks1, aes_ks2, aes_ks3;
313
#endif
314
#ifndef OPENSSL_NO_CAMELLIA
315
16
	CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
316
#endif
317
#define	D_MD2		0
318
#define	D_MD4		1
319
#define	D_MD5		2
320
#define	D_HMAC		3
321
#define	D_SHA1		4
322
#define D_RMD160	5
323
#define	D_RC4		6
324
#define	D_CBC_DES	7
325
#define	D_EDE3_DES	8
326
#define	D_CBC_IDEA	9
327
#define	D_CBC_SEED	10
328
#define	D_CBC_RC2	11
329
#define	D_CBC_RC5	12
330
#define	D_CBC_BF	13
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
338
#define D_EVP		21
339
#define D_SHA256	22
340
#define D_SHA512	23
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
345
#define D_GHASH		28
346
#define D_AES_128_GCM	29
347
#define D_AES_256_GCM	30
348
#define D_CHACHA20_POLY1305	31
349
	double d = 0.0;
350
16
	long c[ALGOR_NUM][SIZE_NUM];
351
#define	R_DSA_512	0
352
#define	R_DSA_1024	1
353
#define	R_DSA_2048	2
354
#define	R_RSA_512	0
355
#define	R_RSA_1024	1
356
#define	R_RSA_2048	2
357
#define	R_RSA_4096	3
358
359
#define R_EC_P160    0
360
#define R_EC_P192    1
361
#define R_EC_P224    2
362
#define R_EC_P256    3
363
#define R_EC_P384    4
364
#define R_EC_P521    5
365
#define R_EC_K163    6
366
#define R_EC_K233    7
367
#define R_EC_K283    8
368
#define R_EC_K409    9
369
#define R_EC_K571    10
370
#define R_EC_B163    11
371
#define R_EC_B233    12
372
#define R_EC_B283    13
373
#define R_EC_B409    14
374
#define R_EC_B571    15
375
376
16
	RSA *rsa_key[RSA_NUM];
377
16
	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
16
	DSA *dsa_key[DSA_NUM];
385
16
	long dsa_c[DSA_NUM][2];
386
	static unsigned int dsa_bits[DSA_NUM] = {512, 1024, 2048};
387
#ifndef OPENSSL_NO_EC
388
	/*
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
392
	 * accordingly.
393
	 */
394
	static unsigned int test_curves[EC_NUM] =
395
	{
396
		/* Prime Curves */
397
		NID_secp160r1,
398
		NID_X9_62_prime192v1,
399
		NID_secp224r1,
400
		NID_X9_62_prime256v1,
401
		NID_secp384r1,
402
		NID_secp521r1,
403
		/* Binary Curves */
404
		NID_sect163k1,
405
		NID_sect233k1,
406
		NID_sect283k1,
407
		NID_sect409k1,
408
		NID_sect571k1,
409
		NID_sect163r2,
410
		NID_sect233r1,
411
		NID_sect283r1,
412
		NID_sect409r1,
413
		NID_sect571r1
414
	};
415
	static const char *test_curves_names[EC_NUM] =
416
	{
417
		/* Prime Curves */
418
		"secp160r1",
419
		"nistp192",
420
		"nistp224",
421
		"nistp256",
422
		"nistp384",
423
		"nistp521",
424
		/* Binary Curves */
425
		"nistk163",
426
		"nistk233",
427
		"nistk283",
428
		"nistk409",
429
		"nistk571",
430
		"nistb163",
431
		"nistb233",
432
		"nistb283",
433
		"nistb409",
434
		"nistb571"
435
	};
436
	static int test_curves_bits[EC_NUM] =
437
	{
438
		160, 192, 224, 256, 384, 521,
439
		163, 233, 283, 409, 571,
440
		163, 233, 283, 409, 571
441
	};
442
443
#endif
444
445
16
	unsigned char ecdsasig[256];
446
16
	unsigned int ecdsasiglen;
447
16
	EC_KEY *ecdsa[EC_NUM];
448
16
	long ecdsa_c[EC_NUM][2];
449
450
16
	EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
451
16
	unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
452
	int secret_size_a, secret_size_b;
453
	int ecdh_checks = 0;
454
	int secret_idx = 0;
455
16
	long ecdh_c[EC_NUM][2];
456
457
16
	int rsa_doit[RSA_NUM];
458
16
	int dsa_doit[DSA_NUM];
459
16
	int ecdsa_doit[EC_NUM];
460
16
	int ecdh_doit[EC_NUM];
461
16
	int doit[ALGOR_NUM];
462
	int pr_header = 0;
463
	const EVP_CIPHER *evp_cipher = NULL;
464
	const EVP_MD *evp_md = NULL;
465
	int decrypt = 0;
466
	int multi = 0;
467
16
	const char *errstr = NULL;
468
469
16
	if (single_execution) {
470
16
		if (pledge("stdio proc flock rpath cpath wpath", NULL) == -1) {
471
			perror("pledge");
472
			exit(1);
473
		}
474
	}
475
476
16
	usertime = -1;
477
478
16
	memset(results, 0, sizeof(results));
479
16
	memset(dsa_key, 0, sizeof(dsa_key));
480
544
	for (i = 0; i < EC_NUM; i++)
481
256
		ecdsa[i] = NULL;
482
544
	for (i = 0; i < EC_NUM; i++) {
483
256
		ecdh_a[i] = NULL;
484
256
		ecdh_b[i] = NULL;
485
	}
486
487
16
	memset(rsa_key, 0, sizeof(rsa_key));
488
160
	for (i = 0; i < RSA_NUM; i++)
489
64
		rsa_key[i] = NULL;
490
491
16
	if ((buf = malloc(BUFSIZE)) == NULL) {
492
		BIO_printf(bio_err, "out of memory\n");
493
		goto end;
494
	}
495
16
	if ((buf2 = malloc(BUFSIZE)) == NULL) {
496
		BIO_printf(bio_err, "out of memory\n");
497
		goto end;
498
	}
499
16
	memset(c, 0, sizeof(c));
500
16
	memset(DES_iv, 0, sizeof(DES_iv));
501
16
	memset(iv, 0, sizeof(iv));
502
503
1056
	for (i = 0; i < ALGOR_NUM; i++)
504
512
		doit[i] = 0;
505
160
	for (i = 0; i < RSA_NUM; i++)
506
64
		rsa_doit[i] = 0;
507
128
	for (i = 0; i < DSA_NUM; i++)
508
48
		dsa_doit[i] = 0;
509
544
	for (i = 0; i < EC_NUM; i++)
510
256
		ecdsa_doit[i] = 0;
511
544
	for (i = 0; i < EC_NUM; i++)
512
256
		ecdh_doit[i] = 0;
513
514
515
	j = 0;
516
16
	argc--;
517
16
	argv++;
518
128
	while (argc) {
519

104
		if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
520
12
			usertime = 0;
521
12
			j--;	/* Otherwise, -elapsed gets confused with an
522
				 * algorithm. */
523

92
		} else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
524
			argc--;
525
			argv++;
526
			if (argc == 0) {
527
				BIO_printf(bio_err, "no EVP given\n");
528
				goto end;
529
			}
530
			evp_cipher = EVP_get_cipherbyname(*argv);
531
			if (!evp_cipher) {
532
				evp_md = EVP_get_digestbyname(*argv);
533
			}
534
			if (!evp_cipher && !evp_md) {
535
				BIO_printf(bio_err, "%s is an unknown cipher or digest\n", *argv);
536
				goto end;
537
			}
538
			doit[D_EVP] = 1;
539

80
		} else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
540
			decrypt = 1;
541
			j--;	/* Otherwise, -decrypt gets confused with an
542
				 * algorithm. */
543
		}
544

80
		else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
545
12
			argc--;
546
12
			argv++;
547
12
			if (argc == 0) {
548
				BIO_printf(bio_err, "no multi count given\n");
549
				goto end;
550
			}
551
12
			multi = strtonum(argv[0], 1, INT_MAX, &errstr);
552
12
			if (errstr) {
553
				BIO_printf(bio_err, "bad multi count: %s", errstr);
554
				goto end;
555
			}
556
12
			j--;	/* Otherwise, -multi gets confused with an
557
				 * algorithm. */
558
12
		}
559

56
		else if (argc > 0 && !strcmp(*argv, "-mr")) {
560
			mr = 1;
561
			j--;	/* Otherwise, -mr gets confused with an
562
				 * algorithm. */
563
		} else
564
#ifndef OPENSSL_NO_MD4
565
28
		if (strcmp(*argv, "md4") == 0)
566
			doit[D_MD4] = 1;
567
		else
568
#endif
569
#ifndef OPENSSL_NO_MD5
570
28
		if (strcmp(*argv, "md5") == 0)
571
			doit[D_MD5] = 1;
572
		else
573
#endif
574
#ifndef OPENSSL_NO_MD5
575
28
		if (strcmp(*argv, "hmac") == 0)
576
			doit[D_HMAC] = 1;
577
		else
578
#endif
579
#ifndef OPENSSL_NO_SHA
580
28
		if (strcmp(*argv, "sha1") == 0)
581
			doit[D_SHA1] = 1;
582
28
		else if (strcmp(*argv, "sha") == 0)
583
			doit[D_SHA1] = 1,
584
			    doit[D_SHA256] = 1,
585
			    doit[D_SHA512] = 1;
586
		else
587
#ifndef OPENSSL_NO_SHA256
588
28
		if (strcmp(*argv, "sha256") == 0)
589
			doit[D_SHA256] = 1;
590
		else
591
#endif
592
#ifndef OPENSSL_NO_SHA512
593
28
		if (strcmp(*argv, "sha512") == 0)
594
12
			doit[D_SHA512] = 1;
595
		else
596
#endif
597
#endif
598
#ifndef OPENSSL_NO_WHIRLPOOL
599
16
		if (strcmp(*argv, "whirlpool") == 0)
600
			doit[D_WHIRLPOOL] = 1;
601
		else
602
#endif
603
#ifndef OPENSSL_NO_RIPEMD
604
16
		if (strcmp(*argv, "ripemd") == 0)
605
			doit[D_RMD160] = 1;
606
16
		else if (strcmp(*argv, "rmd160") == 0)
607
			doit[D_RMD160] = 1;
608
16
		else if (strcmp(*argv, "ripemd160") == 0)
609
			doit[D_RMD160] = 1;
610
		else
611
#endif
612
#ifndef OPENSSL_NO_RC4
613
16
		if (strcmp(*argv, "rc4") == 0)
614
			doit[D_RC4] = 1;
615
		else
616
#endif
617
#ifndef OPENSSL_NO_DES
618
16
		if (strcmp(*argv, "des-cbc") == 0)
619
			doit[D_CBC_DES] = 1;
620
16
		else if (strcmp(*argv, "des-ede3") == 0)
621
			doit[D_EDE3_DES] = 1;
622
		else
623
#endif
624
#ifndef OPENSSL_NO_AES
625
16
		if (strcmp(*argv, "aes-128-cbc") == 0)
626
			doit[D_CBC_128_AES] = 1;
627
16
		else if (strcmp(*argv, "aes-192-cbc") == 0)
628
			doit[D_CBC_192_AES] = 1;
629
16
		else if (strcmp(*argv, "aes-256-cbc") == 0)
630
			doit[D_CBC_256_AES] = 1;
631
16
		else if (strcmp(*argv, "aes-128-ige") == 0)
632
			doit[D_IGE_128_AES] = 1;
633
16
		else if (strcmp(*argv, "aes-192-ige") == 0)
634
			doit[D_IGE_192_AES] = 1;
635
16
		else if (strcmp(*argv, "aes-256-ige") == 0)
636
			doit[D_IGE_256_AES] = 1;
637
		else
638
#endif
639
#ifndef OPENSSL_NO_CAMELLIA
640
16
		if (strcmp(*argv, "camellia-128-cbc") == 0)
641
			doit[D_CBC_128_CML] = 1;
642
16
		else if (strcmp(*argv, "camellia-192-cbc") == 0)
643
			doit[D_CBC_192_CML] = 1;
644
16
		else if (strcmp(*argv, "camellia-256-cbc") == 0)
645
			doit[D_CBC_256_CML] = 1;
646
		else
647
#endif
648
#ifndef RSA_NULL
649
16
		if (strcmp(*argv, "openssl") == 0) {
650
			RSA_set_default_method(RSA_PKCS1_SSLeay());
651
			j--;
652
		} else
653
#endif
654
16
		if (strcmp(*argv, "dsa512") == 0)
655
			dsa_doit[R_DSA_512] = 2;
656
16
		else if (strcmp(*argv, "dsa1024") == 0)
657
			dsa_doit[R_DSA_1024] = 2;
658
16
		else if (strcmp(*argv, "dsa2048") == 0)
659
			dsa_doit[R_DSA_2048] = 2;
660
16
		else if (strcmp(*argv, "rsa512") == 0)
661
			rsa_doit[R_RSA_512] = 2;
662
16
		else if (strcmp(*argv, "rsa1024") == 0)
663
			rsa_doit[R_RSA_1024] = 2;
664
16
		else if (strcmp(*argv, "rsa2048") == 0)
665
12
			rsa_doit[R_RSA_2048] = 2;
666
4
		else if (strcmp(*argv, "rsa4096") == 0)
667
			rsa_doit[R_RSA_4096] = 2;
668
		else
669
#ifndef OPENSSL_NO_RC2
670
4
		if (strcmp(*argv, "rc2-cbc") == 0)
671
			doit[D_CBC_RC2] = 1;
672
4
		else if (strcmp(*argv, "rc2") == 0)
673
			doit[D_CBC_RC2] = 1;
674
		else
675
#endif
676
#ifndef OPENSSL_NO_IDEA
677
4
		if (strcmp(*argv, "idea-cbc") == 0)
678
			doit[D_CBC_IDEA] = 1;
679
4
		else if (strcmp(*argv, "idea") == 0)
680
			doit[D_CBC_IDEA] = 1;
681
		else
682
#endif
683
#ifndef OPENSSL_NO_BF
684
4
		if (strcmp(*argv, "bf-cbc") == 0)
685
			doit[D_CBC_BF] = 1;
686
4
		else if (strcmp(*argv, "blowfish") == 0)
687
			doit[D_CBC_BF] = 1;
688
4
		else if (strcmp(*argv, "bf") == 0)
689
			doit[D_CBC_BF] = 1;
690
		else
691
#endif
692
#ifndef OPENSSL_NO_CAST
693
4
		if (strcmp(*argv, "cast-cbc") == 0)
694
			doit[D_CBC_CAST] = 1;
695
4
		else if (strcmp(*argv, "cast") == 0)
696
			doit[D_CBC_CAST] = 1;
697
4
		else if (strcmp(*argv, "cast5") == 0)
698
			doit[D_CBC_CAST] = 1;
699
		else
700
#endif
701
#ifndef OPENSSL_NO_DES
702
4
		if (strcmp(*argv, "des") == 0) {
703
			doit[D_CBC_DES] = 1;
704
			doit[D_EDE3_DES] = 1;
705
		} else
706
#endif
707
#ifndef OPENSSL_NO_AES
708
4
		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
4
		} else if (strcmp(*argv, "ghash") == 0)
713
			doit[D_GHASH] = 1;
714
4
		else if (strcmp(*argv,"aes-128-gcm") == 0)
715
			doit[D_AES_128_GCM]=1;
716
4
		else if (strcmp(*argv,"aes-256-gcm") == 0)
717
			doit[D_AES_256_GCM]=1;
718
		else
719
#endif
720
#ifndef OPENSSL_NO_CAMELLIA
721
4
		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;
725
		} else
726
#endif
727
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
728
4
		if (strcmp(*argv,"chacha20-poly1305") == 0)
729
			doit[D_CHACHA20_POLY1305]=1;
730
		else
731
#endif
732
4
		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;
737
		} else
738
4
		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;
742
		} else
743
4
		if (strcmp(*argv, "ecdsap160") == 0)
744
			ecdsa_doit[R_EC_P160] = 2;
745
4
		else if (strcmp(*argv, "ecdsap192") == 0)
746
			ecdsa_doit[R_EC_P192] = 2;
747
4
		else if (strcmp(*argv, "ecdsap224") == 0)
748
			ecdsa_doit[R_EC_P224] = 2;
749
4
		else if (strcmp(*argv, "ecdsap256") == 0)
750
			ecdsa_doit[R_EC_P256] = 2;
751
4
		else if (strcmp(*argv, "ecdsap384") == 0)
752
			ecdsa_doit[R_EC_P384] = 2;
753
4
		else if (strcmp(*argv, "ecdsap521") == 0)
754
			ecdsa_doit[R_EC_P521] = 2;
755
4
		else if (strcmp(*argv, "ecdsak163") == 0)
756
			ecdsa_doit[R_EC_K163] = 2;
757
4
		else if (strcmp(*argv, "ecdsak233") == 0)
758
			ecdsa_doit[R_EC_K233] = 2;
759
4
		else if (strcmp(*argv, "ecdsak283") == 0)
760
			ecdsa_doit[R_EC_K283] = 2;
761
4
		else if (strcmp(*argv, "ecdsak409") == 0)
762
			ecdsa_doit[R_EC_K409] = 2;
763
4
		else if (strcmp(*argv, "ecdsak571") == 0)
764
			ecdsa_doit[R_EC_K571] = 2;
765
4
		else if (strcmp(*argv, "ecdsab163") == 0)
766
			ecdsa_doit[R_EC_B163] = 2;
767
4
		else if (strcmp(*argv, "ecdsab233") == 0)
768
			ecdsa_doit[R_EC_B233] = 2;
769
4
		else if (strcmp(*argv, "ecdsab283") == 0)
770
			ecdsa_doit[R_EC_B283] = 2;
771
4
		else if (strcmp(*argv, "ecdsab409") == 0)
772
			ecdsa_doit[R_EC_B409] = 2;
773
4
		else if (strcmp(*argv, "ecdsab571") == 0)
774
			ecdsa_doit[R_EC_B571] = 2;
775
4
		else if (strcmp(*argv, "ecdsa") == 0) {
776
			for (i = 0; i < EC_NUM; i++)
777
				ecdsa_doit[i] = 1;
778
		} else
779
4
		if (strcmp(*argv, "ecdhp160") == 0)
780
			ecdh_doit[R_EC_P160] = 2;
781
4
		else if (strcmp(*argv, "ecdhp192") == 0)
782
			ecdh_doit[R_EC_P192] = 2;
783
4
		else if (strcmp(*argv, "ecdhp224") == 0)
784
			ecdh_doit[R_EC_P224] = 2;
785
4
		else if (strcmp(*argv, "ecdhp256") == 0)
786
			ecdh_doit[R_EC_P256] = 2;
787
4
		else if (strcmp(*argv, "ecdhp384") == 0)
788
			ecdh_doit[R_EC_P384] = 2;
789
4
		else if (strcmp(*argv, "ecdhp521") == 0)
790
			ecdh_doit[R_EC_P521] = 2;
791
4
		else if (strcmp(*argv, "ecdhk163") == 0)
792
			ecdh_doit[R_EC_K163] = 2;
793
4
		else if (strcmp(*argv, "ecdhk233") == 0)
794
			ecdh_doit[R_EC_K233] = 2;
795
4
		else if (strcmp(*argv, "ecdhk283") == 0)
796
			ecdh_doit[R_EC_K283] = 2;
797
4
		else if (strcmp(*argv, "ecdhk409") == 0)
798
			ecdh_doit[R_EC_K409] = 2;
799
4
		else if (strcmp(*argv, "ecdhk571") == 0)
800
			ecdh_doit[R_EC_K571] = 2;
801
4
		else if (strcmp(*argv, "ecdhb163") == 0)
802
			ecdh_doit[R_EC_B163] = 2;
803
4
		else if (strcmp(*argv, "ecdhb233") == 0)
804
			ecdh_doit[R_EC_B233] = 2;
805
4
		else if (strcmp(*argv, "ecdhb283") == 0)
806
			ecdh_doit[R_EC_B283] = 2;
807
4
		else if (strcmp(*argv, "ecdhb409") == 0)
808
			ecdh_doit[R_EC_B409] = 2;
809
4
		else if (strcmp(*argv, "ecdhb571") == 0)
810
			ecdh_doit[R_EC_B571] = 2;
811
4
		else if (strcmp(*argv, "ecdh") == 0) {
812
			for (i = 0; i < EC_NUM; i++)
813
				ecdh_doit[i] = 1;
814
		} else
815
		{
816
4
			BIO_printf(bio_err, "Error: bad option or value\n");
817
4
			BIO_printf(bio_err, "\n");
818
4
			BIO_printf(bio_err, "Available values:\n");
819
#ifndef OPENSSL_NO_MD4
820
4
			BIO_printf(bio_err, "md4      ");
821
#endif
822
#ifndef OPENSSL_NO_MD5
823
4
			BIO_printf(bio_err, "md5      ");
824
#ifndef OPENSSL_NO_HMAC
825
4
			BIO_printf(bio_err, "hmac     ");
826
#endif
827
#endif
828
#ifndef OPENSSL_NO_SHA1
829
4
			BIO_printf(bio_err, "sha1     ");
830
#endif
831
#ifndef OPENSSL_NO_SHA256
832
4
			BIO_printf(bio_err, "sha256   ");
833
#endif
834
#ifndef OPENSSL_NO_SHA512
835
4
			BIO_printf(bio_err, "sha512   ");
836
#endif
837
#ifndef OPENSSL_NO_WHIRLPOOL
838
4
			BIO_printf(bio_err, "whirlpool");
839
#endif
840
#ifndef OPENSSL_NO_RIPEMD160
841
4
			BIO_printf(bio_err, "rmd160");
842
#endif
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
4
			BIO_printf(bio_err, "\n");
848
#endif
849
850
#ifndef OPENSSL_NO_IDEA
851
4
			BIO_printf(bio_err, "idea-cbc ");
852
#endif
853
#ifndef OPENSSL_NO_RC2
854
4
			BIO_printf(bio_err, "rc2-cbc  ");
855
#endif
856
#ifndef OPENSSL_NO_BF
857
4
			BIO_printf(bio_err, "bf-cbc   ");
858
#endif
859
#ifndef OPENSSL_NO_DES
860
4
			BIO_printf(bio_err, "des-cbc  des-ede3\n");
861
#endif
862
#ifndef OPENSSL_NO_AES
863
4
			BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
864
4
			BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige\n");
865
4
			BIO_printf(bio_err, "aes-128-gcm aes-256-gcm ");
866
#endif
867
#ifndef OPENSSL_NO_CAMELLIA
868
4
			BIO_printf(bio_err, "\n");
869
4
			BIO_printf(bio_err, "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
870
#endif
871
#ifndef OPENSSL_NO_RC4
872
4
			BIO_printf(bio_err, "rc4");
873
#endif
874
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
875
4
			BIO_printf(bio_err," chacha20-poly1305");
876
#endif
877
4
			BIO_printf(bio_err, "\n");
878
879
4
			BIO_printf(bio_err, "rsa512   rsa1024  rsa2048  rsa4096\n");
880
881
4
			BIO_printf(bio_err, "dsa512   dsa1024  dsa2048\n");
882
4
			BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
883
4
			BIO_printf(bio_err, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
884
4
			BIO_printf(bio_err, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571 ecdsa\n");
885
4
			BIO_printf(bio_err, "ecdhp160  ecdhp192  ecdhp224  ecdhp256  ecdhp384  ecdhp521\n");
886
4
			BIO_printf(bio_err, "ecdhk163  ecdhk233  ecdhk283  ecdhk409  ecdhk571\n");
887
4
			BIO_printf(bio_err, "ecdhb163  ecdhb233  ecdhb283  ecdhb409  ecdhb571  ecdh\n");
888
889
#ifndef OPENSSL_NO_IDEA
890
4
			BIO_printf(bio_err, "idea     ");
891
#endif
892
#ifndef OPENSSL_NO_RC2
893
4
			BIO_printf(bio_err, "rc2      ");
894
#endif
895
#ifndef OPENSSL_NO_DES
896
4
			BIO_printf(bio_err, "des      ");
897
#endif
898
#ifndef OPENSSL_NO_AES
899
4
			BIO_printf(bio_err, "aes      ");
900
#endif
901
#ifndef OPENSSL_NO_CAMELLIA
902
4
			BIO_printf(bio_err, "camellia ");
903
#endif
904
4
			BIO_printf(bio_err, "rsa      ");
905
#ifndef OPENSSL_NO_BF
906
4
			BIO_printf(bio_err, "blowfish");
907
#endif
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
4
			BIO_printf(bio_err, "\n");
913
#endif
914
915
4
			BIO_printf(bio_err, "\n");
916
4
			BIO_printf(bio_err, "Available options:\n");
917
4
			BIO_printf(bio_err, "-elapsed        measure time in real time instead of CPU user time.\n");
918
4
			BIO_printf(bio_err, "-evp e          use EVP e.\n");
919
4
			BIO_printf(bio_err, "-decrypt        time decryption instead of encryption (only EVP).\n");
920
4
			BIO_printf(bio_err, "-mr             produce machine readable output.\n");
921
4
			BIO_printf(bio_err, "-multi n        run n benchmarks in parallel.\n");
922
4
			goto end;
923
		}
924
48
		argc--;
925
48
		argv++;
926
48
		j++;
927
	}
928
929

24
	if (multi && do_multi(multi))
930
		goto show_res;
931
932
8
	if (j == 0) {
933
		for (i = 0; i < ALGOR_NUM; i++) {
934
			if (i != D_EVP)
935
				doit[i] = 1;
936
		}
937
		for (i = 0; i < RSA_NUM; i++)
938
			rsa_doit[i] = 1;
939
		for (i = 0; i < DSA_NUM; i++)
940
			dsa_doit[i] = 1;
941
		for (i = 0; i < EC_NUM; i++)
942
			ecdsa_doit[i] = 1;
943
		for (i = 0; i < EC_NUM; i++)
944
			ecdh_doit[i] = 1;
945
	}
946
528
	for (i = 0; i < ALGOR_NUM; i++)
947
256
		if (doit[i])
948
8
			pr_header++;
949
950
8
	if (usertime == 0 && !mr)
951
		BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
952
953
80
	for (i = 0; i < RSA_NUM; i++) {
954
32
		const unsigned char *p;
955
956
32
		p = rsa_data[i];
957
32
		rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
958
32
		if (rsa_key[i] == NULL) {
959
			BIO_printf(bio_err, "internal error loading RSA key number %d\n", i);
960
			goto end;
961
		}
962
80
	}
963
964
8
	dsa_key[0] = get_dsa512();
965
8
	dsa_key[1] = get_dsa1024();
966
8
	dsa_key[2] = get_dsa2048();
967
968
#ifndef OPENSSL_NO_DES
969
8
	DES_set_key_unchecked(&key, &sch);
970
8
	DES_set_key_unchecked(&key2, &sch2);
971
8
	DES_set_key_unchecked(&key3, &sch3);
972
#endif
973
#ifndef OPENSSL_NO_AES
974
8
	AES_set_encrypt_key(key16, 128, &aes_ks1);
975
8
	AES_set_encrypt_key(key24, 192, &aes_ks2);
976
8
	AES_set_encrypt_key(key32, 256, &aes_ks3);
977
#endif
978
#ifndef OPENSSL_NO_CAMELLIA
979
8
	Camellia_set_key(key16, 128, &camellia_ks1);
980
8
	Camellia_set_key(ckey24, 192, &camellia_ks2);
981
8
	Camellia_set_key(ckey32, 256, &camellia_ks3);
982
#endif
983
#ifndef OPENSSL_NO_IDEA
984
8
	idea_set_encrypt_key(key16, &idea_ks);
985
#endif
986
#ifndef OPENSSL_NO_RC4
987
8
	RC4_set_key(&rc4_ks, 16, key16);
988
#endif
989
#ifndef OPENSSL_NO_RC2
990
8
	RC2_set_key(&rc2_ks, 16, key16, 128);
991
#endif
992
#ifndef OPENSSL_NO_BF
993
8
	BF_set_key(&bf_ks, 16, key16);
994
#endif
995
#ifndef OPENSSL_NO_CAST
996
8
	CAST_set_key(&cast_ks, 16, key16);
997
#endif
998
8
	memset(rsa_c, 0, sizeof(rsa_c));
999
#define COND(c)	(run && count<0x7fffffff)
1000
#define COUNT(d) (count)
1001
8
	signal(SIGALRM, sig_done);
1002
1003
#ifndef OPENSSL_NO_MD4
1004
8
	if (doit[D_MD4]) {
1005
		for (j = 0; j < SIZE_NUM; j++) {
1006
			print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1007
			Time_F(START);
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);
1010
			d = Time_F(STOP);
1011
			print_result(D_MD4, j, count, d);
1012
		}
1013
	}
1014
#endif
1015
1016
#ifndef OPENSSL_NO_MD5
1017
8
	if (doit[D_MD5]) {
1018
		for (j = 0; j < SIZE_NUM; j++) {
1019
			print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1020
			Time_F(START);
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);
1023
			d = Time_F(STOP);
1024
			print_result(D_MD5, j, count, d);
1025
		}
1026
	}
1027
#endif
1028
1029
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1030
8
	if (doit[D_HMAC]) {
1031
		HMAC_CTX hctx;
1032
1033
		HMAC_CTX_init(&hctx);
1034
		HMAC_Init_ex(&hctx, (unsigned char *) "This is a key...",
1035
		    16, EVP_md5(), NULL);
1036
1037
		for (j = 0; j < SIZE_NUM; j++) {
1038
			print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1039
			Time_F(START);
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);
1044
			}
1045
			d = Time_F(STOP);
1046
			print_result(D_HMAC, j, count, d);
1047
		}
1048
		HMAC_CTX_cleanup(&hctx);
1049
	}
1050
#endif
1051
#ifndef OPENSSL_NO_SHA
1052
8
	if (doit[D_SHA1]) {
1053
		for (j = 0; j < SIZE_NUM; j++) {
1054
			print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1055
			Time_F(START);
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);
1058
			d = Time_F(STOP);
1059
			print_result(D_SHA1, j, count, d);
1060
		}
1061
	}
1062
#ifndef OPENSSL_NO_SHA256
1063
8
	if (doit[D_SHA256]) {
1064
		for (j = 0; j < SIZE_NUM; j++) {
1065
			print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1066
			Time_F(START);
1067
			for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1068
				SHA256(buf, lengths[j], sha256);
1069
			d = Time_F(STOP);
1070
			print_result(D_SHA256, j, count, d);
1071
		}
1072
	}
1073
#endif
1074
1075
#ifndef OPENSSL_NO_SHA512
1076
8
	if (doit[D_SHA512]) {
1077
96
		for (j = 0; j < SIZE_NUM; j++) {
1078
40
			print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1079
40
			Time_F(START);
1080
156601086
			for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1081
78300503
				SHA512(buf, lengths[j], sha512);
1082
40
			d = Time_F(STOP);
1083
40
			print_result(D_SHA512, j, count, d);
1084
		}
1085
	}
1086
#endif
1087
#endif
1088
1089
#ifndef OPENSSL_NO_WHIRLPOOL
1090
8
	if (doit[D_WHIRLPOOL]) {
1091
		for (j = 0; j < SIZE_NUM; j++) {
1092
			print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1093
			Time_F(START);
1094
			for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1095
				WHIRLPOOL(buf, lengths[j], whirlpool);
1096
			d = Time_F(STOP);
1097
			print_result(D_WHIRLPOOL, j, count, d);
1098
		}
1099
	}
1100
#endif
1101
1102
#ifndef OPENSSL_NO_RIPEMD
1103
8
	if (doit[D_RMD160]) {
1104
		for (j = 0; j < SIZE_NUM; j++) {
1105
			print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1106
			Time_F(START);
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);
1109
			d = Time_F(STOP);
1110
			print_result(D_RMD160, j, count, d);
1111
		}
1112
	}
1113
#endif
1114
#ifndef OPENSSL_NO_RC4
1115
8
	if (doit[D_RC4]) {
1116
		for (j = 0; j < SIZE_NUM; j++) {
1117
			print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1118
			Time_F(START);
1119
			for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1120
				RC4(&rc4_ks, (unsigned int) lengths[j],
1121
				    buf, buf);
1122
			d = Time_F(STOP);
1123
			print_result(D_RC4, j, count, d);
1124
		}
1125
	}
1126
#endif
1127
#ifndef OPENSSL_NO_DES
1128
8
	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]);
1131
			Time_F(START);
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);
1135
			d = Time_F(STOP);
1136
			print_result(D_CBC_DES, j, count, d);
1137
		}
1138
	}
1139
8
	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]);
1142
			Time_F(START);
1143
			for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1144
				DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1145
				    &sch, &sch2, &sch3,
1146
				    &DES_iv, DES_ENCRYPT);
1147
			d = Time_F(STOP);
1148
			print_result(D_EDE3_DES, j, count, d);
1149
		}
1150
	}
1151
#endif
1152
#ifndef OPENSSL_NO_AES
1153
8
	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]);
1156
			Time_F(START);
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,
1160
				    iv, AES_ENCRYPT);
1161
			d = Time_F(STOP);
1162
			print_result(D_CBC_128_AES, j, count, d);
1163
		}
1164
	}
1165
8
	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]);
1168
			Time_F(START);
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,
1172
				    iv, AES_ENCRYPT);
1173
			d = Time_F(STOP);
1174
			print_result(D_CBC_192_AES, j, count, d);
1175
		}
1176
	}
1177
8
	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]);
1180
			Time_F(START);
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,
1184
				    iv, AES_ENCRYPT);
1185
			d = Time_F(STOP);
1186
			print_result(D_CBC_256_AES, j, count, d);
1187
		}
1188
	}
1189
8
	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]);
1192
			Time_F(START);
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,
1196
				    iv, AES_ENCRYPT);
1197
			d = Time_F(STOP);
1198
			print_result(D_IGE_128_AES, j, count, d);
1199
		}
1200
	}
1201
8
	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]);
1204
			Time_F(START);
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,
1208
				    iv, AES_ENCRYPT);
1209
			d = Time_F(STOP);
1210
			print_result(D_IGE_192_AES, j, count, d);
1211
		}
1212
	}
1213
8
	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]);
1216
			Time_F(START);
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,
1220
				    iv, AES_ENCRYPT);
1221
			d = Time_F(STOP);
1222
			print_result(D_IGE_256_AES, j, count, d);
1223
		}
1224
	}
1225
8
	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);
1228
1229
		for (j = 0; j < SIZE_NUM; j++) {
1230
			print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1231
			Time_F(START);
1232
			for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1233
				CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1234
			d = Time_F(STOP);
1235
			print_result(D_GHASH, j, count, d);
1236
		}
1237
		CRYPTO_gcm128_release(ctx);
1238
	}
1239
8
	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;
1243
		EVP_AEAD_CTX ctx;
1244
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);
1248
1249
		for (j = 0; j < SIZE_NUM; j++) {
1250
			print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
1251
			Time_F(START);
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);
1255
			d=Time_F(STOP);
1256
			print_result(D_AES_128_GCM,j,count,d);
1257
		}
1258
		EVP_AEAD_CTX_cleanup(&ctx);
1259
	}
1260
1261
8
	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;
1265
		EVP_AEAD_CTX ctx;
1266
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);
1270
1271
		for (j = 0; j < SIZE_NUM; j++) {
1272
			print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
1273
			Time_F(START);
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);
1277
			d=Time_F(STOP);
1278
			print_result(D_AES_256_GCM, j, count, d);
1279
		}
1280
		EVP_AEAD_CTX_cleanup(&ctx);
1281
	}
1282
#endif
1283
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1284
8
	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;
1288
		EVP_AEAD_CTX ctx;
1289
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);
1293
1294
		for (j = 0; j < SIZE_NUM; j++) {
1295
			print_message(names[D_CHACHA20_POLY1305],
1296
			    c[D_CHACHA20_POLY1305][j], lengths[j]);
1297
			Time_F(START);
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);
1301
			d=Time_F(STOP);
1302
			print_result(D_CHACHA20_POLY1305, j, count, d);
1303
		}
1304
		EVP_AEAD_CTX_cleanup(&ctx);
1305
	}
1306
#endif
1307
#ifndef OPENSSL_NO_CAMELLIA
1308
8
	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]);
1311
			Time_F(START);
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);
1316
			d = Time_F(STOP);
1317
			print_result(D_CBC_128_CML, j, count, d);
1318
		}
1319
	}
1320
8
	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]);
1323
			Time_F(START);
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);
1328
			d = Time_F(STOP);
1329
			print_result(D_CBC_192_CML, j, count, d);
1330
		}
1331
	}
1332
8
	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]);
1335
			Time_F(START);
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);
1340
			d = Time_F(STOP);
1341
			print_result(D_CBC_256_CML, j, count, d);
1342
		}
1343
	}
1344
#endif
1345
#ifndef OPENSSL_NO_IDEA
1346
8
	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]);
1349
			Time_F(START);
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,
1353
				    iv, IDEA_ENCRYPT);
1354
			d = Time_F(STOP);
1355
			print_result(D_CBC_IDEA, j, count, d);
1356
		}
1357
	}
1358
#endif
1359
#ifndef OPENSSL_NO_RC2
1360
8
	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]);
1363
			Time_F(START);
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,
1367
				    iv, RC2_ENCRYPT);
1368
			d = Time_F(STOP);
1369
			print_result(D_CBC_RC2, j, count, d);
1370
		}
1371
	}
1372
#endif
1373
#ifndef OPENSSL_NO_BF
1374
8
	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]);
1377
			Time_F(START);
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,
1381
				    iv, BF_ENCRYPT);
1382
			d = Time_F(STOP);
1383
			print_result(D_CBC_BF, j, count, d);
1384
		}
1385
	}
1386
#endif
1387
#ifndef OPENSSL_NO_CAST
1388
8
	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]);
1391
			Time_F(START);
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,
1395
				    iv, CAST_ENCRYPT);
1396
			d = Time_F(STOP);
1397
			print_result(D_CBC_CAST, j, count, d);
1398
		}
1399
	}
1400
#endif
1401
1402
8
	if (doit[D_EVP]) {
1403
		for (j = 0; j < SIZE_NUM; j++) {
1404
			if (evp_cipher) {
1405
				EVP_CIPHER_CTX ctx;
1406
				int outl;
1407
1408
				names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1409
				/*
1410
				 * -O3 -fschedule-insns messes up an
1411
				 * optimization here!  names[D_EVP] somehow
1412
				 * becomes NULL
1413
				 */
1414
				print_message(names[D_EVP], save_count,
1415
				    lengths[j]);
1416
1417
				EVP_CIPHER_CTX_init(&ctx);
1418
				if (decrypt)
1419
					EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1420
				else
1421
					EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1422
				EVP_CIPHER_CTX_set_padding(&ctx, 0);
1423
1424
				Time_F(START);
1425
				if (decrypt)
1426
					for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1427
						EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1428
				else
1429
					for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1430
						EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1431
				if (decrypt)
1432
					EVP_DecryptFinal_ex(&ctx, buf, &outl);
1433
				else
1434
					EVP_EncryptFinal_ex(&ctx, buf, &outl);
1435
				d = Time_F(STOP);
1436
				EVP_CIPHER_CTX_cleanup(&ctx);
1437
			}
1438
			if (evp_md) {
1439
				names[D_EVP] = OBJ_nid2ln(evp_md->type);
1440
				print_message(names[D_EVP], save_count,
1441
				    lengths[j]);
1442
1443
				Time_F(START);
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);
1446
1447
				d = Time_F(STOP);
1448
			}
1449
			print_result(D_EVP, j, count, d);
1450
		}
1451
	}
1452
8
	arc4random_buf(buf, 36);
1453
80
	for (j = 0; j < RSA_NUM; j++) {
1454
		int ret;
1455
32
		if (!rsa_doit[j])
1456
24
			continue;
1457
8
		ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1458
8
		if (ret == 0) {
1459
			BIO_printf(bio_err, "RSA sign failure.  No RSA sign will be done.\n");
1460
			ERR_print_errors(bio_err);
1461
			rsa_count = 1;
1462
		} else {
1463
8
			pkey_print_message("private", "rsa",
1464
8
			    rsa_c[j][0], rsa_bits[j],
1465
			    RSA_SECONDS);
1466
/*			RSA_blinding_on(rsa_key[j],NULL); */
1467
8
			Time_F(START);
1468
81842
			for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1469
40913
				ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1470
40913
				    &rsa_num, rsa_key[j]);
1471
40913
				if (ret == 0) {
1472
					BIO_printf(bio_err,
1473
					    "RSA sign failure\n");
1474
					ERR_print_errors(bio_err);
1475
					count = 1;
1476
					break;
1477
				}
1478
			}
1479
8
			d = Time_F(STOP);
1480
16
			BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
1481
			    : "%ld %d bit private RSA's in %.2fs\n",
1482
8
			    count, rsa_bits[j], d);
1483
8
			rsa_results[j][0] = d / (double) count;
1484
			rsa_count = count;
1485
		}
1486
1487
8
		ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1488
8
		if (ret <= 0) {
1489
			BIO_printf(bio_err, "RSA verify failure.  No RSA verify will be done.\n");
1490
			ERR_print_errors(bio_err);
1491
			rsa_doit[j] = 0;
1492
		} else {
1493
8
			pkey_print_message("public", "rsa",
1494
8
			    rsa_c[j][1], rsa_bits[j],
1495
			    RSA_SECONDS);
1496
8
			Time_F(START);
1497
1446830
			for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1498
723407
				ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1499
723407
				    rsa_num, rsa_key[j]);
1500
723407
				if (ret <= 0) {
1501
					BIO_printf(bio_err,
1502
					    "RSA verify failure\n");
1503
					ERR_print_errors(bio_err);
1504
					count = 1;
1505
					break;
1506
				}
1507
			}
1508
8
			d = Time_F(STOP);
1509
16
			BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
1510
			    : "%ld %d bit public RSA's in %.2fs\n",
1511
8
			    count, rsa_bits[j], d);
1512
8
			rsa_results[j][1] = d / (double) count;
1513
		}
1514
1515
8
		if (rsa_count <= 1) {
1516
			/* if longer than 10s, don't do any more */
1517
			for (j++; j < RSA_NUM; j++)
1518
				rsa_doit[j] = 0;
1519
		}
1520
8
	}
1521
1522
8
	arc4random_buf(buf, 20);
1523
64
	for (j = 0; j < DSA_NUM; j++) {
1524
24
		unsigned int kk;
1525
		int ret;
1526
1527
24
		if (!dsa_doit[j])
1528
24
			continue;
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,
1532
		    &kk, dsa_key[j]);
1533
		if (ret == 0) {
1534
			BIO_printf(bio_err, "DSA sign failure.  No DSA sign will be done.\n");
1535
			ERR_print_errors(bio_err);
1536
			rsa_count = 1;
1537
		} else {
1538
			pkey_print_message("sign", "dsa",
1539
			    dsa_c[j][0], dsa_bits[j],
1540
			    DSA_SECONDS);
1541
			Time_F(START);
1542
			for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1543
				ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1544
				    &kk, dsa_key[j]);
1545
				if (ret == 0) {
1546
					BIO_printf(bio_err,
1547
					    "DSA sign failure\n");
1548
					ERR_print_errors(bio_err);
1549
					count = 1;
1550
					break;
1551
				}
1552
			}
1553
			d = Time_F(STOP);
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;
1558
			rsa_count = count;
1559
		}
1560
1561
		ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1562
		    kk, dsa_key[j]);
1563
		if (ret <= 0) {
1564
			BIO_printf(bio_err, "DSA verify failure.  No DSA verify will be done.\n");
1565
			ERR_print_errors(bio_err);
1566
			dsa_doit[j] = 0;
1567
		} else {
1568
			pkey_print_message("verify", "dsa",
1569
			    dsa_c[j][1], dsa_bits[j],
1570
			    DSA_SECONDS);
1571
			Time_F(START);
1572
			for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1573
				ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1574
				    kk, dsa_key[j]);
1575
				if (ret <= 0) {
1576
					BIO_printf(bio_err,
1577
					    "DSA verify failure\n");
1578
					ERR_print_errors(bio_err);
1579
					count = 1;
1580
					break;
1581
				}
1582
			}
1583
			d = Time_F(STOP);
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;
1588
		}
1589
1590
		if (rsa_count <= 1) {
1591
			/* if longer than 10s, don't do any more */
1592
			for (j++; j < DSA_NUM; j++)
1593
				dsa_doit[j] = 0;
1594
		}
1595
24
	}
1596
1597
272
	for (j = 0; j < EC_NUM; j++) {
1598
		int ret;
1599
1600
128
		if (!ecdsa_doit[j])
1601
128
			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);
1606
			rsa_count = 1;
1607
		} else {
1608
			EC_KEY_precompute_mult(ecdsa[j], NULL);
1609
1610
			/* Perform ECDSA signature test */
1611
			EC_KEY_generate_key(ecdsa[j]);
1612
			ret = ECDSA_sign(0, buf, 20, ecdsasig,
1613
			    &ecdsasiglen, ecdsa[j]);
1614
			if (ret == 0) {
1615
				BIO_printf(bio_err, "ECDSA sign failure.  No ECDSA sign will be done.\n");
1616
				ERR_print_errors(bio_err);
1617
				rsa_count = 1;
1618
			} else {
1619
				pkey_print_message("sign", "ecdsa",
1620
				    ecdsa_c[j][0],
1621
				    test_curves_bits[j],
1622
				    ECDSA_SECONDS);
1623
1624
				Time_F(START);
1625
				for (count = 0, run = 1; COND(ecdsa_c[j][0]);
1626
				    count++) {
1627
					ret = ECDSA_sign(0, buf, 20,
1628
					    ecdsasig, &ecdsasiglen,
1629
					    ecdsa[j]);
1630
					if (ret == 0) {
1631
						BIO_printf(bio_err, "ECDSA sign failure\n");
1632
						ERR_print_errors(bio_err);
1633
						count = 1;
1634
						break;
1635
					}
1636
				}
1637
				d = Time_F(STOP);
1638
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;
1643
				rsa_count = count;
1644
			}
1645
1646
			/* Perform ECDSA verification test */
1647
			ret = ECDSA_verify(0, buf, 20, ecdsasig,
1648
			    ecdsasiglen, ecdsa[j]);
1649
			if (ret != 1) {
1650
				BIO_printf(bio_err, "ECDSA verify failure.  No ECDSA verify will be done.\n");
1651
				ERR_print_errors(bio_err);
1652
				ecdsa_doit[j] = 0;
1653
			} else {
1654
				pkey_print_message("verify", "ecdsa",
1655
				    ecdsa_c[j][1],
1656
				    test_curves_bits[j],
1657
				    ECDSA_SECONDS);
1658
				Time_F(START);
1659
				for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1660
					ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1661
					if (ret != 1) {
1662
						BIO_printf(bio_err, "ECDSA verify failure\n");
1663
						ERR_print_errors(bio_err);
1664
						count = 1;
1665
						break;
1666
					}
1667
				}
1668
				d = Time_F(STOP);
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;
1673
			}
1674
1675
			if (rsa_count <= 1) {
1676
				/* if longer than 10s, don't do any more */
1677
				for (j++; j < EC_NUM; j++)
1678
					ecdsa_doit[j] = 0;
1679
			}
1680
		}
1681
	}
1682
1683
272
	for (j = 0; j < EC_NUM; j++) {
1684
128
		if (!ecdh_doit[j])
1685
			continue;
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);
1691
			rsa_count = 1;
1692
		} else {
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);
1698
				rsa_count = 1;
1699
			} else {
1700
				/*
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).
1705
				 */
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;
1711
					kdf = KDF1_SHA1;
1712
				} else {
1713
					outlen = (field_size + 7) / 8;
1714
					kdf = NULL;
1715
				}
1716
				secret_size_a = ECDH_compute_key(secret_a, outlen,
1717
				    EC_KEY_get0_public_key(ecdh_b[j]),
1718
				    ecdh_a[j], kdf);
1719
				secret_size_b = ECDH_compute_key(secret_b, outlen,
1720
				    EC_KEY_get0_public_key(ecdh_a[j]),
1721
				    ecdh_b[j], kdf);
1722
				if (secret_size_a != secret_size_b)
1723
					ecdh_checks = 0;
1724
				else
1725
					ecdh_checks = 1;
1726
1727
				for (secret_idx = 0;
1728
				    (secret_idx < secret_size_a)
1729
				    && (ecdh_checks == 1);
1730
				    secret_idx++) {
1731
					if (secret_a[secret_idx] != secret_b[secret_idx])
1732
						ecdh_checks = 0;
1733
				}
1734
1735
				if (ecdh_checks == 0) {
1736
					BIO_printf(bio_err,
1737
					    "ECDH computations don't match.\n");
1738
					ERR_print_errors(bio_err);
1739
					rsa_count = 1;
1740
				} else {
1741
					pkey_print_message("", "ecdh",
1742
					    ecdh_c[j][0],
1743
					    test_curves_bits[j],
1744
					    ECDH_SECONDS);
1745
					Time_F(START);
1746
					for (count = 0, run = 1;
1747
					     COND(ecdh_c[j][0]); count++) {
1748
						ECDH_compute_key(secret_a,
1749
						    outlen,
1750
						    EC_KEY_get0_public_key(ecdh_b[j]),
1751
						    ecdh_a[j], kdf);
1752
					}
1753
					d = Time_F(STOP);
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;
1759
					rsa_count = count;
1760
				}
1761
			}
1762
		}
1763
1764
1765
		if (rsa_count <= 1) {
1766
			/* if longer than 10s, don't do any more */
1767
			for (j++; j < EC_NUM; j++)
1768
				ecdh_doit[j] = 0;
1769
		}
1770
	}
1771
show_res:
1772
12
	if (!mr) {
1773
4
		fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
1774
4
		fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
1775
4
		printf("options:");
1776
4
		printf("%s ", BN_options());
1777
#ifndef OPENSSL_NO_RC4
1778
4
		printf("%s ", RC4_options());
1779
#endif
1780
#ifndef OPENSSL_NO_DES
1781
4
		printf("%s ", DES_options());
1782
#endif
1783
#ifndef OPENSSL_NO_AES
1784
4
		printf("%s ", AES_options());
1785
#endif
1786
#ifndef OPENSSL_NO_IDEA
1787
4
		printf("%s ", idea_options());
1788
#endif
1789
#ifndef OPENSSL_NO_BF
1790
4
		printf("%s ", BF_options());
1791
#endif
1792
4
		fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
1793
4
	}
1794
12
	if (pr_header) {
1795
8
		if (mr)
1796
8
			fprintf(stdout, "+H");
1797
		else {
1798
			fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n");
1799
			fprintf(stdout, "type        ");
1800
		}
1801
96
		for (j = 0; j < SIZE_NUM; j++)
1802
40
			fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
1803
8
		fprintf(stdout, "\n");
1804
8
	}
1805
792
	for (k = 0; k < ALGOR_NUM; k++) {
1806
384
		if (!doit[k])
1807
			continue;
1808
12
		if (mr)
1809
8
			fprintf(stdout, "+F:%d:%s", k, names[k]);
1810
		else
1811
4
			fprintf(stdout, "%-13s", names[k]);
1812
144
		for (j = 0; j < SIZE_NUM; j++) {
1813
60
			if (results[k][j] > 10000 && !mr)
1814
20
				fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
1815
			else
1816
40
				fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
1817
		}
1818
12
		fprintf(stdout, "\n");
1819
12
	}
1820
	j = 1;
1821
120
	for (k = 0; k < RSA_NUM; k++) {
1822
48
		if (!rsa_doit[k])
1823
			continue;
1824
12
		if (j && !mr) {
1825
4
			printf("%18ssign    verify    sign/s verify/s\n", " ");
1826
			j = 0;
1827
4
		}
1828
12
		if (mr)
1829
8
			fprintf(stdout, "+F2:%u:%u:%f:%f\n",
1830
8
			    k, rsa_bits[k], rsa_results[k][0],
1831
8
			    rsa_results[k][1]);
1832
		else
1833
4
			fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1834
4
			    rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1835
4
			    1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
1836
	}
1837
	j = 1;
1838
96
	for (k = 0; k < DSA_NUM; k++) {
1839
36
		if (!dsa_doit[k])
1840
			continue;
1841
		if (j && !mr) {
1842
			printf("%18ssign    verify    sign/s verify/s\n", " ");
1843
			j = 0;
1844
		}
1845
		if (mr)
1846
			fprintf(stdout, "+F3:%u:%u:%f:%f\n",
1847
			    k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
1848
		else
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]);
1852
	}
1853
	j = 1;
1854
408
	for (k = 0; k < EC_NUM; k++) {
1855
192
		if (!ecdsa_doit[k])
1856
			continue;
1857
		if (j && !mr) {
1858
			printf("%30ssign    verify    sign/s verify/s\n", " ");
1859
			j = 0;
1860
		}
1861
		if (mr)
1862
			fprintf(stdout, "+F4:%u:%u:%f:%f\n",
1863
			    k, test_curves_bits[k],
1864
			    ecdsa_results[k][0], ecdsa_results[k][1]);
1865
		else
1866
			fprintf(stdout,
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]);
1872
	}
1873
1874
1875
	j = 1;
1876
408
	for (k = 0; k < EC_NUM; k++) {
1877
192
		if (!ecdh_doit[k])
1878
			continue;
1879
		if (j && !mr) {
1880
			printf("%30sop      op/s\n", " ");
1881
			j = 0;
1882
		}
1883
		if (mr)
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]);
1887
1888
		else
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]);
1893
	}
1894
1895
12
	mret = 0;
1896
1897
end:
1898
16
	ERR_print_errors(bio_err);
1899
16
	free(buf);
1900
16
	free(buf2);
1901
160
	for (i = 0; i < RSA_NUM; i++)
1902
64
		if (rsa_key[i] != NULL)
1903
32
			RSA_free(rsa_key[i]);
1904
128
	for (i = 0; i < DSA_NUM; i++)
1905
48
		if (dsa_key[i] != NULL)
1906
24
			DSA_free(dsa_key[i]);
1907
1908
544
	for (i = 0; i < EC_NUM; i++)
1909
256
		if (ecdsa[i] != NULL)
1910
			EC_KEY_free(ecdsa[i]);
1911
544
	for (i = 0; i < EC_NUM; i++) {
1912
256
		if (ecdh_a[i] != NULL)
1913
			EC_KEY_free(ecdh_a[i]);
1914
256
		if (ecdh_b[i] != NULL)
1915
			EC_KEY_free(ecdh_b[i]);
1916
	}
1917
1918
1919
16
	return (mret);
1920
16
}
1921
1922
static void
1923
print_message(const char *s, long num, int length)
1924
{
1925
80
	BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
1926
	    : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
1927
40
	(void) BIO_flush(bio_err);
1928
40
	alarm(SECONDS);
1929
40
}
1930
1931
static void
1932
pkey_print_message(const char *str, const char *str2, long num,
1933
    int bits, int tm)
1934
{
1935
32
	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
16
	(void) BIO_flush(bio_err);
1938
16
	alarm(tm);
1939
16
}
1940
1941
static void
1942
print_result(int alg, int run_no, int count, double time_used)
1943
{
1944
120
	BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
1945
40
	    : "%d %s's in %.2fs\n", count, names[alg], time_used);
1946
40
	results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
1947
40
}
1948
1949
static char *
1950
sstrsep(char **string, const char *delim)
1951
{
1952
176
	char isdelim[256];
1953
88
	char *token = *string;
1954
1955
88
	if (**string == 0)
1956
		return NULL;
1957
1958
88
	memset(isdelim, 0, sizeof isdelim);
1959
88
	isdelim[0] = 1;
1960
1961
352
	while (*delim) {
1962
88
		isdelim[(unsigned char) (*delim)] = 1;
1963
88
		delim++;
1964
	}
1965
1966
1568
	while (!isdelim[(unsigned char) (**string)]) {
1967
696
		(*string)++;
1968
	}
1969
1970
88
	if (**string) {
1971
72
		**string = 0;
1972
72
		(*string)++;
1973
72
	}
1974
88
	return token;
1975
88
}
1976
1977
static int
1978
do_multi(int multi)
1979
{
1980
	int n;
1981
24
	int fd[2];
1982
	int *fds;
1983
	static char sep[] = ":";
1984
12
	const char *errstr = NULL;
1985
1986
12
	fds = reallocarray(NULL, multi, sizeof *fds);
1987
12
	if (fds == NULL) {
1988
		fprintf(stderr, "reallocarray failure\n");
1989
		exit(1);
1990
	}
1991
48
	for (n = 0; n < multi; ++n) {
1992
20
		if (pipe(fd) == -1) {
1993
			fprintf(stderr, "pipe failure\n");
1994
			exit(1);
1995
		}
1996
20
		fflush(stdout);
1997
20
		fflush(stderr);
1998
20
		if (fork()) {
1999
12
			close(fd[1]);
2000
12
			fds[n] = fd[0];
2001
		} else {
2002
8
			close(fd[0]);
2003
8
			close(1);
2004
8
			if (dup(fd[1]) == -1) {
2005
				fprintf(stderr, "dup failed\n");
2006
				exit(1);
2007
			}
2008
8
			close(fd[1]);
2009
8
			mr = 1;
2010
8
			usertime = 0;
2011
8
			free(fds);
2012
8
			return 0;
2013
		}
2014
12
		printf("Forked child %d\n", n);
2015
	}
2016
2017
	/* for now, assume the pipe is long enough to take all the output */
2018
24
	for (n = 0; n < multi; ++n) {
2019
		FILE *f;
2020
8
		char buf[1024];
2021
8
		char *p;
2022
2023
8
		f = fdopen(fds[n], "r");
2024
64
		while (fgets(buf, sizeof buf, f)) {
2025
24
			p = strchr(buf, '\n');
2026
24
			if (p)
2027
24
				*p = '\0';
2028
24
			if (buf[0] != '+') {
2029
				fprintf(stderr, "Don't understand line '%s' from child %d\n",
2030
				    buf, n);
2031
				continue;
2032
			}
2033
24
			printf("Got: %s from %d\n", buf, n);
2034
24
			if (!strncmp(buf, "+F:", 3)) {
2035
				int alg;
2036
				int j;
2037
2038
8
				p = buf + 3;
2039
8
				alg = strtonum(sstrsep(&p, sep),
2040
				    0, ALGOR_NUM - 1, &errstr);
2041
8
				sstrsep(&p, sep);
2042
96
				for (j = 0; j < SIZE_NUM; ++j)
2043
40
					results[alg][j] += atof(sstrsep(&p, sep));
2044
24
			} else if (!strncmp(buf, "+F2:", 4)) {
2045
				int k;
2046
				double d;
2047
2048
8
				p = buf + 4;
2049
8
				k = strtonum(sstrsep(&p, sep),
2050
				    0, ALGOR_NUM - 1, &errstr);
2051
8
				sstrsep(&p, sep);
2052
2053
8
				d = atof(sstrsep(&p, sep));
2054
8
				if (n)
2055
4
					rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2056
				else
2057
					rsa_results[k][0] = d;
2058
2059
8
				d = atof(sstrsep(&p, sep));
2060
8
				if (n)
2061
4
					rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2062
				else
2063
					rsa_results[k][1] = d;
2064
16
			} else if (!strncmp(buf, "+F2:", 4)) {
2065
				int k;
2066
				double d;
2067
2068
				p = buf + 4;
2069
				k = strtonum(sstrsep(&p, sep),
2070
				    0, ALGOR_NUM - 1, &errstr);
2071
				sstrsep(&p, sep);
2072
2073
				d = atof(sstrsep(&p, sep));
2074
				if (n)
2075
					rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2076
				else
2077
					rsa_results[k][0] = d;
2078
2079
				d = atof(sstrsep(&p, sep));
2080
				if (n)
2081
					rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2082
				else
2083
					rsa_results[k][1] = d;
2084
			}
2085
8
			else if (!strncmp(buf, "+F3:", 4)) {
2086
				int k;
2087
				double d;
2088
2089
				p = buf + 4;
2090
				k = strtonum(sstrsep(&p, sep),
2091
				    0, ALGOR_NUM - 1, &errstr);
2092
				sstrsep(&p, sep);
2093
2094
				d = atof(sstrsep(&p, sep));
2095
				if (n)
2096
					dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2097
				else
2098
					dsa_results[k][0] = d;
2099
2100
				d = atof(sstrsep(&p, sep));
2101
				if (n)
2102
					dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2103
				else
2104
					dsa_results[k][1] = d;
2105
			}
2106
8
			else if (!strncmp(buf, "+F4:", 4)) {
2107
				int k;
2108
				double d;
2109
2110
				p = buf + 4;
2111
				k = strtonum(sstrsep(&p, sep),
2112
				    0, ALGOR_NUM - 1, &errstr);
2113
				sstrsep(&p, sep);
2114
2115
				d = atof(sstrsep(&p, sep));
2116
				if (n)
2117
					ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
2118
				else
2119
					ecdsa_results[k][0] = d;
2120
2121
				d = atof(sstrsep(&p, sep));
2122
				if (n)
2123
					ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
2124
				else
2125
					ecdsa_results[k][1] = d;
2126
			}
2127
2128
8
			else if (!strncmp(buf, "+F5:", 4)) {
2129
				int k;
2130
				double d;
2131
2132
				p = buf + 4;
2133
				k = strtonum(sstrsep(&p, sep),
2134
				    0, ALGOR_NUM - 1, &errstr);
2135
				sstrsep(&p, sep);
2136
2137
				d = atof(sstrsep(&p, sep));
2138
				if (n)
2139
					ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2140
				else
2141
					ecdh_results[k][0] = d;
2142
2143
			}
2144
2145
8
			else if (!strncmp(buf, "+H:", 3)) {
2146
			} else
2147
				fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2148
		}
2149
2150
8
		fclose(f);
2151
8
	}
2152
4
	free(fds);
2153
4
	return 1;
2154
12
}
2155
#endif