]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/speed.c
update ordinals
[thirdparty/openssl.git] / apps / speed.c
CommitLineData
7876e448 1/* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
58964a49 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
d02b48c6
RE
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.
0f113f3e 8 *
d02b48c6
RE
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).
0f113f3e 15 *
d02b48c6
RE
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.
0f113f3e 22 *
d02b48c6
RE
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 :-).
0f113f3e 37 * 4. If you include any Windows specific code (or a derivative thereof) from
d02b48c6
RE
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
0f113f3e 40 *
d02b48c6
RE
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.
0f113f3e 52 *
d02b48c6
RE
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 */
e172d60d 58/* ====================================================================
7e965dcc 59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
e172d60d 60 *
0f113f3e 61 * Portions of the attached software ("Contribution") are developed by
e172d60d
BM
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 *
0f113f3e 67 * The ECDH and ECDSA speed test software is originally written by
e172d60d
BM
68 * Sumit Gupta of Sun Microsystems Laboratories.
69 *
70 */
d02b48c6 71
a00ae6c4
RS
72#undef SECONDS
73#define SECONDS 3
74#define PRIME_SECONDS 10
75#define RSA_SECONDS 10
76#define DSA_SECONDS 10
77#define ECDSA_SECONDS 10
78#define ECDH_SECONDS 10
79
80#undef PROG
81#define PROG speed_main
82
83#include <stdio.h>
84#include <stdlib.h>
85
86#include <string.h>
87#include <math.h>
88#include "apps.h"
89#include <openssl/crypto.h>
90#include <openssl/rand.h>
91#include <openssl/err.h>
92#include <openssl/evp.h>
93#include <openssl/objects.h>
94#if !defined(OPENSSL_SYS_MSDOS)
95# include OPENSSL_UNISTD
96#endif
d02b48c6 97
a00ae6c4
RS
98#ifndef OPENSSL_SYS_NETWARE
99# include <signal.h>
100#endif
4d8743f4 101
a00ae6c4
RS
102#if defined(_WIN32) || defined(__CYGWIN__)
103# include <windows.h>
104# if defined(__CYGWIN__) && !defined(_WIN32)
0f113f3e
MC
105 /*
106 * <windows.h> should define _WIN32, which normally is mutually exclusive
107 * with __CYGWIN__, but if it didn't...
108 */
a00ae6c4 109# define _WIN32
bdba4595 110 /* this is done because Cygwin alarm() fails sometimes. */
0f113f3e 111# endif
a00ae6c4 112#endif
d02b48c6 113
a00ae6c4
RS
114#include <openssl/bn.h>
115#ifndef OPENSSL_NO_DES
116# include <openssl/des.h>
117#endif
118#ifndef OPENSSL_NO_AES
119# include <openssl/aes.h>
120#endif
121#ifndef OPENSSL_NO_CAMELLIA
122# include <openssl/camellia.h>
123#endif
124#ifndef OPENSSL_NO_MD2
125# include <openssl/md2.h>
126#endif
127#ifndef OPENSSL_NO_MDC2
128# include <openssl/mdc2.h>
129#endif
130#ifndef OPENSSL_NO_MD4
131# include <openssl/md4.h>
132#endif
133#ifndef OPENSSL_NO_MD5
134# include <openssl/md5.h>
135#endif
a00ae6c4 136# include <openssl/hmac.h>
a00ae6c4 137#include <openssl/evp.h>
a00ae6c4 138# include <openssl/sha.h>
a00ae6c4
RS
139#ifndef OPENSSL_NO_RMD160
140# include <openssl/ripemd.h>
141#endif
142#ifndef OPENSSL_NO_WHIRLPOOL
143# include <openssl/whrlpool.h>
144#endif
145#ifndef OPENSSL_NO_RC4
146# include <openssl/rc4.h>
147#endif
148#ifndef OPENSSL_NO_RC5
149# include <openssl/rc5.h>
150#endif
151#ifndef OPENSSL_NO_RC2
152# include <openssl/rc2.h>
153#endif
154#ifndef OPENSSL_NO_IDEA
155# include <openssl/idea.h>
156#endif
157#ifndef OPENSSL_NO_SEED
158# include <openssl/seed.h>
159#endif
160#ifndef OPENSSL_NO_BF
161# include <openssl/blowfish.h>
162#endif
163#ifndef OPENSSL_NO_CAST
164# include <openssl/cast.h>
165#endif
166#ifndef OPENSSL_NO_RSA
167# include <openssl/rsa.h>
168# include "./testrsa.h"
169#endif
170#include <openssl/x509.h>
171#ifndef OPENSSL_NO_DSA
172# include <openssl/dsa.h>
173# include "./testdsa.h"
174#endif
10bf4fc2 175#ifndef OPENSSL_NO_EC
a00ae6c4 176# include <openssl/ecdsa.h>
a00ae6c4
RS
177# include <openssl/ecdh.h>
178#endif
179#include <openssl/modes.h>
b5419b81 180
a00ae6c4 181#include <openssl/bn.h>
ebaa2cf5 182
a00ae6c4
RS
183#ifndef HAVE_FORK
184# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
185# define HAVE_FORK 0
0f113f3e 186# else
a00ae6c4 187# define HAVE_FORK 1
0f113f3e 188# endif
a00ae6c4 189#endif
66d3e748 190
a00ae6c4
RS
191#if HAVE_FORK
192# undef NO_FORK
193#else
194# define NO_FORK
195#endif
196
197#undef BUFSIZE
198#define BUFSIZE (1024*8+1)
199#define MAX_MISALIGNMENT 63
e2d03db4 200
0f113f3e 201static volatile int run = 0;
d02b48c6 202
0f113f3e
MC
203static int mr = 0;
204static int usertime = 1;
7876e448 205
0e211563 206static double Time_F(int s);
0f113f3e 207static void print_message(const char *s, long num, int length);
689c6f25 208static void pkey_print_message(const char *str, const char *str2,
0f113f3e
MC
209 long num, int bits, int sec);
210static void print_result(int alg, int run_no, int count, double time_used);
a00ae6c4 211#ifndef NO_FORK
0e211563 212static int do_multi(int multi);
a00ae6c4 213#endif
0f113f3e 214
a00ae6c4
RS
215#define ALGOR_NUM 30
216#define SIZE_NUM 5
217#define PRIME_NUM 3
218#define RSA_NUM 7
219#define DSA_NUM 3
0f113f3e 220
a00ae6c4
RS
221#define EC_NUM 16
222#define MAX_ECDH_SIZE 256
0f113f3e
MC
223
224static const char *names[ALGOR_NUM] = {
225 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
226 "des cbc", "des ede3", "idea cbc", "seed cbc",
227 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
228 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
229 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
230 "evp", "sha256", "sha512", "whirlpool",
231 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
232};
d02b48c6 233
0e211563 234static double results[ALGOR_NUM][SIZE_NUM];
0f113f3e
MC
235static int lengths[SIZE_NUM] = { 16, 64, 256, 1024, 8 * 1024 };
236
a00ae6c4 237#ifndef OPENSSL_NO_RSA
0e211563 238static double rsa_results[RSA_NUM][2];
a00ae6c4
RS
239#endif
240#ifndef OPENSSL_NO_DSA
0e211563 241static double dsa_results[DSA_NUM][2];
a00ae6c4 242#endif
10bf4fc2 243#ifndef OPENSSL_NO_EC
e172d60d
BM
244static double ecdsa_results[EC_NUM][2];
245static double ecdh_results[EC_NUM][1];
a00ae6c4 246#endif
e172d60d 247
10bf4fc2 248#if defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_EC)
0f113f3e
MC
249static const char rnd_seed[] =
250 "string to make the random number generator think it has entropy";
3eeaab4b 251static int rnd_fake = 0;
a00ae6c4 252#endif
0e211563 253
a00ae6c4
RS
254#ifdef SIGALRM
255# if defined(__STDC__) || defined(sgi) || defined(_AIX)
256# define SIGRETTYPE void
257# else
258# define SIGRETTYPE int
259# endif
b83eddc5 260
d02b48c6 261static SIGRETTYPE sig_done(int sig);
6b691a5c 262static SIGRETTYPE sig_done(int sig)
0f113f3e
MC
263{
264 signal(SIGALRM, sig_done);
265 run = 0;
266}
a00ae6c4 267#endif
d02b48c6 268
a00ae6c4
RS
269#define START 0
270#define STOP 1
d02b48c6 271
a00ae6c4 272#if defined(_WIN32)
4d8743f4 273
a00ae6c4
RS
274# if !defined(SIGALRM)
275# define SIGALRM
276# endif
0f113f3e
MC
277static unsigned int lapse, schlock;
278static void alarm_win32(unsigned int secs)
279{
280 lapse = secs * 1000;
281}
4d8743f4 282
a00ae6c4 283# define alarm alarm_win32
0f113f3e
MC
284
285static DWORD WINAPI sleepy(VOID * arg)
286{
287 schlock = 1;
288 Sleep(lapse);
289 run = 0;
290 return 0;
291}
4e74239c 292
0a39d8f2 293static double Time_F(int s)
0f113f3e
MC
294{
295 double ret;
296 static HANDLE thr;
297
298 if (s == START) {
299 schlock = 0;
300 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
301 if (thr == NULL) {
302 DWORD ret = GetLastError();
303 BIO_printf(bio_err, "unable to CreateThread (%d)", ret);
304 ExitProcess(ret);
305 }
306 while (!schlock)
307 Sleep(0); /* scheduler spinlock */
308 ret = app_tminterval(s, usertime);
309 } else {
310 ret = app_tminterval(s, usertime);
311 if (run)
312 TerminateThread(thr, 0);
313 CloseHandle(thr);
314 }
315
316 return ret;
317}
a00ae6c4 318#else
d02b48c6 319
0f113f3e
MC
320static double Time_F(int s)
321{
322 double ret = app_tminterval(s, usertime);
323 if (s == STOP)
324 alarm(0);
325 return ret;
326}
a00ae6c4 327#endif
176f31dd 328
10bf4fc2 329#ifndef OPENSSL_NO_EC
176f31dd 330static const int KDF1_SHA1_len = 20;
0f113f3e
MC
331static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
332 size_t *outlen)
333{
0f113f3e
MC
334 if (*outlen < SHA_DIGEST_LENGTH)
335 return NULL;
474e469b 336 *outlen = SHA_DIGEST_LENGTH;
0f113f3e 337 return SHA1(in, inlen, out);
0f113f3e 338}
10bf4fc2 339#endif /* OPENSSL_NO_EC */
176f31dd 340
375a64e3 341static void multiblock_speed(const EVP_CIPHER *evp_cipher);
176f31dd 342
667ac4ec
RE
343int MAIN(int, char **);
344
6b691a5c 345int MAIN(int argc, char **argv)
0f113f3e
MC
346{
347 unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
348 unsigned char *buf = NULL, *buf2 = NULL;
349 int mret = 1;
350 long count = 0, save_count = 0;
351 int i, j, k;
a00ae6c4 352#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
0f113f3e 353 long rsa_count;
a00ae6c4
RS
354#endif
355#ifndef OPENSSL_NO_RSA
0f113f3e 356 unsigned rsa_num;
a00ae6c4 357#endif
0f113f3e 358 unsigned char md[EVP_MAX_MD_SIZE];
a00ae6c4 359#ifndef OPENSSL_NO_MD2
0f113f3e 360 unsigned char md2[MD2_DIGEST_LENGTH];
a00ae6c4
RS
361#endif
362#ifndef OPENSSL_NO_MDC2
0f113f3e 363 unsigned char mdc2[MDC2_DIGEST_LENGTH];
a00ae6c4
RS
364#endif
365#ifndef OPENSSL_NO_MD4
0f113f3e 366 unsigned char md4[MD4_DIGEST_LENGTH];
a00ae6c4
RS
367#endif
368#ifndef OPENSSL_NO_MD5
0f113f3e
MC
369 unsigned char md5[MD5_DIGEST_LENGTH];
370 unsigned char hmac[MD5_DIGEST_LENGTH];
a00ae6c4 371#endif
0f113f3e 372 unsigned char sha[SHA_DIGEST_LENGTH];
0f113f3e 373 unsigned char sha256[SHA256_DIGEST_LENGTH];
0f113f3e 374 unsigned char sha512[SHA512_DIGEST_LENGTH];
a00ae6c4 375#ifndef OPENSSL_NO_WHIRLPOOL
0f113f3e 376 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
a00ae6c4
RS
377#endif
378#ifndef OPENSSL_NO_RMD160
0f113f3e 379 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
a00ae6c4
RS
380#endif
381#ifndef OPENSSL_NO_RC4
0f113f3e 382 RC4_KEY rc4_ks;
a00ae6c4
RS
383#endif
384#ifndef OPENSSL_NO_RC5
0f113f3e 385 RC5_32_KEY rc5_ks;
a00ae6c4
RS
386#endif
387#ifndef OPENSSL_NO_RC2
0f113f3e 388 RC2_KEY rc2_ks;
a00ae6c4
RS
389#endif
390#ifndef OPENSSL_NO_IDEA
0f113f3e 391 IDEA_KEY_SCHEDULE idea_ks;
a00ae6c4
RS
392#endif
393#ifndef OPENSSL_NO_SEED
0f113f3e 394 SEED_KEY_SCHEDULE seed_ks;
a00ae6c4
RS
395#endif
396#ifndef OPENSSL_NO_BF
0f113f3e 397 BF_KEY bf_ks;
a00ae6c4
RS
398#endif
399#ifndef OPENSSL_NO_CAST
0f113f3e 400 CAST_KEY cast_ks;
a00ae6c4 401#endif
0f113f3e
MC
402 static const unsigned char key16[16] = {
403 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
404 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
405 };
a00ae6c4 406#ifndef OPENSSL_NO_AES
0f113f3e
MC
407 static const unsigned char key24[24] = {
408 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
409 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
410 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
411 };
412 static const unsigned char key32[32] = {
413 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
414 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
415 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
416 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
417 };
a00ae6c4
RS
418#endif
419#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
420 static const unsigned char ckey24[24] = {
421 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
422 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
423 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
424 };
425 static const unsigned char ckey32[32] = {
426 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
427 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
428 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
429 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
430 };
a00ae6c4
RS
431#endif
432#ifndef OPENSSL_NO_AES
433# define MAX_BLOCK_SIZE 128
434#else
435# define MAX_BLOCK_SIZE 64
436#endif
0f113f3e
MC
437 unsigned char DES_iv[8];
438 unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
a00ae6c4 439#ifndef OPENSSL_NO_DES
0f113f3e
MC
440 static DES_cblock key =
441 { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
442 static DES_cblock key2 =
443 { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
444 static DES_cblock key3 =
445 { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
446 DES_key_schedule sch;
447 DES_key_schedule sch2;
448 DES_key_schedule sch3;
a00ae6c4
RS
449#endif
450#ifndef OPENSSL_NO_AES
0f113f3e 451 AES_KEY aes_ks1, aes_ks2, aes_ks3;
a00ae6c4
RS
452#endif
453#ifndef OPENSSL_NO_CAMELLIA
0f113f3e 454 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
a00ae6c4
RS
455#endif
456#define D_MD2 0
457#define D_MDC2 1
458#define D_MD4 2
459#define D_MD5 3
460#define D_HMAC 4
461#define D_SHA1 5
462#define D_RMD160 6
463#define D_RC4 7
464#define D_CBC_DES 8
465#define D_EDE3_DES 9
466#define D_CBC_IDEA 10
467#define D_CBC_SEED 11
468#define D_CBC_RC2 12
469#define D_CBC_RC5 13
470#define D_CBC_BF 14
471#define D_CBC_CAST 15
472#define D_CBC_128_AES 16
473#define D_CBC_192_AES 17
474#define D_CBC_256_AES 18
475#define D_CBC_128_CML 19
476#define D_CBC_192_CML 20
477#define D_CBC_256_CML 21
478#define D_EVP 22
479#define D_SHA256 23
480#define D_SHA512 24
481#define D_WHIRLPOOL 25
482#define D_IGE_128_AES 26
483#define D_IGE_192_AES 27
484#define D_IGE_256_AES 28
485#define D_GHASH 29
0f113f3e
MC
486 double d = 0.0;
487 long c[ALGOR_NUM][SIZE_NUM];
488
a00ae6c4
RS
489#ifndef OPENSSL_SYS_WIN32
490#endif
491#define R_DSA_512 0
492#define R_DSA_1024 1
493#define R_DSA_2048 2
494#define R_RSA_512 0
495#define R_RSA_1024 1
496#define R_RSA_2048 2
497#define R_RSA_3072 3
498#define R_RSA_4096 4
499#define R_RSA_7680 5
500#define R_RSA_15360 6
501
502#define R_EC_P160 0
503#define R_EC_P192 1
504#define R_EC_P224 2
505#define R_EC_P256 3
506#define R_EC_P384 4
507#define R_EC_P521 5
508#define R_EC_K163 6
509#define R_EC_K233 7
510#define R_EC_K283 8
511#define R_EC_K409 9
512#define R_EC_K571 10
513#define R_EC_B163 11
514#define R_EC_B233 12
515#define R_EC_B283 13
516#define R_EC_B409 14
517#define R_EC_B571 15
518
519#ifndef OPENSSL_NO_RSA
0f113f3e
MC
520 RSA *rsa_key[RSA_NUM];
521 long rsa_c[RSA_NUM][2];
522 static unsigned int rsa_bits[RSA_NUM] = {
523 512, 1024, 2048, 3072, 4096, 7680, 15360
524 };
525 static unsigned char *rsa_data[RSA_NUM] = {
526 test512, test1024, test2048, test3072, test4096, test7680, test15360
527 };
528 static int rsa_data_length[RSA_NUM] = {
529 sizeof(test512), sizeof(test1024),
530 sizeof(test2048), sizeof(test3072),
531 sizeof(test4096), sizeof(test7680),
532 sizeof(test15360)
533 };
a00ae6c4
RS
534#endif
535#ifndef OPENSSL_NO_DSA
0f113f3e
MC
536 DSA *dsa_key[DSA_NUM];
537 long dsa_c[DSA_NUM][2];
538 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
a00ae6c4
RS
539#endif
540#ifndef OPENSSL_NO_EC
0f113f3e
MC
541 /*
542 * We only test over the following curves as they are representative, To
543 * add tests over more curves, simply add the curve NID and curve name to
544 * the following arrays and increase the EC_NUM value accordingly.
545 */
546 static unsigned int test_curves[EC_NUM] = {
547 /* Prime Curves */
548 NID_secp160r1,
549 NID_X9_62_prime192v1,
550 NID_secp224r1,
551 NID_X9_62_prime256v1,
552 NID_secp384r1,
553 NID_secp521r1,
554 /* Binary Curves */
555 NID_sect163k1,
556 NID_sect233k1,
557 NID_sect283k1,
558 NID_sect409k1,
559 NID_sect571k1,
560 NID_sect163r2,
561 NID_sect233r1,
562 NID_sect283r1,
563 NID_sect409r1,
564 NID_sect571r1
565 };
566 static const char *test_curves_names[EC_NUM] = {
567 /* Prime Curves */
568 "secp160r1",
569 "nistp192",
570 "nistp224",
571 "nistp256",
572 "nistp384",
573 "nistp521",
574 /* Binary Curves */
575 "nistk163",
576 "nistk233",
577 "nistk283",
578 "nistk409",
579 "nistk571",
580 "nistb163",
581 "nistb233",
582 "nistb283",
583 "nistb409",
584 "nistb571"
585 };
586 static int test_curves_bits[EC_NUM] = {
5c6bf031 587 160, 192, 224, 256, 384, 521,
e172d60d
BM
588 163, 233, 283, 409, 571,
589 163, 233, 283, 409, 571
0f113f3e 590 };
e172d60d 591
a00ae6c4 592#endif
e172d60d 593
10bf4fc2 594#ifndef OPENSSL_NO_EC
0f113f3e
MC
595 unsigned char ecdsasig[256];
596 unsigned int ecdsasiglen;
597 EC_KEY *ecdsa[EC_NUM];
598 long ecdsa_c[EC_NUM][2];
0f113f3e
MC
599 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
600 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
601 int secret_size_a, secret_size_b;
602 int ecdh_checks = 0;
603 int secret_idx = 0;
604 long ecdh_c[EC_NUM][2];
10bf4fc2
RS
605 int ecdsa_doit[EC_NUM];
606 int ecdh_doit[EC_NUM];
a00ae6c4 607#endif
e172d60d 608
0f113f3e
MC
609 int rsa_doit[RSA_NUM];
610 int dsa_doit[DSA_NUM];
0f113f3e
MC
611 int doit[ALGOR_NUM];
612 int pr_header = 0;
613 const EVP_CIPHER *evp_cipher = NULL;
614 const EVP_MD *evp_md = NULL;
615 int decrypt = 0;
a00ae6c4 616#ifndef NO_FORK
0f113f3e 617 int multi = 0;
a00ae6c4 618#endif
0f113f3e
MC
619 int multiblock = 0;
620 int misalign = MAX_MISALIGNMENT + 1;
4e74239c 621
a00ae6c4 622#ifndef TIMES
0f113f3e 623 usertime = -1;
a00ae6c4 624#endif
d02b48c6 625
0f113f3e
MC
626 apps_startup();
627 memset(results, 0, sizeof(results));
a00ae6c4 628#ifndef OPENSSL_NO_DSA
0f113f3e 629 memset(dsa_key, 0, sizeof(dsa_key));
a00ae6c4 630#endif
10bf4fc2 631#ifndef OPENSSL_NO_EC
0f113f3e
MC
632 for (i = 0; i < EC_NUM; i++)
633 ecdsa[i] = NULL;
0f113f3e
MC
634 for (i = 0; i < EC_NUM; i++) {
635 ecdh_a[i] = NULL;
636 ecdh_b[i] = NULL;
637 }
a00ae6c4 638#endif
e172d60d 639
0f113f3e
MC
640 if (bio_err == NULL)
641 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
642 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
d02b48c6 643
0f113f3e
MC
644 if (!load_config(bio_err, NULL))
645 goto end;
d02b48c6 646
a00ae6c4 647#ifndef OPENSSL_NO_RSA
0f113f3e
MC
648 memset(rsa_key, 0, sizeof(rsa_key));
649 for (i = 0; i < RSA_NUM; i++)
650 rsa_key[i] = NULL;
a00ae6c4 651#endif
3647bee2 652
0f113f3e
MC
653 if ((buf_malloc =
654 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
655 BIO_printf(bio_err, "out of memory\n");
656 goto end;
657 }
658 if ((buf2_malloc =
659 (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
660 BIO_printf(bio_err, "out of memory\n");
661 goto end;
662 }
d02b48c6 663
0f113f3e
MC
664 misalign = 0; /* set later and buf/buf2 are adjusted
665 * accordingly */
666 buf = buf_malloc;
667 buf2 = buf2_malloc;
668
669 memset(c, 0, sizeof(c));
670 memset(DES_iv, 0, sizeof(DES_iv));
671 memset(iv, 0, sizeof(iv));
672
673 for (i = 0; i < ALGOR_NUM; i++)
674 doit[i] = 0;
675 for (i = 0; i < RSA_NUM; i++)
676 rsa_doit[i] = 0;
677 for (i = 0; i < DSA_NUM; i++)
678 dsa_doit[i] = 0;
10bf4fc2 679#ifndef OPENSSL_NO_EC
0f113f3e
MC
680 for (i = 0; i < EC_NUM; i++)
681 ecdsa_doit[i] = 0;
0f113f3e
MC
682 for (i = 0; i < EC_NUM; i++)
683 ecdh_doit[i] = 0;
a00ae6c4 684#endif
0f113f3e
MC
685
686 j = 0;
687 argc--;
688 argv++;
689 while (argc) {
690 if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
691 usertime = 0;
692 j--; /* Otherwise, -elapsed gets confused with an
693 * algorithm. */
694 } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
695 argc--;
696 argv++;
697 if (argc == 0) {
698 BIO_printf(bio_err, "no EVP given\n");
699 goto end;
700 }
701 evp_cipher = EVP_get_cipherbyname(*argv);
702 if (!evp_cipher) {
703 evp_md = EVP_get_digestbyname(*argv);
704 }
705 if (!evp_cipher && !evp_md) {
706 BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
707 *argv);
708 goto end;
709 }
710 doit[D_EVP] = 1;
711 } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
712 decrypt = 1;
713 j--; /* Otherwise, -elapsed gets confused with an
714 * algorithm. */
715 }
a00ae6c4 716#ifndef OPENSSL_NO_ENGINE
0f113f3e
MC
717 else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
718 argc--;
719 argv++;
720 if (argc == 0) {
721 BIO_printf(bio_err, "no engine given\n");
722 goto end;
723 }
724 setup_engine(bio_err, *argv, 0);
725 /*
726 * j will be increased again further down. We just don't want
727 * speed to confuse an engine with an algorithm, especially when
728 * none is given (which means all of them should be run)
729 */
730 j--;
731 }
a00ae6c4
RS
732#endif
733#ifndef NO_FORK
0f113f3e
MC
734 else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
735 argc--;
736 argv++;
737 if (argc == 0) {
738 BIO_printf(bio_err, "no multi count given\n");
739 goto end;
740 }
741 multi = atoi(argv[0]);
742 if (multi <= 0) {
743 BIO_printf(bio_err, "bad multi count\n");
744 goto end;
745 }
746 j--; /* Otherwise, -mr gets confused with an
747 * algorithm. */
748 }
a00ae6c4 749#endif
0f113f3e
MC
750 else if (argc > 0 && !strcmp(*argv, "-mr")) {
751 mr = 1;
752 j--; /* Otherwise, -mr gets confused with an
753 * algorithm. */
754 } else if (argc > 0 && !strcmp(*argv, "-mb")) {
755 multiblock = 1;
756 j--;
757 } else if (argc > 0 && !strcmp(*argv, "-misalign")) {
758 argc--;
759 argv++;
760 if (argc == 0) {
761 BIO_printf(bio_err, "no misalignment given\n");
762 goto end;
763 }
764 misalign = atoi(argv[0]);
765 if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
766 BIO_printf(bio_err,
767 "misalignment is outsize permitted range 0-%d\n",
768 MAX_MISALIGNMENT);
769 goto end;
770 }
771 buf = buf_malloc + misalign;
772 buf2 = buf2_malloc + misalign;
773 j--;
774 } else
a00ae6c4 775#ifndef OPENSSL_NO_MD2
0f113f3e
MC
776 if (strcmp(*argv, "md2") == 0)
777 doit[D_MD2] = 1;
778 else
a00ae6c4
RS
779#endif
780#ifndef OPENSSL_NO_MDC2
0f113f3e
MC
781 if (strcmp(*argv, "mdc2") == 0)
782 doit[D_MDC2] = 1;
783 else
a00ae6c4
RS
784#endif
785#ifndef OPENSSL_NO_MD4
0f113f3e
MC
786 if (strcmp(*argv, "md4") == 0)
787 doit[D_MD4] = 1;
788 else
a00ae6c4
RS
789#endif
790#ifndef OPENSSL_NO_MD5
0f113f3e
MC
791 if (strcmp(*argv, "md5") == 0)
792 doit[D_MD5] = 1;
793 else
a00ae6c4
RS
794#endif
795#ifndef OPENSSL_NO_MD5
0f113f3e
MC
796 if (strcmp(*argv, "hmac") == 0)
797 doit[D_HMAC] = 1;
798 else
a00ae6c4 799#endif
0f113f3e
MC
800 if (strcmp(*argv, "sha1") == 0)
801 doit[D_SHA1] = 1;
802 else if (strcmp(*argv, "sha") == 0)
803 doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
474e469b 804 else if (strcmp(*argv, "sha256") == 0)
0f113f3e 805 doit[D_SHA256] = 1;
474e469b 806 else if (strcmp(*argv, "sha512") == 0)
0f113f3e
MC
807 doit[D_SHA512] = 1;
808 else
a00ae6c4 809#ifndef OPENSSL_NO_WHIRLPOOL
0f113f3e
MC
810 if (strcmp(*argv, "whirlpool") == 0)
811 doit[D_WHIRLPOOL] = 1;
812 else
a00ae6c4
RS
813#endif
814#ifndef OPENSSL_NO_RMD160
0f113f3e
MC
815 if (strcmp(*argv, "ripemd") == 0)
816 doit[D_RMD160] = 1;
817 else if (strcmp(*argv, "rmd160") == 0)
818 doit[D_RMD160] = 1;
819 else if (strcmp(*argv, "ripemd160") == 0)
820 doit[D_RMD160] = 1;
821 else
a00ae6c4
RS
822#endif
823#ifndef OPENSSL_NO_RC4
0f113f3e
MC
824 if (strcmp(*argv, "rc4") == 0)
825 doit[D_RC4] = 1;
826 else
a00ae6c4
RS
827#endif
828#ifndef OPENSSL_NO_DES
0f113f3e
MC
829 if (strcmp(*argv, "des-cbc") == 0)
830 doit[D_CBC_DES] = 1;
831 else if (strcmp(*argv, "des-ede3") == 0)
832 doit[D_EDE3_DES] = 1;
833 else
a00ae6c4
RS
834#endif
835#ifndef OPENSSL_NO_AES
0f113f3e
MC
836 if (strcmp(*argv, "aes-128-cbc") == 0)
837 doit[D_CBC_128_AES] = 1;
838 else if (strcmp(*argv, "aes-192-cbc") == 0)
839 doit[D_CBC_192_AES] = 1;
840 else if (strcmp(*argv, "aes-256-cbc") == 0)
841 doit[D_CBC_256_AES] = 1;
842 else if (strcmp(*argv, "aes-128-ige") == 0)
843 doit[D_IGE_128_AES] = 1;
844 else if (strcmp(*argv, "aes-192-ige") == 0)
845 doit[D_IGE_192_AES] = 1;
846 else if (strcmp(*argv, "aes-256-ige") == 0)
847 doit[D_IGE_256_AES] = 1;
848 else
a00ae6c4
RS
849#endif
850#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
851 if (strcmp(*argv, "camellia-128-cbc") == 0)
852 doit[D_CBC_128_CML] = 1;
853 else if (strcmp(*argv, "camellia-192-cbc") == 0)
854 doit[D_CBC_192_CML] = 1;
855 else if (strcmp(*argv, "camellia-256-cbc") == 0)
856 doit[D_CBC_256_CML] = 1;
857 else
a00ae6c4
RS
858#endif
859#ifndef OPENSSL_NO_RSA
a00ae6c4 860# ifndef RSA_NULL
0f113f3e
MC
861 if (strcmp(*argv, "openssl") == 0) {
862 RSA_set_default_method(RSA_PKCS1_SSLeay());
863 j--;
864 } else
a00ae6c4
RS
865# endif
866#endif /* !OPENSSL_NO_RSA */
0f113f3e
MC
867 if (strcmp(*argv, "dsa512") == 0)
868 dsa_doit[R_DSA_512] = 2;
869 else if (strcmp(*argv, "dsa1024") == 0)
870 dsa_doit[R_DSA_1024] = 2;
871 else if (strcmp(*argv, "dsa2048") == 0)
872 dsa_doit[R_DSA_2048] = 2;
873 else if (strcmp(*argv, "rsa512") == 0)
874 rsa_doit[R_RSA_512] = 2;
875 else if (strcmp(*argv, "rsa1024") == 0)
876 rsa_doit[R_RSA_1024] = 2;
877 else if (strcmp(*argv, "rsa2048") == 0)
878 rsa_doit[R_RSA_2048] = 2;
879 else if (strcmp(*argv, "rsa3072") == 0)
880 rsa_doit[R_RSA_3072] = 2;
881 else if (strcmp(*argv, "rsa4096") == 0)
882 rsa_doit[R_RSA_4096] = 2;
883 else if (strcmp(*argv, "rsa7680") == 0)
884 rsa_doit[R_RSA_7680] = 2;
885 else if (strcmp(*argv, "rsa15360") == 0)
886 rsa_doit[R_RSA_15360] = 2;
887 else
a00ae6c4 888#ifndef OPENSSL_NO_RC2
0f113f3e
MC
889 if (strcmp(*argv, "rc2-cbc") == 0)
890 doit[D_CBC_RC2] = 1;
891 else if (strcmp(*argv, "rc2") == 0)
892 doit[D_CBC_RC2] = 1;
893 else
a00ae6c4
RS
894#endif
895#ifndef OPENSSL_NO_RC5
0f113f3e
MC
896 if (strcmp(*argv, "rc5-cbc") == 0)
897 doit[D_CBC_RC5] = 1;
898 else if (strcmp(*argv, "rc5") == 0)
899 doit[D_CBC_RC5] = 1;
900 else
a00ae6c4
RS
901#endif
902#ifndef OPENSSL_NO_IDEA
0f113f3e
MC
903 if (strcmp(*argv, "idea-cbc") == 0)
904 doit[D_CBC_IDEA] = 1;
905 else if (strcmp(*argv, "idea") == 0)
906 doit[D_CBC_IDEA] = 1;
907 else
a00ae6c4
RS
908#endif
909#ifndef OPENSSL_NO_SEED
0f113f3e
MC
910 if (strcmp(*argv, "seed-cbc") == 0)
911 doit[D_CBC_SEED] = 1;
912 else if (strcmp(*argv, "seed") == 0)
913 doit[D_CBC_SEED] = 1;
914 else
a00ae6c4
RS
915#endif
916#ifndef OPENSSL_NO_BF
0f113f3e
MC
917 if (strcmp(*argv, "bf-cbc") == 0)
918 doit[D_CBC_BF] = 1;
919 else if (strcmp(*argv, "blowfish") == 0)
920 doit[D_CBC_BF] = 1;
921 else if (strcmp(*argv, "bf") == 0)
922 doit[D_CBC_BF] = 1;
923 else
a00ae6c4
RS
924#endif
925#ifndef OPENSSL_NO_CAST
0f113f3e
MC
926 if (strcmp(*argv, "cast-cbc") == 0)
927 doit[D_CBC_CAST] = 1;
928 else if (strcmp(*argv, "cast") == 0)
929 doit[D_CBC_CAST] = 1;
930 else if (strcmp(*argv, "cast5") == 0)
931 doit[D_CBC_CAST] = 1;
932 else
a00ae6c4
RS
933#endif
934#ifndef OPENSSL_NO_DES
0f113f3e
MC
935 if (strcmp(*argv, "des") == 0) {
936 doit[D_CBC_DES] = 1;
937 doit[D_EDE3_DES] = 1;
938 } else
a00ae6c4
RS
939#endif
940#ifndef OPENSSL_NO_AES
0f113f3e
MC
941 if (strcmp(*argv, "aes") == 0) {
942 doit[D_CBC_128_AES] = 1;
943 doit[D_CBC_192_AES] = 1;
944 doit[D_CBC_256_AES] = 1;
945 } else if (strcmp(*argv, "ghash") == 0) {
946 doit[D_GHASH] = 1;
947 } else
a00ae6c4
RS
948#endif
949#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
950 if (strcmp(*argv, "camellia") == 0) {
951 doit[D_CBC_128_CML] = 1;
952 doit[D_CBC_192_CML] = 1;
953 doit[D_CBC_256_CML] = 1;
954 } else
a00ae6c4
RS
955#endif
956#ifndef OPENSSL_NO_RSA
0f113f3e
MC
957 if (strcmp(*argv, "rsa") == 0) {
958 rsa_doit[R_RSA_512] = 1;
959 rsa_doit[R_RSA_1024] = 1;
960 rsa_doit[R_RSA_2048] = 1;
961 rsa_doit[R_RSA_3072] = 1;
962 rsa_doit[R_RSA_4096] = 1;
963 rsa_doit[R_RSA_7680] = 1;
964 rsa_doit[R_RSA_15360] = 1;
965 } else
a00ae6c4
RS
966#endif
967#ifndef OPENSSL_NO_DSA
0f113f3e
MC
968 if (strcmp(*argv, "dsa") == 0) {
969 dsa_doit[R_DSA_512] = 1;
970 dsa_doit[R_DSA_1024] = 1;
971 dsa_doit[R_DSA_2048] = 1;
972 } else
a00ae6c4 973#endif
10bf4fc2 974#ifndef OPENSSL_NO_EC
0f113f3e
MC
975 if (strcmp(*argv, "ecdsap160") == 0)
976 ecdsa_doit[R_EC_P160] = 2;
977 else if (strcmp(*argv, "ecdsap192") == 0)
978 ecdsa_doit[R_EC_P192] = 2;
979 else if (strcmp(*argv, "ecdsap224") == 0)
980 ecdsa_doit[R_EC_P224] = 2;
981 else if (strcmp(*argv, "ecdsap256") == 0)
982 ecdsa_doit[R_EC_P256] = 2;
983 else if (strcmp(*argv, "ecdsap384") == 0)
984 ecdsa_doit[R_EC_P384] = 2;
985 else if (strcmp(*argv, "ecdsap521") == 0)
986 ecdsa_doit[R_EC_P521] = 2;
987 else if (strcmp(*argv, "ecdsak163") == 0)
988 ecdsa_doit[R_EC_K163] = 2;
989 else if (strcmp(*argv, "ecdsak233") == 0)
990 ecdsa_doit[R_EC_K233] = 2;
991 else if (strcmp(*argv, "ecdsak283") == 0)
992 ecdsa_doit[R_EC_K283] = 2;
993 else if (strcmp(*argv, "ecdsak409") == 0)
994 ecdsa_doit[R_EC_K409] = 2;
995 else if (strcmp(*argv, "ecdsak571") == 0)
996 ecdsa_doit[R_EC_K571] = 2;
997 else if (strcmp(*argv, "ecdsab163") == 0)
998 ecdsa_doit[R_EC_B163] = 2;
999 else if (strcmp(*argv, "ecdsab233") == 0)
1000 ecdsa_doit[R_EC_B233] = 2;
1001 else if (strcmp(*argv, "ecdsab283") == 0)
1002 ecdsa_doit[R_EC_B283] = 2;
1003 else if (strcmp(*argv, "ecdsab409") == 0)
1004 ecdsa_doit[R_EC_B409] = 2;
1005 else if (strcmp(*argv, "ecdsab571") == 0)
1006 ecdsa_doit[R_EC_B571] = 2;
1007 else if (strcmp(*argv, "ecdsa") == 0) {
1008 for (i = 0; i < EC_NUM; i++)
1009 ecdsa_doit[i] = 1;
10bf4fc2 1010 } else if (strcmp(*argv, "ecdhp160") == 0)
0f113f3e
MC
1011 ecdh_doit[R_EC_P160] = 2;
1012 else if (strcmp(*argv, "ecdhp192") == 0)
1013 ecdh_doit[R_EC_P192] = 2;
1014 else if (strcmp(*argv, "ecdhp224") == 0)
1015 ecdh_doit[R_EC_P224] = 2;
1016 else if (strcmp(*argv, "ecdhp256") == 0)
1017 ecdh_doit[R_EC_P256] = 2;
1018 else if (strcmp(*argv, "ecdhp384") == 0)
1019 ecdh_doit[R_EC_P384] = 2;
1020 else if (strcmp(*argv, "ecdhp521") == 0)
1021 ecdh_doit[R_EC_P521] = 2;
1022 else if (strcmp(*argv, "ecdhk163") == 0)
1023 ecdh_doit[R_EC_K163] = 2;
1024 else if (strcmp(*argv, "ecdhk233") == 0)
1025 ecdh_doit[R_EC_K233] = 2;
1026 else if (strcmp(*argv, "ecdhk283") == 0)
1027 ecdh_doit[R_EC_K283] = 2;
1028 else if (strcmp(*argv, "ecdhk409") == 0)
1029 ecdh_doit[R_EC_K409] = 2;
1030 else if (strcmp(*argv, "ecdhk571") == 0)
1031 ecdh_doit[R_EC_K571] = 2;
1032 else if (strcmp(*argv, "ecdhb163") == 0)
1033 ecdh_doit[R_EC_B163] = 2;
1034 else if (strcmp(*argv, "ecdhb233") == 0)
1035 ecdh_doit[R_EC_B233] = 2;
1036 else if (strcmp(*argv, "ecdhb283") == 0)
1037 ecdh_doit[R_EC_B283] = 2;
1038 else if (strcmp(*argv, "ecdhb409") == 0)
1039 ecdh_doit[R_EC_B409] = 2;
1040 else if (strcmp(*argv, "ecdhb571") == 0)
1041 ecdh_doit[R_EC_B571] = 2;
1042 else if (strcmp(*argv, "ecdh") == 0) {
1043 for (i = 0; i < EC_NUM; i++)
1044 ecdh_doit[i] = 1;
1045 } else
a00ae6c4 1046#endif
0f113f3e
MC
1047 {
1048 BIO_printf(bio_err, "Error: bad option or value\n");
1049 BIO_printf(bio_err, "\n");
1050 BIO_printf(bio_err, "Available values:\n");
a00ae6c4 1051#ifndef OPENSSL_NO_MD2
0f113f3e 1052 BIO_printf(bio_err, "md2 ");
a00ae6c4
RS
1053#endif
1054#ifndef OPENSSL_NO_MDC2
0f113f3e 1055 BIO_printf(bio_err, "mdc2 ");
a00ae6c4
RS
1056#endif
1057#ifndef OPENSSL_NO_MD4
0f113f3e 1058 BIO_printf(bio_err, "md4 ");
a00ae6c4
RS
1059#endif
1060#ifndef OPENSSL_NO_MD5
0f113f3e 1061 BIO_printf(bio_err, "md5 ");
0f113f3e 1062 BIO_printf(bio_err, "hmac ");
a00ae6c4 1063#endif
0f113f3e 1064 BIO_printf(bio_err, "sha1 ");
0f113f3e 1065 BIO_printf(bio_err, "sha256 ");
0f113f3e 1066 BIO_printf(bio_err, "sha512 ");
a00ae6c4 1067#ifndef OPENSSL_NO_WHIRLPOOL
0f113f3e 1068 BIO_printf(bio_err, "whirlpool");
a00ae6c4
RS
1069#endif
1070#ifndef OPENSSL_NO_RMD160
0f113f3e 1071 BIO_printf(bio_err, "rmd160");
a00ae6c4 1072#endif
0f113f3e 1073 BIO_printf(bio_err, "\n");
3009458e 1074
a00ae6c4 1075#ifndef OPENSSL_NO_IDEA
0f113f3e 1076 BIO_printf(bio_err, "idea-cbc ");
a00ae6c4
RS
1077#endif
1078#ifndef OPENSSL_NO_SEED
0f113f3e 1079 BIO_printf(bio_err, "seed-cbc ");
a00ae6c4
RS
1080#endif
1081#ifndef OPENSSL_NO_RC2
0f113f3e 1082 BIO_printf(bio_err, "rc2-cbc ");
a00ae6c4
RS
1083#endif
1084#ifndef OPENSSL_NO_RC5
0f113f3e 1085 BIO_printf(bio_err, "rc5-cbc ");
a00ae6c4
RS
1086#endif
1087#ifndef OPENSSL_NO_BF
0f113f3e 1088 BIO_printf(bio_err, "bf-cbc");
a00ae6c4
RS
1089#endif
1090#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
cf1b7d96 1091 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
0f113f3e 1092 BIO_printf(bio_err, "\n");
a00ae6c4
RS
1093#endif
1094#ifndef OPENSSL_NO_DES
0f113f3e 1095 BIO_printf(bio_err, "des-cbc des-ede3 ");
a00ae6c4
RS
1096#endif
1097#ifndef OPENSSL_NO_AES
0f113f3e
MC
1098 BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1099 BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
a00ae6c4
RS
1100#endif
1101#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
1102 BIO_printf(bio_err, "\n");
1103 BIO_printf(bio_err,
1104 "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
a00ae6c4
RS
1105#endif
1106#ifndef OPENSSL_NO_RC4
0f113f3e 1107 BIO_printf(bio_err, "rc4");
a00ae6c4 1108#endif
0f113f3e 1109 BIO_printf(bio_err, "\n");
3009458e 1110
a00ae6c4 1111#ifndef OPENSSL_NO_RSA
0f113f3e
MC
1112 BIO_printf(bio_err,
1113 "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1114 BIO_printf(bio_err, "rsa7680 rsa15360\n");
a00ae6c4 1115#endif
3009458e 1116
a00ae6c4 1117#ifndef OPENSSL_NO_DSA
0f113f3e 1118 BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
a00ae6c4 1119#endif
10bf4fc2 1120#ifndef OPENSSL_NO_EC
0f113f3e
MC
1121 BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
1122 "ecdsap256 ecdsap384 ecdsap521\n");
1123 BIO_printf(bio_err,
1124 "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1125 BIO_printf(bio_err,
1126 "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1127 BIO_printf(bio_err, "ecdsa\n");
0f113f3e
MC
1128 BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
1129 "ecdhp256 ecdhp384 ecdhp521\n");
1130 BIO_printf(bio_err,
1131 "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1132 BIO_printf(bio_err,
1133 "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1134 BIO_printf(bio_err, "ecdh\n");
a00ae6c4 1135#endif
3009458e 1136
a00ae6c4 1137#ifndef OPENSSL_NO_IDEA
0f113f3e 1138 BIO_printf(bio_err, "idea ");
a00ae6c4
RS
1139#endif
1140#ifndef OPENSSL_NO_SEED
0f113f3e 1141 BIO_printf(bio_err, "seed ");
a00ae6c4
RS
1142#endif
1143#ifndef OPENSSL_NO_RC2
0f113f3e 1144 BIO_printf(bio_err, "rc2 ");
a00ae6c4
RS
1145#endif
1146#ifndef OPENSSL_NO_DES
0f113f3e 1147 BIO_printf(bio_err, "des ");
a00ae6c4
RS
1148#endif
1149#ifndef OPENSSL_NO_AES
0f113f3e 1150 BIO_printf(bio_err, "aes ");
a00ae6c4
RS
1151#endif
1152#ifndef OPENSSL_NO_CAMELLIA
0f113f3e 1153 BIO_printf(bio_err, "camellia ");
a00ae6c4
RS
1154#endif
1155#ifndef OPENSSL_NO_RSA
0f113f3e 1156 BIO_printf(bio_err, "rsa ");
a00ae6c4
RS
1157#endif
1158#ifndef OPENSSL_NO_BF
0f113f3e 1159 BIO_printf(bio_err, "blowfish");
a00ae6c4
RS
1160#endif
1161#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
96afc1cf
BM
1162 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1163 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1164 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
0f113f3e 1165 BIO_printf(bio_err, "\n");
a00ae6c4 1166#endif
0e211563 1167
0f113f3e
MC
1168 BIO_printf(bio_err, "\n");
1169 BIO_printf(bio_err, "Available options:\n");
a00ae6c4 1170#if defined(TIMES) || defined(USE_TOD)
0f113f3e
MC
1171 BIO_printf(bio_err, "-elapsed "
1172 "measure time in real time instead of CPU user time.\n");
a00ae6c4
RS
1173#endif
1174#ifndef OPENSSL_NO_ENGINE
0f113f3e
MC
1175 BIO_printf(bio_err,
1176 "-engine e "
1177 "use engine e, possibly a hardware device.\n");
a00ae6c4 1178#endif
0f113f3e
MC
1179 BIO_printf(bio_err, "-evp e " "use EVP e.\n");
1180 BIO_printf(bio_err,
1181 "-decrypt "
1182 "time decryption instead of encryption (only EVP).\n");
1183 BIO_printf(bio_err,
1184 "-mr "
1185 "produce machine readable output.\n");
1186 BIO_printf(bio_err,
1187 "-mb "
1188 "perform multi-block benchmark (for specific ciphers)\n");
1189 BIO_printf(bio_err,
1190 "-misalign n "
1191 "perform benchmark with misaligned data\n");
a00ae6c4 1192#ifndef NO_FORK
0f113f3e
MC
1193 BIO_printf(bio_err,
1194 "-multi n " "run n benchmarks in parallel.\n");
a00ae6c4 1195#endif
0f113f3e
MC
1196 goto end;
1197 }
1198 argc--;
1199 argv++;
1200 j++;
1201 }
d02b48c6 1202
a00ae6c4 1203#ifndef NO_FORK
0f113f3e
MC
1204 if (multi && do_multi(multi))
1205 goto show_res;
a00ae6c4 1206#endif
d02b48c6 1207
0f113f3e
MC
1208 if (j == 0) {
1209 for (i = 0; i < ALGOR_NUM; i++) {
1210 if (i != D_EVP)
1211 doit[i] = 1;
1212 }
1213 for (i = 0; i < RSA_NUM; i++)
1214 rsa_doit[i] = 1;
1215 for (i = 0; i < DSA_NUM; i++)
1216 dsa_doit[i] = 1;
10bf4fc2 1217#ifndef OPENSSL_NO_EC
0f113f3e
MC
1218 for (i = 0; i < EC_NUM; i++)
1219 ecdsa_doit[i] = 1;
0f113f3e
MC
1220 for (i = 0; i < EC_NUM; i++)
1221 ecdh_doit[i] = 1;
a00ae6c4 1222#endif
0f113f3e
MC
1223 }
1224 for (i = 0; i < ALGOR_NUM; i++)
1225 if (doit[i])
1226 pr_header++;
1227
1228 if (usertime == 0 && !mr)
1229 BIO_printf(bio_err,
1230 "You have chosen to measure elapsed time "
1231 "instead of user CPU time.\n");
1232
a00ae6c4 1233#ifndef OPENSSL_NO_RSA
0f113f3e
MC
1234 for (i = 0; i < RSA_NUM; i++) {
1235 const unsigned char *p;
1236
1237 p = rsa_data[i];
1238 rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
1239 if (rsa_key[i] == NULL) {
1240 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1241 i);
1242 goto end;
1243 }
a00ae6c4
RS
1244 }
1245#endif
d02b48c6 1246
a00ae6c4 1247#ifndef OPENSSL_NO_DSA
0f113f3e
MC
1248 dsa_key[0] = get_dsa512();
1249 dsa_key[1] = get_dsa1024();
1250 dsa_key[2] = get_dsa2048();
a00ae6c4 1251#endif
d02b48c6 1252
a00ae6c4 1253#ifndef OPENSSL_NO_DES
0f113f3e
MC
1254 DES_set_key_unchecked(&key, &sch);
1255 DES_set_key_unchecked(&key2, &sch2);
1256 DES_set_key_unchecked(&key3, &sch3);
a00ae6c4
RS
1257#endif
1258#ifndef OPENSSL_NO_AES
0f113f3e
MC
1259 AES_set_encrypt_key(key16, 128, &aes_ks1);
1260 AES_set_encrypt_key(key24, 192, &aes_ks2);
1261 AES_set_encrypt_key(key32, 256, &aes_ks3);
a00ae6c4
RS
1262#endif
1263#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
1264 Camellia_set_key(key16, 128, &camellia_ks1);
1265 Camellia_set_key(ckey24, 192, &camellia_ks2);
1266 Camellia_set_key(ckey32, 256, &camellia_ks3);
a00ae6c4
RS
1267#endif
1268#ifndef OPENSSL_NO_IDEA
0f113f3e 1269 idea_set_encrypt_key(key16, &idea_ks);
a00ae6c4
RS
1270#endif
1271#ifndef OPENSSL_NO_SEED
0f113f3e 1272 SEED_set_key(key16, &seed_ks);
a00ae6c4
RS
1273#endif
1274#ifndef OPENSSL_NO_RC4
0f113f3e 1275 RC4_set_key(&rc4_ks, 16, key16);
a00ae6c4
RS
1276#endif
1277#ifndef OPENSSL_NO_RC2
0f113f3e 1278 RC2_set_key(&rc2_ks, 16, key16, 128);
a00ae6c4
RS
1279#endif
1280#ifndef OPENSSL_NO_RC5
0f113f3e 1281 RC5_32_set_key(&rc5_ks, 16, key16, 12);
a00ae6c4
RS
1282#endif
1283#ifndef OPENSSL_NO_BF
0f113f3e 1284 BF_set_key(&bf_ks, 16, key16);
a00ae6c4
RS
1285#endif
1286#ifndef OPENSSL_NO_CAST
0f113f3e 1287 CAST_set_key(&cast_ks, 16, key16);
a00ae6c4
RS
1288#endif
1289#ifndef OPENSSL_NO_RSA
0f113f3e 1290 memset(rsa_c, 0, sizeof(rsa_c));
a00ae6c4
RS
1291#endif
1292#ifndef SIGALRM
1293# ifndef OPENSSL_NO_DES
0f113f3e
MC
1294 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1295 count = 10;
1296 do {
1297 long it;
1298 count *= 2;
1299 Time_F(START);
1300 for (it = count; it; it--)
1301 DES_ecb_encrypt((DES_cblock *)buf,
1302 (DES_cblock *)buf, &sch, DES_ENCRYPT);
1303 d = Time_F(STOP);
1304 } while (d < 3);
1305 save_count = count;
1306 c[D_MD2][0] = count / 10;
1307 c[D_MDC2][0] = count / 10;
1308 c[D_MD4][0] = count;
1309 c[D_MD5][0] = count;
1310 c[D_HMAC][0] = count;
1311 c[D_SHA1][0] = count;
1312 c[D_RMD160][0] = count;
1313 c[D_RC4][0] = count * 5;
1314 c[D_CBC_DES][0] = count;
1315 c[D_EDE3_DES][0] = count / 3;
1316 c[D_CBC_IDEA][0] = count;
1317 c[D_CBC_SEED][0] = count;
1318 c[D_CBC_RC2][0] = count;
1319 c[D_CBC_RC5][0] = count;
1320 c[D_CBC_BF][0] = count;
1321 c[D_CBC_CAST][0] = count;
1322 c[D_CBC_128_AES][0] = count;
1323 c[D_CBC_192_AES][0] = count;
1324 c[D_CBC_256_AES][0] = count;
1325 c[D_CBC_128_CML][0] = count;
1326 c[D_CBC_192_CML][0] = count;
1327 c[D_CBC_256_CML][0] = count;
1328 c[D_SHA256][0] = count;
1329 c[D_SHA512][0] = count;
1330 c[D_WHIRLPOOL][0] = count;
1331 c[D_IGE_128_AES][0] = count;
1332 c[D_IGE_192_AES][0] = count;
1333 c[D_IGE_256_AES][0] = count;
1334 c[D_GHASH][0] = count;
1335
1336 for (i = 1; i < SIZE_NUM; i++) {
1337 long l0, l1;
1338
1339 l0 = (long)lengths[0];
1340 l1 = (long)lengths[i];
1341
1342 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1343 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1344 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1345 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1346 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1347 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1348 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1349 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1350 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1351 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
1352
1353 l0 = (long)lengths[i - 1];
1354
1355 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1356 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1357 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1358 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1359 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1360 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1361 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1362 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1363 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1364 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1365 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1366 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1367 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1368 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1369 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1370 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1371 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1372 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1373 }
e172d60d 1374
a00ae6c4 1375# ifndef OPENSSL_NO_RSA
0f113f3e
MC
1376 rsa_c[R_RSA_512][0] = count / 2000;
1377 rsa_c[R_RSA_512][1] = count / 400;
1378 for (i = 1; i < RSA_NUM; i++) {
1379 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1380 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1381 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1382 rsa_doit[i] = 0;
1383 else {
1384 if (rsa_c[i][0] == 0) {
1385 rsa_c[i][0] = 1;
1386 rsa_c[i][1] = 20;
1387 }
1388 }
1389 }
a00ae6c4 1390# endif
0f113f3e 1391
a00ae6c4 1392# ifndef OPENSSL_NO_DSA
0f113f3e
MC
1393 dsa_c[R_DSA_512][0] = count / 1000;
1394 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1395 for (i = 1; i < DSA_NUM; i++) {
1396 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1397 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1398 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1399 dsa_doit[i] = 0;
1400 else {
1401 if (dsa_c[i] == 0) {
1402 dsa_c[i][0] = 1;
1403 dsa_c[i][1] = 1;
1404 }
1405 }
1406 }
a00ae6c4 1407# endif
0f113f3e 1408
10bf4fc2 1409# ifndef OPENSSL_NO_EC
0f113f3e
MC
1410 ecdsa_c[R_EC_P160][0] = count / 1000;
1411 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1412 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1413 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1414 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1415 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1416 ecdsa_doit[i] = 0;
1417 else {
1418 if (ecdsa_c[i] == 0) {
1419 ecdsa_c[i][0] = 1;
1420 ecdsa_c[i][1] = 1;
1421 }
1422 }
1423 }
1424 ecdsa_c[R_EC_K163][0] = count / 1000;
1425 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1426 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1427 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1428 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1429 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1430 ecdsa_doit[i] = 0;
1431 else {
1432 if (ecdsa_c[i] == 0) {
1433 ecdsa_c[i][0] = 1;
1434 ecdsa_c[i][1] = 1;
1435 }
1436 }
1437 }
1438 ecdsa_c[R_EC_B163][0] = count / 1000;
1439 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1440 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1441 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1442 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1443 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1444 ecdsa_doit[i] = 0;
1445 else {
1446 if (ecdsa_c[i] == 0) {
1447 ecdsa_c[i][0] = 1;
1448 ecdsa_c[i][1] = 1;
1449 }
1450 }
1451 }
0f113f3e
MC
1452 ecdh_c[R_EC_P160][0] = count / 1000;
1453 ecdh_c[R_EC_P160][1] = count / 1000;
1454 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1455 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1456 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1457 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1458 ecdh_doit[i] = 0;
1459 else {
1460 if (ecdh_c[i] == 0) {
1461 ecdh_c[i][0] = 1;
1462 ecdh_c[i][1] = 1;
1463 }
1464 }
1465 }
1466 ecdh_c[R_EC_K163][0] = count / 1000;
1467 ecdh_c[R_EC_K163][1] = count / 1000;
1468 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1469 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1470 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1471 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1472 ecdh_doit[i] = 0;
1473 else {
1474 if (ecdh_c[i] == 0) {
1475 ecdh_c[i][0] = 1;
1476 ecdh_c[i][1] = 1;
1477 }
1478 }
1479 }
1480 ecdh_c[R_EC_B163][0] = count / 1000;
1481 ecdh_c[R_EC_B163][1] = count / 1000;
1482 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1483 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1484 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1485 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1486 ecdh_doit[i] = 0;
1487 else {
1488 if (ecdh_c[i] == 0) {
1489 ecdh_c[i][0] = 1;
1490 ecdh_c[i][1] = 1;
1491 }
1492 }
1493 }
a00ae6c4 1494# endif
e172d60d 1495
a00ae6c4
RS
1496# define COND(d) (count < (d))
1497# define COUNT(d) (d)
0f113f3e 1498# else
a00ae6c4
RS
1499/* not worth fixing */
1500# error "You cannot disable DES on systems without SIGALRM."
1501# endif /* OPENSSL_NO_DES */
1502#else
1503# define COND(c) (run && count<0x7fffffff)
1504# define COUNT(d) (count)
1505# ifndef _WIN32
0f113f3e 1506 signal(SIGALRM, sig_done);
a00ae6c4
RS
1507# endif
1508#endif /* SIGALRM */
0f113f3e 1509
a00ae6c4 1510#ifndef OPENSSL_NO_MD2
0f113f3e
MC
1511 if (doit[D_MD2]) {
1512 for (j = 0; j < SIZE_NUM; j++) {
1513 print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
1514 Time_F(START);
1515 for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
1516 EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
1517 EVP_md2(), NULL);
1518 d = Time_F(STOP);
1519 print_result(D_MD2, j, count, d);
1520 }
1521 }
a00ae6c4
RS
1522#endif
1523#ifndef OPENSSL_NO_MDC2
0f113f3e
MC
1524 if (doit[D_MDC2]) {
1525 for (j = 0; j < SIZE_NUM; j++) {
1526 print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
1527 Time_F(START);
1528 for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
1529 EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
1530 EVP_mdc2(), NULL);
1531 d = Time_F(STOP);
1532 print_result(D_MDC2, j, count, d);
1533 }
1534 }
a00ae6c4 1535#endif
d02b48c6 1536
a00ae6c4 1537#ifndef OPENSSL_NO_MD4
0f113f3e
MC
1538 if (doit[D_MD4]) {
1539 for (j = 0; j < SIZE_NUM; j++) {
1540 print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1541 Time_F(START);
1542 for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1543 EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
1544 NULL, EVP_md4(), NULL);
1545 d = Time_F(STOP);
1546 print_result(D_MD4, j, count, d);
1547 }
1548 }
a00ae6c4 1549#endif
3009458e 1550
a00ae6c4 1551#ifndef OPENSSL_NO_MD5
0f113f3e
MC
1552 if (doit[D_MD5]) {
1553 for (j = 0; j < SIZE_NUM; j++) {
1554 print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1555 Time_F(START);
1556 for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1557 MD5(buf, lengths[j], md5);
1558 d = Time_F(STOP);
1559 print_result(D_MD5, j, count, d);
1560 }
1561 }
a00ae6c4 1562#endif
d02b48c6 1563
a283d2a8 1564#if !defined(OPENSSL_NO_MD5)
0f113f3e
MC
1565 if (doit[D_HMAC]) {
1566 HMAC_CTX hctx;
1567
1568 HMAC_CTX_init(&hctx);
1569 HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
1570 16, EVP_md5(), NULL);
1571
1572 for (j = 0; j < SIZE_NUM; j++) {
1573 print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1574 Time_F(START);
1575 for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1576 HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1577 HMAC_Update(&hctx, buf, lengths[j]);
1578 HMAC_Final(&hctx, &(hmac[0]), NULL);
1579 }
1580 d = Time_F(STOP);
1581 print_result(D_HMAC, j, count, d);
1582 }
1583 HMAC_CTX_cleanup(&hctx);
1584 }
a00ae6c4 1585#endif
0f113f3e
MC
1586 if (doit[D_SHA1]) {
1587 for (j = 0; j < SIZE_NUM; j++) {
1588 print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1589 Time_F(START);
1590 for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
0f113f3e 1591 SHA1(buf, lengths[j], sha);
0f113f3e
MC
1592 d = Time_F(STOP);
1593 print_result(D_SHA1, j, count, d);
1594 }
1595 }
0f113f3e
MC
1596 if (doit[D_SHA256]) {
1597 for (j = 0; j < SIZE_NUM; j++) {
1598 print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1599 Time_F(START);
1600 for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1601 SHA256(buf, lengths[j], sha256);
1602 d = Time_F(STOP);
1603 print_result(D_SHA256, j, count, d);
1604 }
1605 }
0f113f3e
MC
1606 if (doit[D_SHA512]) {
1607 for (j = 0; j < SIZE_NUM; j++) {
1608 print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1609 Time_F(START);
1610 for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1611 SHA512(buf, lengths[j], sha512);
1612 d = Time_F(STOP);
1613 print_result(D_SHA512, j, count, d);
1614 }
1615 }
46ceb15c 1616
a00ae6c4 1617#ifndef OPENSSL_NO_WHIRLPOOL
0f113f3e
MC
1618 if (doit[D_WHIRLPOOL]) {
1619 for (j = 0; j < SIZE_NUM; j++) {
1620 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1621 Time_F(START);
1622 for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1623 WHIRLPOOL(buf, lengths[j], whirlpool);
1624 d = Time_F(STOP);
1625 print_result(D_WHIRLPOOL, j, count, d);
1626 }
1627 }
a00ae6c4 1628#endif
c88f8f76 1629
a00ae6c4 1630#ifndef OPENSSL_NO_RMD160
0f113f3e
MC
1631 if (doit[D_RMD160]) {
1632 for (j = 0; j < SIZE_NUM; j++) {
1633 print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1634 Time_F(START);
1635 for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1636 EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
1637 EVP_ripemd160(), NULL);
1638 d = Time_F(STOP);
1639 print_result(D_RMD160, j, count, d);
1640 }
1641 }
a00ae6c4
RS
1642#endif
1643#ifndef OPENSSL_NO_RC4
0f113f3e
MC
1644 if (doit[D_RC4]) {
1645 for (j = 0; j < SIZE_NUM; j++) {
1646 print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1647 Time_F(START);
1648 for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1649 RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
1650 d = Time_F(STOP);
1651 print_result(D_RC4, j, count, d);
1652 }
1653 }
a00ae6c4
RS
1654#endif
1655#ifndef OPENSSL_NO_DES
0f113f3e
MC
1656 if (doit[D_CBC_DES]) {
1657 for (j = 0; j < SIZE_NUM; j++) {
1658 print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1659 Time_F(START);
1660 for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1661 DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1662 &DES_iv, DES_ENCRYPT);
1663 d = Time_F(STOP);
1664 print_result(D_CBC_DES, j, count, d);
1665 }
1666 }
ae93dc13 1667
0f113f3e
MC
1668 if (doit[D_EDE3_DES]) {
1669 for (j = 0; j < SIZE_NUM; j++) {
1670 print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1671 Time_F(START);
1672 for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1673 DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1674 &sch, &sch2, &sch3,
1675 &DES_iv, DES_ENCRYPT);
1676 d = Time_F(STOP);
1677 print_result(D_EDE3_DES, j, count, d);
1678 }
1679 }
a00ae6c4
RS
1680#endif
1681#ifndef OPENSSL_NO_AES
0f113f3e
MC
1682 if (doit[D_CBC_128_AES]) {
1683 for (j = 0; j < SIZE_NUM; j++) {
1684 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
1685 lengths[j]);
1686 Time_F(START);
1687 for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1688 AES_cbc_encrypt(buf, buf,
1689 (unsigned long)lengths[j], &aes_ks1,
1690 iv, AES_ENCRYPT);
1691 d = Time_F(STOP);
1692 print_result(D_CBC_128_AES, j, count, d);
1693 }
1694 }
1695 if (doit[D_CBC_192_AES]) {
1696 for (j = 0; j < SIZE_NUM; j++) {
1697 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
1698 lengths[j]);
1699 Time_F(START);
1700 for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1701 AES_cbc_encrypt(buf, buf,
1702 (unsigned long)lengths[j], &aes_ks2,
1703 iv, AES_ENCRYPT);
1704 d = Time_F(STOP);
1705 print_result(D_CBC_192_AES, j, count, d);
1706 }
1707 }
1708 if (doit[D_CBC_256_AES]) {
1709 for (j = 0; j < SIZE_NUM; j++) {
1710 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
1711 lengths[j]);
1712 Time_F(START);
1713 for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1714 AES_cbc_encrypt(buf, buf,
1715 (unsigned long)lengths[j], &aes_ks3,
1716 iv, AES_ENCRYPT);
1717 d = Time_F(STOP);
1718 print_result(D_CBC_256_AES, j, count, d);
1719 }
1720 }
5f09d0ec 1721
0f113f3e
MC
1722 if (doit[D_IGE_128_AES]) {
1723 for (j = 0; j < SIZE_NUM; j++) {
1724 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
1725 lengths[j]);
1726 Time_F(START);
1727 for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1728 AES_ige_encrypt(buf, buf2,
1729 (unsigned long)lengths[j], &aes_ks1,
1730 iv, AES_ENCRYPT);
1731 d = Time_F(STOP);
1732 print_result(D_IGE_128_AES, j, count, d);
1733 }
1734 }
1735 if (doit[D_IGE_192_AES]) {
1736 for (j = 0; j < SIZE_NUM; j++) {
1737 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
1738 lengths[j]);
1739 Time_F(START);
1740 for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1741 AES_ige_encrypt(buf, buf2,
1742 (unsigned long)lengths[j], &aes_ks2,
1743 iv, AES_ENCRYPT);
1744 d = Time_F(STOP);
1745 print_result(D_IGE_192_AES, j, count, d);
1746 }
1747 }
1748 if (doit[D_IGE_256_AES]) {
1749 for (j = 0; j < SIZE_NUM; j++) {
1750 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
1751 lengths[j]);
1752 Time_F(START);
1753 for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1754 AES_ige_encrypt(buf, buf2,
1755 (unsigned long)lengths[j], &aes_ks3,
1756 iv, AES_ENCRYPT);
1757 d = Time_F(STOP);
1758 print_result(D_IGE_256_AES, j, count, d);
1759 }
1760 }
1761 if (doit[D_GHASH]) {
1762 GCM128_CONTEXT *ctx =
1763 CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1764 CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
1765
1766 for (j = 0; j < SIZE_NUM; j++) {
1767 print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1768 Time_F(START);
1769 for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1770 CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1771 d = Time_F(STOP);
1772 print_result(D_GHASH, j, count, d);
1773 }
1774 CRYPTO_gcm128_release(ctx);
1775 }
a00ae6c4
RS
1776#endif
1777#ifndef OPENSSL_NO_CAMELLIA
0f113f3e
MC
1778 if (doit[D_CBC_128_CML]) {
1779 for (j = 0; j < SIZE_NUM; j++) {
1780 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
1781 lengths[j]);
1782 Time_F(START);
1783 for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1784 Camellia_cbc_encrypt(buf, buf,
1785 (unsigned long)lengths[j], &camellia_ks1,
1786 iv, CAMELLIA_ENCRYPT);
1787 d = Time_F(STOP);
1788 print_result(D_CBC_128_CML, j, count, d);
1789 }
1790 }
1791 if (doit[D_CBC_192_CML]) {
1792 for (j = 0; j < SIZE_NUM; j++) {
1793 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
1794 lengths[j]);
1795 Time_F(START);
1796 for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1797 Camellia_cbc_encrypt(buf, buf,
1798 (unsigned long)lengths[j], &camellia_ks2,
1799 iv, CAMELLIA_ENCRYPT);
1800 d = Time_F(STOP);
1801 print_result(D_CBC_192_CML, j, count, d);
1802 }
1803 }
1804 if (doit[D_CBC_256_CML]) {
1805 for (j = 0; j < SIZE_NUM; j++) {
1806 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
1807 lengths[j]);
1808 Time_F(START);
1809 for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1810 Camellia_cbc_encrypt(buf, buf,
1811 (unsigned long)lengths[j], &camellia_ks3,
1812 iv, CAMELLIA_ENCRYPT);
1813 d = Time_F(STOP);
1814 print_result(D_CBC_256_CML, j, count, d);
1815 }
1816 }
a00ae6c4
RS
1817#endif
1818#ifndef OPENSSL_NO_IDEA
0f113f3e
MC
1819 if (doit[D_CBC_IDEA]) {
1820 for (j = 0; j < SIZE_NUM; j++) {
1821 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1822 Time_F(START);
1823 for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1824 idea_cbc_encrypt(buf, buf,
1825 (unsigned long)lengths[j], &idea_ks,
1826 iv, IDEA_ENCRYPT);
1827 d = Time_F(STOP);
1828 print_result(D_CBC_IDEA, j, count, d);
1829 }
1830 }
a00ae6c4
RS
1831#endif
1832#ifndef OPENSSL_NO_SEED
0f113f3e
MC
1833 if (doit[D_CBC_SEED]) {
1834 for (j = 0; j < SIZE_NUM; j++) {
1835 print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
1836 Time_F(START);
1837 for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
1838 SEED_cbc_encrypt(buf, buf,
1839 (unsigned long)lengths[j], &seed_ks, iv, 1);
1840 d = Time_F(STOP);
1841 print_result(D_CBC_SEED, j, count, d);
1842 }
1843 }
a00ae6c4
RS
1844#endif
1845#ifndef OPENSSL_NO_RC2
0f113f3e
MC
1846 if (doit[D_CBC_RC2]) {
1847 for (j = 0; j < SIZE_NUM; j++) {
1848 print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1849 Time_F(START);
1850 for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1851 RC2_cbc_encrypt(buf, buf,
1852 (unsigned long)lengths[j], &rc2_ks,
1853 iv, RC2_ENCRYPT);
1854 d = Time_F(STOP);
1855 print_result(D_CBC_RC2, j, count, d);
1856 }
1857 }
a00ae6c4
RS
1858#endif
1859#ifndef OPENSSL_NO_RC5
0f113f3e
MC
1860 if (doit[D_CBC_RC5]) {
1861 for (j = 0; j < SIZE_NUM; j++) {
1862 print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1863 Time_F(START);
1864 for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1865 RC5_32_cbc_encrypt(buf, buf,
1866 (unsigned long)lengths[j], &rc5_ks,
1867 iv, RC5_ENCRYPT);
1868 d = Time_F(STOP);
1869 print_result(D_CBC_RC5, j, count, d);
1870 }
1871 }
a00ae6c4
RS
1872#endif
1873#ifndef OPENSSL_NO_BF
0f113f3e
MC
1874 if (doit[D_CBC_BF]) {
1875 for (j = 0; j < SIZE_NUM; j++) {
1876 print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1877 Time_F(START);
1878 for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1879 BF_cbc_encrypt(buf, buf,
1880 (unsigned long)lengths[j], &bf_ks,
1881 iv, BF_ENCRYPT);
1882 d = Time_F(STOP);
1883 print_result(D_CBC_BF, j, count, d);
1884 }
1885 }
a00ae6c4
RS
1886#endif
1887#ifndef OPENSSL_NO_CAST
0f113f3e
MC
1888 if (doit[D_CBC_CAST]) {
1889 for (j = 0; j < SIZE_NUM; j++) {
1890 print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1891 Time_F(START);
1892 for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1893 CAST_cbc_encrypt(buf, buf,
1894 (unsigned long)lengths[j], &cast_ks,
1895 iv, CAST_ENCRYPT);
1896 d = Time_F(STOP);
1897 print_result(D_CBC_CAST, j, count, d);
1898 }
1899 }
a00ae6c4 1900#endif
f3dea9a5 1901
0f113f3e 1902 if (doit[D_EVP]) {
a00ae6c4 1903#ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
0f113f3e
MC
1904 if (multiblock && evp_cipher) {
1905 if (!
1906 (EVP_CIPHER_flags(evp_cipher) &
1907 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
1908 fprintf(stderr, "%s is not multi-block capable\n",
1909 OBJ_nid2ln(evp_cipher->nid));
1910 goto end;
1911 }
1912 multiblock_speed(evp_cipher);
1913 mret = 0;
1914 goto end;
1915 }
a00ae6c4 1916#endif
0f113f3e
MC
1917 for (j = 0; j < SIZE_NUM; j++) {
1918 if (evp_cipher) {
1919 EVP_CIPHER_CTX ctx;
1920 int outl;
1921
1922 names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1923 /*
1924 * -O3 -fschedule-insns messes up an optimization here!
1925 * names[D_EVP] somehow becomes NULL
1926 */
1927 print_message(names[D_EVP], save_count, lengths[j]);
1928
1929 EVP_CIPHER_CTX_init(&ctx);
1930 if (decrypt)
1931 EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1932 else
1933 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1934 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1935
1936 Time_F(START);
1937 if (decrypt)
1938 for (count = 0, run = 1;
1939 COND(save_count * 4 * lengths[0] / lengths[j]);
1940 count++)
1941 EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1942 else
1943 for (count = 0, run = 1;
1944 COND(save_count * 4 * lengths[0] / lengths[j]);
1945 count++)
1946 EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1947 if (decrypt)
1948 EVP_DecryptFinal_ex(&ctx, buf, &outl);
1949 else
1950 EVP_EncryptFinal_ex(&ctx, buf, &outl);
1951 d = Time_F(STOP);
1952 EVP_CIPHER_CTX_cleanup(&ctx);
1953 }
1954 if (evp_md) {
1955 names[D_EVP] = OBJ_nid2ln(evp_md->type);
1956 print_message(names[D_EVP], save_count, lengths[j]);
1957
1958 Time_F(START);
1959 for (count = 0, run = 1;
1960 COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1961 EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1962
1963 d = Time_F(STOP);
1964 }
1965 print_result(D_EVP, j, count, d);
1966 }
1967 }
a00ae6c4
RS
1968#ifndef OPENSSL_SYS_WIN32
1969#endif
0f113f3e 1970 RAND_pseudo_bytes(buf, 36);
a00ae6c4 1971#ifndef OPENSSL_NO_RSA
0f113f3e
MC
1972 for (j = 0; j < RSA_NUM; j++) {
1973 int ret;
1974 if (!rsa_doit[j])
1975 continue;
1976 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1977 if (ret == 0) {
1978 BIO_printf(bio_err,
1979 "RSA sign failure. No RSA sign will be done.\n");
1980 ERR_print_errors(bio_err);
1981 rsa_count = 1;
1982 } else {
1983 pkey_print_message("private", "rsa",
1984 rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
1985 /* RSA_blinding_on(rsa_key[j],NULL); */
1986 Time_F(START);
1987 for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1988 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1989 &rsa_num, rsa_key[j]);
1990 if (ret == 0) {
1991 BIO_printf(bio_err, "RSA sign failure\n");
1992 ERR_print_errors(bio_err);
1993 count = 1;
1994 break;
1995 }
1996 }
1997 d = Time_F(STOP);
1998 BIO_printf(bio_err,
1999 mr ? "+R1:%ld:%d:%.2f\n"
2000 : "%ld %d bit private RSA's in %.2fs\n",
2001 count, rsa_bits[j], d);
2002 rsa_results[j][0] = d / (double)count;
2003 rsa_count = count;
2004 }
d02b48c6 2005
0f113f3e
MC
2006 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
2007 if (ret <= 0) {
2008 BIO_printf(bio_err,
2009 "RSA verify failure. No RSA verify will be done.\n");
2010 ERR_print_errors(bio_err);
2011 rsa_doit[j] = 0;
2012 } else {
2013 pkey_print_message("public", "rsa",
2014 rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
2015 Time_F(START);
2016 for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
2017 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
2018 rsa_num, rsa_key[j]);
2019 if (ret <= 0) {
2020 BIO_printf(bio_err, "RSA verify failure\n");
2021 ERR_print_errors(bio_err);
2022 count = 1;
2023 break;
2024 }
2025 }
2026 d = Time_F(STOP);
2027 BIO_printf(bio_err,
2028 mr ? "+R2:%ld:%d:%.2f\n"
2029 : "%ld %d bit public RSA's in %.2fs\n",
2030 count, rsa_bits[j], d);
2031 rsa_results[j][1] = d / (double)count;
2032 }
d02b48c6 2033
0f113f3e
MC
2034 if (rsa_count <= 1) {
2035 /* if longer than 10s, don't do any more */
2036 for (j++; j < RSA_NUM; j++)
2037 rsa_doit[j] = 0;
2038 }
2039 }
a00ae6c4 2040#endif
d02b48c6 2041
0f113f3e 2042 RAND_pseudo_bytes(buf, 20);
a00ae6c4 2043#ifndef OPENSSL_NO_DSA
0f113f3e
MC
2044 if (RAND_status() != 1) {
2045 RAND_seed(rnd_seed, sizeof rnd_seed);
2046 rnd_fake = 1;
2047 }
2048 for (j = 0; j < DSA_NUM; j++) {
2049 unsigned int kk;
2050 int ret;
2051
2052 if (!dsa_doit[j])
2053 continue;
2054
2055 /* DSA_generate_key(dsa_key[j]); */
2056 /* DSA_sign_setup(dsa_key[j],NULL); */
2057 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2058 if (ret == 0) {
2059 BIO_printf(bio_err,
2060 "DSA sign failure. No DSA sign will be done.\n");
2061 ERR_print_errors(bio_err);
2062 rsa_count = 1;
2063 } else {
2064 pkey_print_message("sign", "dsa",
2065 dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
2066 Time_F(START);
2067 for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
2068 ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
2069 if (ret == 0) {
2070 BIO_printf(bio_err, "DSA sign failure\n");
2071 ERR_print_errors(bio_err);
2072 count = 1;
2073 break;
2074 }
2075 }
2076 d = Time_F(STOP);
2077 BIO_printf(bio_err,
2078 mr ? "+R3:%ld:%d:%.2f\n"
2079 : "%ld %d bit DSA signs in %.2fs\n",
2080 count, dsa_bits[j], d);
2081 dsa_results[j][0] = d / (double)count;
2082 rsa_count = count;
2083 }
e172d60d 2084
0f113f3e
MC
2085 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2086 if (ret <= 0) {
2087 BIO_printf(bio_err,
2088 "DSA verify failure. No DSA verify will be done.\n");
2089 ERR_print_errors(bio_err);
2090 dsa_doit[j] = 0;
2091 } else {
2092 pkey_print_message("verify", "dsa",
2093 dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
2094 Time_F(START);
2095 for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
2096 ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
2097 if (ret <= 0) {
2098 BIO_printf(bio_err, "DSA verify failure\n");
2099 ERR_print_errors(bio_err);
2100 count = 1;
2101 break;
2102 }
2103 }
2104 d = Time_F(STOP);
2105 BIO_printf(bio_err,
2106 mr ? "+R4:%ld:%d:%.2f\n"
2107 : "%ld %d bit DSA verify in %.2fs\n",
2108 count, dsa_bits[j], d);
2109 dsa_results[j][1] = d / (double)count;
2110 }
e172d60d 2111
0f113f3e
MC
2112 if (rsa_count <= 1) {
2113 /* if longer than 10s, don't do any more */
2114 for (j++; j < DSA_NUM; j++)
2115 dsa_doit[j] = 0;
2116 }
2117 }
2118 if (rnd_fake)
2119 RAND_cleanup();
a00ae6c4 2120#endif
e172d60d 2121
10bf4fc2 2122#ifndef OPENSSL_NO_EC
0f113f3e
MC
2123 if (RAND_status() != 1) {
2124 RAND_seed(rnd_seed, sizeof rnd_seed);
2125 rnd_fake = 1;
2126 }
2127 for (j = 0; j < EC_NUM; j++) {
2128 int ret;
2129
2130 if (!ecdsa_doit[j])
2131 continue; /* Ignore Curve */
2132 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2133 if (ecdsa[j] == NULL) {
2134 BIO_printf(bio_err, "ECDSA failure.\n");
2135 ERR_print_errors(bio_err);
2136 rsa_count = 1;
2137 } else {
0f113f3e 2138 EC_KEY_precompute_mult(ecdsa[j], NULL);
6f91b017 2139
0f113f3e
MC
2140 /* Perform ECDSA signature test */
2141 EC_KEY_generate_key(ecdsa[j]);
2142 ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
2143 if (ret == 0) {
2144 BIO_printf(bio_err,
2145 "ECDSA sign failure. No ECDSA sign will be done.\n");
2146 ERR_print_errors(bio_err);
2147 rsa_count = 1;
2148 } else {
2149 pkey_print_message("sign", "ecdsa",
2150 ecdsa_c[j][0],
2151 test_curves_bits[j], ECDSA_SECONDS);
2152
2153 Time_F(START);
2154 for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
2155 ret = ECDSA_sign(0, buf, 20,
2156 ecdsasig, &ecdsasiglen, ecdsa[j]);
2157 if (ret == 0) {
2158 BIO_printf(bio_err, "ECDSA sign failure\n");
2159 ERR_print_errors(bio_err);
2160 count = 1;
2161 break;
2162 }
2163 }
2164 d = Time_F(STOP);
2165
2166 BIO_printf(bio_err,
2167 mr ? "+R5:%ld:%d:%.2f\n" :
2168 "%ld %d bit ECDSA signs in %.2fs \n",
2169 count, test_curves_bits[j], d);
2170 ecdsa_results[j][0] = d / (double)count;
2171 rsa_count = count;
2172 }
2173
2174 /* Perform ECDSA verification test */
2175 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2176 if (ret != 1) {
2177 BIO_printf(bio_err,
2178 "ECDSA verify failure. No ECDSA verify will be done.\n");
2179 ERR_print_errors(bio_err);
2180 ecdsa_doit[j] = 0;
2181 } else {
2182 pkey_print_message("verify", "ecdsa",
2183 ecdsa_c[j][1],
2184 test_curves_bits[j], ECDSA_SECONDS);
2185 Time_F(START);
2186 for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
2187 ret =
2188 ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
2189 ecdsa[j]);
2190 if (ret != 1) {
2191 BIO_printf(bio_err, "ECDSA verify failure\n");
2192 ERR_print_errors(bio_err);
2193 count = 1;
2194 break;
2195 }
2196 }
2197 d = Time_F(STOP);
2198 BIO_printf(bio_err,
2199 mr ? "+R6:%ld:%d:%.2f\n"
2200 : "%ld %d bit ECDSA verify in %.2fs\n",
2201 count, test_curves_bits[j], d);
2202 ecdsa_results[j][1] = d / (double)count;
2203 }
2204
2205 if (rsa_count <= 1) {
2206 /* if longer than 10s, don't do any more */
2207 for (j++; j < EC_NUM; j++)
2208 ecdsa_doit[j] = 0;
2209 }
2210 }
2211 }
2212 if (rnd_fake)
2213 RAND_cleanup();
0f113f3e
MC
2214 if (RAND_status() != 1) {
2215 RAND_seed(rnd_seed, sizeof rnd_seed);
2216 rnd_fake = 1;
2217 }
2218 for (j = 0; j < EC_NUM; j++) {
2219 if (!ecdh_doit[j])
2220 continue;
2221 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2222 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2223 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
2224 BIO_printf(bio_err, "ECDH failure.\n");
2225 ERR_print_errors(bio_err);
2226 rsa_count = 1;
2227 } else {
2228 /* generate two ECDH key pairs */
2229 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2230 !EC_KEY_generate_key(ecdh_b[j])) {
2231 BIO_printf(bio_err, "ECDH key generation failure.\n");
2232 ERR_print_errors(bio_err);
2233 rsa_count = 1;
2234 } else {
2235 /*
2236 * If field size is not more than 24 octets, then use SHA-1
2237 * hash of result; otherwise, use result (see section 4.8 of
2238 * draft-ietf-tls-ecc-03.txt).
2239 */
2240 int field_size, outlen;
2241 void *(*kdf) (const void *in, size_t inlen, void *out,
2242 size_t *xoutlen);
2243 field_size =
2244 EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2245 if (field_size <= 24 * 8) {
2246 outlen = KDF1_SHA1_len;
2247 kdf = KDF1_SHA1;
2248 } else {
2249 outlen = (field_size + 7) / 8;
2250 kdf = NULL;
2251 }
2252 secret_size_a =
2253 ECDH_compute_key(secret_a, outlen,
2254 EC_KEY_get0_public_key(ecdh_b[j]),
2255 ecdh_a[j], kdf);
2256 secret_size_b =
2257 ECDH_compute_key(secret_b, outlen,
2258 EC_KEY_get0_public_key(ecdh_a[j]),
2259 ecdh_b[j], kdf);
2260 if (secret_size_a != secret_size_b)
2261 ecdh_checks = 0;
2262 else
2263 ecdh_checks = 1;
2264
2265 for (secret_idx = 0; (secret_idx < secret_size_a)
2266 && (ecdh_checks == 1); secret_idx++) {
2267 if (secret_a[secret_idx] != secret_b[secret_idx])
2268 ecdh_checks = 0;
2269 }
2270
2271 if (ecdh_checks == 0) {
2272 BIO_printf(bio_err, "ECDH computations don't match.\n");
2273 ERR_print_errors(bio_err);
2274 rsa_count = 1;
2275 }
2276
2277 pkey_print_message("", "ecdh",
2278 ecdh_c[j][0],
2279 test_curves_bits[j], ECDH_SECONDS);
2280 Time_F(START);
2281 for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
2282 ECDH_compute_key(secret_a, outlen,
2283 EC_KEY_get0_public_key(ecdh_b[j]),
2284 ecdh_a[j], kdf);
2285 }
2286 d = Time_F(STOP);
2287 BIO_printf(bio_err,
2288 mr ? "+R7:%ld:%d:%.2f\n" :
2289 "%ld %d-bit ECDH ops in %.2fs\n", count,
2290 test_curves_bits[j], d);
2291 ecdh_results[j][0] = d / (double)count;
2292 rsa_count = count;
2293 }
2294 }
e172d60d 2295
0f113f3e
MC
2296 if (rsa_count <= 1) {
2297 /* if longer than 10s, don't do any more */
2298 for (j++; j < EC_NUM; j++)
2299 ecdh_doit[j] = 0;
2300 }
2301 }
2302 if (rnd_fake)
2303 RAND_cleanup();
a00ae6c4
RS
2304#endif
2305#ifndef NO_FORK
0f113f3e 2306 show_res:
a00ae6c4 2307#endif
0f113f3e
MC
2308 if (!mr) {
2309 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
2310 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
2311 printf("options:");
2312 printf("%s ", BN_options());
a00ae6c4 2313#ifndef OPENSSL_NO_MD2
0f113f3e 2314 printf("%s ", MD2_options());
a00ae6c4
RS
2315#endif
2316#ifndef OPENSSL_NO_RC4
0f113f3e 2317 printf("%s ", RC4_options());
a00ae6c4
RS
2318#endif
2319#ifndef OPENSSL_NO_DES
0f113f3e 2320 printf("%s ", DES_options());
a00ae6c4
RS
2321#endif
2322#ifndef OPENSSL_NO_AES
0f113f3e 2323 printf("%s ", AES_options());
a00ae6c4
RS
2324#endif
2325#ifndef OPENSSL_NO_IDEA
0f113f3e 2326 printf("%s ", idea_options());
a00ae6c4
RS
2327#endif
2328#ifndef OPENSSL_NO_BF
0f113f3e 2329 printf("%s ", BF_options());
a00ae6c4 2330#endif
0f113f3e
MC
2331 fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
2332 }
e172d60d 2333
0f113f3e
MC
2334 if (pr_header) {
2335 if (mr)
2336 fprintf(stdout, "+H");
2337 else {
2338 fprintf(stdout,
2339 "The 'numbers' are in 1000s of bytes per second processed.\n");
2340 fprintf(stdout, "type ");
2341 }
2342 for (j = 0; j < SIZE_NUM; j++)
2343 fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
2344 fprintf(stdout, "\n");
2345 }
e172d60d 2346
0f113f3e
MC
2347 for (k = 0; k < ALGOR_NUM; k++) {
2348 if (!doit[k])
2349 continue;
2350 if (mr)
2351 fprintf(stdout, "+F:%d:%s", k, names[k]);
2352 else
2353 fprintf(stdout, "%-13s", names[k]);
2354 for (j = 0; j < SIZE_NUM; j++) {
2355 if (results[k][j] > 10000 && !mr)
2356 fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
2357 else
2358 fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
2359 }
2360 fprintf(stdout, "\n");
2361 }
a00ae6c4 2362#ifndef OPENSSL_NO_RSA
0f113f3e
MC
2363 j = 1;
2364 for (k = 0; k < RSA_NUM; k++) {
2365 if (!rsa_doit[k])
2366 continue;
2367 if (j && !mr) {
2368 printf("%18ssign verify sign/s verify/s\n", " ");
2369 j = 0;
2370 }
2371 if (mr)
2372 fprintf(stdout, "+F2:%u:%u:%f:%f\n",
2373 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
2374 else
2375 fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2376 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2377 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
2378 }
a00ae6c4
RS
2379#endif
2380#ifndef OPENSSL_NO_DSA
0f113f3e
MC
2381 j = 1;
2382 for (k = 0; k < DSA_NUM; k++) {
2383 if (!dsa_doit[k])
2384 continue;
2385 if (j && !mr) {
2386 printf("%18ssign verify sign/s verify/s\n", " ");
2387 j = 0;
2388 }
2389 if (mr)
2390 fprintf(stdout, "+F3:%u:%u:%f:%f\n",
2391 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
2392 else
2393 fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2394 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2395 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
2396 }
a00ae6c4 2397#endif
10bf4fc2 2398#ifndef OPENSSL_NO_EC
0f113f3e
MC
2399 j = 1;
2400 for (k = 0; k < EC_NUM; k++) {
2401 if (!ecdsa_doit[k])
2402 continue;
2403 if (j && !mr) {
2404 printf("%30ssign verify sign/s verify/s\n", " ");
2405 j = 0;
2406 }
2407
2408 if (mr)
2409 fprintf(stdout, "+F4:%u:%u:%f:%f\n",
2410 k, test_curves_bits[k],
2411 ecdsa_results[k][0], ecdsa_results[k][1]);
2412 else
2413 fprintf(stdout,
2414 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2415 test_curves_bits[k],
2416 test_curves_names[k],
2417 ecdsa_results[k][0], ecdsa_results[k][1],
2418 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
2419 }
0f113f3e
MC
2420 j = 1;
2421 for (k = 0; k < EC_NUM; k++) {
2422 if (!ecdh_doit[k])
2423 continue;
2424 if (j && !mr) {
2425 printf("%30sop op/s\n", " ");
2426 j = 0;
2427 }
2428 if (mr)
2429 fprintf(stdout, "+F5:%u:%u:%f:%f\n",
2430 k, test_curves_bits[k],
2431 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2432
2433 else
2434 fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
2435 test_curves_bits[k],
2436 test_curves_names[k],
2437 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
2438 }
a00ae6c4 2439#endif
0f113f3e
MC
2440
2441 mret = 0;
2442
2443 end:
2444 ERR_print_errors(bio_err);
2445 if (buf_malloc != NULL)
2446 OPENSSL_free(buf_malloc);
2447 if (buf2_malloc != NULL)
2448 OPENSSL_free(buf2_malloc);
a00ae6c4 2449#ifndef OPENSSL_NO_RSA
0f113f3e
MC
2450 for (i = 0; i < RSA_NUM; i++)
2451 if (rsa_key[i] != NULL)
2452 RSA_free(rsa_key[i]);
a00ae6c4
RS
2453#endif
2454#ifndef OPENSSL_NO_DSA
0f113f3e
MC
2455 for (i = 0; i < DSA_NUM; i++)
2456 if (dsa_key[i] != NULL)
2457 DSA_free(dsa_key[i]);
a00ae6c4 2458#endif
0f113f3e 2459
10bf4fc2 2460#ifndef OPENSSL_NO_EC
0f113f3e
MC
2461 for (i = 0; i < EC_NUM; i++)
2462 if (ecdsa[i] != NULL)
2463 EC_KEY_free(ecdsa[i]);
0f113f3e
MC
2464 for (i = 0; i < EC_NUM; i++) {
2465 if (ecdh_a[i] != NULL)
2466 EC_KEY_free(ecdh_a[i]);
2467 if (ecdh_b[i] != NULL)
2468 EC_KEY_free(ecdh_b[i]);
2469 }
a00ae6c4 2470#endif
0f113f3e
MC
2471
2472 apps_shutdown();
2473 OPENSSL_EXIT(mret);
2474}
d02b48c6 2475
646d5695 2476static void print_message(const char *s, long num, int length)
0f113f3e 2477{
a00ae6c4 2478#ifdef SIGALRM
0f113f3e
MC
2479 BIO_printf(bio_err,
2480 mr ? "+DT:%s:%d:%d\n"
2481 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2482 (void)BIO_flush(bio_err);
2483 alarm(SECONDS);
a00ae6c4 2484#else
0f113f3e
MC
2485 BIO_printf(bio_err,
2486 mr ? "+DN:%s:%ld:%d\n"
2487 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2488 (void)BIO_flush(bio_err);
a00ae6c4 2489#endif
0f113f3e 2490}
d02b48c6 2491
689c6f25 2492static void pkey_print_message(const char *str, const char *str2, long num,
0f113f3e
MC
2493 int bits, int tm)
2494{
a00ae6c4 2495#ifdef SIGALRM
0f113f3e
MC
2496 BIO_printf(bio_err,
2497 mr ? "+DTP:%d:%s:%s:%d\n"
2498 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2499 (void)BIO_flush(bio_err);
2500 alarm(tm);
a00ae6c4 2501#else
0f113f3e
MC
2502 BIO_printf(bio_err,
2503 mr ? "+DNP:%ld:%d:%s:%s\n"
2504 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2505 (void)BIO_flush(bio_err);
a00ae6c4 2506#endif
0f113f3e 2507}
58964a49 2508
0f113f3e
MC
2509static void print_result(int alg, int run_no, int count, double time_used)
2510{
2511 BIO_printf(bio_err,
2512 mr ? "+R:%d:%s:%f\n"
2513 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2514 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2515}
0e211563 2516
a00ae6c4 2517#ifndef NO_FORK
0e211563 2518static char *sstrsep(char **string, const char *delim)
0f113f3e 2519{
0e211563
BL
2520 char isdelim[256];
2521 char *token = *string;
2522
2523 if (**string == 0)
2524 return NULL;
2525
54a656ef 2526 memset(isdelim, 0, sizeof isdelim);
0e211563
BL
2527 isdelim[0] = 1;
2528
0f113f3e 2529 while (*delim) {
0e211563
BL
2530 isdelim[(unsigned char)(*delim)] = 1;
2531 delim++;
0f113f3e 2532 }
0e211563 2533
0f113f3e 2534 while (!isdelim[(unsigned char)(**string)]) {
0e211563 2535 (*string)++;
0f113f3e 2536 }
0e211563 2537
0f113f3e 2538 if (**string) {
0e211563
BL
2539 **string = 0;
2540 (*string)++;
0f113f3e 2541 }
0e211563
BL
2542
2543 return token;
0f113f3e 2544}
0e211563
BL
2545
2546static int do_multi(int multi)
0f113f3e
MC
2547{
2548 int n;
2549 int fd[2];
2550 int *fds;
2551 static char sep[] = ":";
2552
2553 fds = malloc(multi * sizeof *fds);
2554 for (n = 0; n < multi; ++n) {
2555 if (pipe(fd) == -1) {
2556 fprintf(stderr, "pipe failure\n");
2557 exit(1);
2558 }
2559 fflush(stdout);
2560 fflush(stderr);
2561 if (fork()) {
2562 close(fd[1]);
2563 fds[n] = fd[0];
2564 } else {
2565 close(fd[0]);
2566 close(1);
2567 if (dup(fd[1]) == -1) {
2568 fprintf(stderr, "dup failed\n");
2569 exit(1);
2570 }
2571 close(fd[1]);
2572 mr = 1;
2573 usertime = 0;
2574 free(fds);
2575 return 0;
2576 }
2577 printf("Forked child %d\n", n);
2578 }
e172d60d 2579
0f113f3e
MC
2580 /* for now, assume the pipe is long enough to take all the output */
2581 for (n = 0; n < multi; ++n) {
2582 FILE *f;
2583 char buf[1024];
2584 char *p;
2585
2586 f = fdopen(fds[n], "r");
2587 while (fgets(buf, sizeof buf, f)) {
2588 p = strchr(buf, '\n');
2589 if (p)
2590 *p = '\0';
2591 if (buf[0] != '+') {
2592 fprintf(stderr, "Don't understand line '%s' from child %d\n",
2593 buf, n);
2594 continue;
2595 }
2596 printf("Got: %s from %d\n", buf, n);
2597 if (!strncmp(buf, "+F:", 3)) {
2598 int alg;
2599 int j;
2600
2601 p = buf + 3;
2602 alg = atoi(sstrsep(&p, sep));
2603 sstrsep(&p, sep);
2604 for (j = 0; j < SIZE_NUM; ++j)
2605 results[alg][j] += atof(sstrsep(&p, sep));
2606 } else if (!strncmp(buf, "+F2:", 4)) {
2607 int k;
2608 double d;
2609
2610 p = buf + 4;
2611 k = atoi(sstrsep(&p, sep));
2612 sstrsep(&p, sep);
2613
2614 d = atof(sstrsep(&p, sep));
2615 if (n)
2616 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2617 else
2618 rsa_results[k][0] = d;
2619
2620 d = atof(sstrsep(&p, sep));
2621 if (n)
2622 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2623 else
2624 rsa_results[k][1] = d;
2625 } else if (!strncmp(buf, "+F2:", 4)) {
2626 int k;
2627 double d;
2628
2629 p = buf + 4;
2630 k = atoi(sstrsep(&p, sep));
2631 sstrsep(&p, sep);
2632
2633 d = atof(sstrsep(&p, sep));
2634 if (n)
2635 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2636 else
2637 rsa_results[k][0] = d;
2638
2639 d = atof(sstrsep(&p, sep));
2640 if (n)
2641 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2642 else
2643 rsa_results[k][1] = d;
2644 }
a00ae6c4 2645# ifndef OPENSSL_NO_DSA
0f113f3e
MC
2646 else if (!strncmp(buf, "+F3:", 4)) {
2647 int k;
2648 double d;
2649
2650 p = buf + 4;
2651 k = atoi(sstrsep(&p, sep));
2652 sstrsep(&p, sep);
2653
2654 d = atof(sstrsep(&p, sep));
2655 if (n)
2656 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2657 else
2658 dsa_results[k][0] = d;
2659
2660 d = atof(sstrsep(&p, sep));
2661 if (n)
2662 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2663 else
2664 dsa_results[k][1] = d;
2665 }
a00ae6c4 2666# endif
10bf4fc2 2667# ifndef OPENSSL_NO_EC
0f113f3e
MC
2668 else if (!strncmp(buf, "+F4:", 4)) {
2669 int k;
2670 double d;
2671
2672 p = buf + 4;
2673 k = atoi(sstrsep(&p, sep));
2674 sstrsep(&p, sep);
2675
2676 d = atof(sstrsep(&p, sep));
2677 if (n)
2678 ecdsa_results[k][0] =
2679 1 / (1 / ecdsa_results[k][0] + 1 / d);
2680 else
2681 ecdsa_results[k][0] = d;
2682
2683 d = atof(sstrsep(&p, sep));
2684 if (n)
2685 ecdsa_results[k][1] =
2686 1 / (1 / ecdsa_results[k][1] + 1 / d);
2687 else
2688 ecdsa_results[k][1] = d;
2689 }
0f113f3e
MC
2690 else if (!strncmp(buf, "+F5:", 4)) {
2691 int k;
2692 double d;
2693
2694 p = buf + 4;
2695 k = atoi(sstrsep(&p, sep));
2696 sstrsep(&p, sep);
2697
2698 d = atof(sstrsep(&p, sep));
2699 if (n)
2700 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2701 else
2702 ecdh_results[k][0] = d;
2703
2704 }
a00ae6c4 2705# endif
0f113f3e
MC
2706
2707 else if (!strncmp(buf, "+H:", 3)) {
2708 } else
2709 fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2710 }
2711
2712 fclose(f);
2713 }
2714 free(fds);
2715 return 1;
2716}
a00ae6c4 2717#endif
375a64e3
AP
2718
2719static void multiblock_speed(const EVP_CIPHER *evp_cipher)
0f113f3e
MC
2720{
2721 static int mblengths[] =
2722 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
2723 int j, count, num = sizeof(lengths) / sizeof(lengths[0]);
2724 const char *alg_name;
2725 unsigned char *inp, *out, no_key[32], no_iv[16];
2726 EVP_CIPHER_CTX ctx;
2727 double d = 0.0;
2728
2729 inp = OPENSSL_malloc(mblengths[num - 1]);
2730 out = OPENSSL_malloc(mblengths[num - 1] + 1024);
918bb865
MC
2731 if(!inp || !out) {
2732 BIO_printf(bio_err,"Out of memory\n");
2733 goto end;
2734 }
2735
0f113f3e
MC
2736
2737 EVP_CIPHER_CTX_init(&ctx);
2738 EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv);
2739 EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
2740 no_key);
2741 alg_name = OBJ_nid2ln(evp_cipher->nid);
2742
2743 for (j = 0; j < num; j++) {
2744 print_message(alg_name, 0, mblengths[j]);
2745 Time_F(START);
2746 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
2747 unsigned char aad[13];
2748 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2749 size_t len = mblengths[j];
2750 int packlen;
2751
2752 memset(aad, 0, 8); /* avoid uninitialized values */
2753 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2754 aad[9] = 3; /* version */
2755 aad[10] = 2;
2756 aad[11] = 0; /* length */
2757 aad[12] = 0;
2758 mb_param.out = NULL;
2759 mb_param.inp = aad;
2760 mb_param.len = len;
2761 mb_param.interleave = 8;
2762
2763 packlen = EVP_CIPHER_CTX_ctrl(&ctx,
2764 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2765 sizeof(mb_param), &mb_param);
2766
2767 if (packlen > 0) {
2768 mb_param.out = out;
2769 mb_param.inp = inp;
2770 mb_param.len = len;
2771 EVP_CIPHER_CTX_ctrl(&ctx,
2772 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2773 sizeof(mb_param), &mb_param);
2774 } else {
2775 int pad;
2776
2777 RAND_bytes(out, 16);
2778 len += 16;
2779 aad[11] = len >> 8;
2780 aad[12] = len;
2781 pad = EVP_CIPHER_CTX_ctrl(&ctx,
2782 EVP_CTRL_AEAD_TLS1_AAD, 13, aad);
2783 EVP_Cipher(&ctx, out, inp, len + pad);
2784 }
2785 }
2786 d = Time_F(STOP);
2787 BIO_printf(bio_err,
2788 mr ? "+R:%d:%s:%f\n"
2789 : "%d %s's in %.2fs\n", count, "evp", d);
2790 results[D_EVP][j] = ((double)count) / d * mblengths[j];
2791 }
2792
2793 if (mr) {
2794 fprintf(stdout, "+H");
2795 for (j = 0; j < num; j++)
2796 fprintf(stdout, ":%d", mblengths[j]);
2797 fprintf(stdout, "\n");
2798 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
2799 for (j = 0; j < num; j++)
2800 fprintf(stdout, ":%.2f", results[D_EVP][j]);
2801 fprintf(stdout, "\n");
2802 } else {
2803 fprintf(stdout,
2804 "The 'numbers' are in 1000s of bytes per second processed.\n");
2805 fprintf(stdout, "type ");
2806 for (j = 0; j < num; j++)
2807 fprintf(stdout, "%7d bytes", mblengths[j]);
2808 fprintf(stdout, "\n");
2809 fprintf(stdout, "%-24s", alg_name);
2810
2811 for (j = 0; j < num; j++) {
2812 if (results[D_EVP][j] > 10000)
2813 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
2814 else
2815 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
2816 }
2817 fprintf(stdout, "\n");
2818 }
2819
918bb865
MC
2820end:
2821 if(inp)
2822 OPENSSL_free(inp);
2823 if(out)
2824 OPENSSL_free(out);
0f113f3e 2825}