blob: ee6a4b2d578e8c5451b9e289474cbff8046918f0 [file] [log] [blame]
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00001/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002 * All rights reserved.
3 *
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
Matt Caswell0f113f32015-01-22 03:40:55 +00007 *
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00008 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
Matt Caswell0f113f32015-01-22 03:40:55 +000014 *
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000015 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
Matt Caswell0f113f32015-01-22 03:40:55 +000021 *
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000022 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
Matt Caswell0f113f32015-01-22 03:40:55 +000036 * 4. If you include any Windows specific code (or a derivative thereof) from
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000037 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
Matt Caswell0f113f32015-01-22 03:40:55 +000039 *
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000040 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
Matt Caswell0f113f32015-01-22 03:40:55 +000051 *
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000052 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.]
56 */
Bodo Möllere172d602002-08-09 08:43:04 +000057/* ====================================================================
Felix Laurie von Massenbach7e965dc2014-05-27 12:41:20 +010058 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
Bodo Möllere172d602002-08-09 08:43:04 +000059 *
Matt Caswell0f113f32015-01-22 03:40:55 +000060 * Portions of the attached software ("Contribution") are developed by
Bodo Möllere172d602002-08-09 08:43:04 +000061 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
62 *
63 * The Contribution is licensed pursuant to the OpenSSL open source
64 * license provided above.
65 *
Matt Caswell0f113f32015-01-22 03:40:55 +000066 * The ECDH and ECDSA speed test software is originally written by
Bodo Möllere172d602002-08-09 08:43:04 +000067 * Sumit Gupta of Sun Microsystems Laboratories.
68 *
69 */
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000070
Rich Salza00ae6c2015-01-27 10:06:22 -050071#undef SECONDS
72#define SECONDS 3
73#define PRIME_SECONDS 10
74#define RSA_SECONDS 10
75#define DSA_SECONDS 10
76#define ECDSA_SECONDS 10
77#define ECDH_SECONDS 10
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000078
Rich Salza00ae6c2015-01-27 10:06:22 -050079#include <stdio.h>
80#include <stdlib.h>
Rich Salza00ae6c2015-01-27 10:06:22 -050081#include <string.h>
82#include <math.h>
83#include "apps.h"
84#include <openssl/crypto.h>
85#include <openssl/rand.h>
86#include <openssl/err.h>
87#include <openssl/evp.h>
88#include <openssl/objects.h>
Andrea Grandi8b0b80d2015-12-09 07:26:38 +000089#include <openssl/async.h>
Rich Salza00ae6c2015-01-27 10:06:22 -050090#if !defined(OPENSSL_SYS_MSDOS)
91# include OPENSSL_UNISTD
92#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000093
Corinna Vinschen8d35ceb2016-01-16 19:30:48 +010094#if defined(_WIN32)
Rich Salza00ae6c2015-01-27 10:06:22 -050095# include <windows.h>
Rich Salza00ae6c2015-01-27 10:06:22 -050096#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +000097
Rich Salza00ae6c2015-01-27 10:06:22 -050098#include <openssl/bn.h>
99#ifndef OPENSSL_NO_DES
100# include <openssl/des.h>
101#endif
Matt Caswell5158c762016-04-13 11:28:45 +0100102#include <openssl/aes.h>
Rich Salza00ae6c2015-01-27 10:06:22 -0500103#ifndef OPENSSL_NO_CAMELLIA
104# include <openssl/camellia.h>
105#endif
106#ifndef OPENSSL_NO_MD2
107# include <openssl/md2.h>
108#endif
109#ifndef OPENSSL_NO_MDC2
110# include <openssl/mdc2.h>
111#endif
112#ifndef OPENSSL_NO_MD4
113# include <openssl/md4.h>
114#endif
115#ifndef OPENSSL_NO_MD5
116# include <openssl/md5.h>
117#endif
Rich Salz7e1b7482015-04-24 15:26:15 -0400118#include <openssl/hmac.h>
Rich Salz7e1b7482015-04-24 15:26:15 -0400119#include <openssl/sha.h>
Rich Salza00ae6c2015-01-27 10:06:22 -0500120#ifndef OPENSSL_NO_RMD160
121# include <openssl/ripemd.h>
122#endif
123#ifndef OPENSSL_NO_WHIRLPOOL
124# include <openssl/whrlpool.h>
125#endif
126#ifndef OPENSSL_NO_RC4
127# include <openssl/rc4.h>
128#endif
129#ifndef OPENSSL_NO_RC5
130# include <openssl/rc5.h>
131#endif
132#ifndef OPENSSL_NO_RC2
133# include <openssl/rc2.h>
134#endif
135#ifndef OPENSSL_NO_IDEA
136# include <openssl/idea.h>
137#endif
138#ifndef OPENSSL_NO_SEED
139# include <openssl/seed.h>
140#endif
141#ifndef OPENSSL_NO_BF
142# include <openssl/blowfish.h>
143#endif
144#ifndef OPENSSL_NO_CAST
145# include <openssl/cast.h>
146#endif
147#ifndef OPENSSL_NO_RSA
148# include <openssl/rsa.h>
149# include "./testrsa.h"
150#endif
151#include <openssl/x509.h>
152#ifndef OPENSSL_NO_DSA
153# include <openssl/dsa.h>
154# include "./testdsa.h"
155#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -0400156#ifndef OPENSSL_NO_EC
Dr. Stephen Hensonfb29bb52015-10-27 19:39:32 +0000157# include <openssl/ec.h>
Rich Salza00ae6c2015-01-27 10:06:22 -0500158#endif
159#include <openssl/modes.h>
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000160
Rich Salza00ae6c2015-01-27 10:06:22 -0500161#ifndef HAVE_FORK
Rich Salz1fbab1d2016-03-17 12:53:11 -0400162# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
Rich Salza00ae6c2015-01-27 10:06:22 -0500163# define HAVE_FORK 0
Dr. Stephen Hensonebaa2cf2010-03-03 19:56:34 +0000164# else
Rich Salza00ae6c2015-01-27 10:06:22 -0500165# define HAVE_FORK 1
Dr. Stephen Hensonebaa2cf2010-03-03 19:56:34 +0000166# endif
Rich Salza00ae6c2015-01-27 10:06:22 -0500167#endif
Dr. Stephen Hensonebaa2cf2010-03-03 19:56:34 +0000168
Rich Salza00ae6c2015-01-27 10:06:22 -0500169#if HAVE_FORK
170# undef NO_FORK
171#else
172# define NO_FORK
173#endif
174
175#undef BUFSIZE
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000176#define BUFSIZE (1024*16+1)
Rich Salza00ae6c2015-01-27 10:06:22 -0500177#define MAX_MISALIGNMENT 63
Richard Levitte66d3e742001-10-25 16:08:17 +0000178
Andrea Grandi0ff43432016-02-18 10:56:53 +0000179#define ALGOR_NUM 30
180#define SIZE_NUM 6
181#define PRIME_NUM 3
182#define RSA_NUM 7
183#define DSA_NUM 3
184
185#define EC_NUM 17
186#define MAX_ECDH_SIZE 256
187#define MISALIGN 64
188
Matt Caswell0f113f32015-01-22 03:40:55 +0000189static volatile int run = 0;
Andy Polyakove2d03db2014-08-30 10:25:32 +0200190
Matt Caswell0f113f32015-01-22 03:40:55 +0000191static int mr = 0;
192static int usertime = 1;
Richard Levitte7876e442001-09-27 15:43:55 +0000193
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000194typedef struct loopargs_st {
195 ASYNC_JOB *inprogress_job;
Andrea Grandi1e613922016-02-29 11:28:55 +0000196 ASYNC_WAIT_CTX *wait_ctx;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000197 unsigned char *buf;
198 unsigned char *buf2;
199 unsigned char *buf_malloc;
200 unsigned char *buf2_malloc;
Andrea Grandi0ff43432016-02-18 10:56:53 +0000201 unsigned int *siglen;
202#ifndef OPENSSL_NO_RSA
203 RSA *rsa_key[RSA_NUM];
204#endif
205#ifndef OPENSSL_NO_DSA
206 DSA *dsa_key[DSA_NUM];
207#endif
208#ifndef OPENSSL_NO_EC
209 EC_KEY *ecdsa[EC_NUM];
210 EC_KEY *ecdh_a[EC_NUM];
211 EC_KEY *ecdh_b[EC_NUM];
212 unsigned char *secret_a;
213 unsigned char *secret_b;
214#endif
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000215 EVP_CIPHER_CTX *ctx;
216 HMAC_CTX *hctx;
217 GCM128_CONTEXT *gcm_ctx;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000218} loopargs_t;
219
220#ifndef OPENSSL_NO_MD2
221static int EVP_Digest_MD2_loop(void *args);
222#endif
223
224#ifndef OPENSSL_NO_MDC2
225static int EVP_Digest_MDC2_loop(void *args);
226#endif
227#ifndef OPENSSL_NO_MD4
228static int EVP_Digest_MD4_loop(void *args);
229#endif
230#ifndef OPENSSL_NO_MD5
231static int MD5_loop(void *args);
232static int HMAC_loop(void *args);
233#endif
234static int SHA1_loop(void *args);
235static int SHA256_loop(void *args);
236static int SHA512_loop(void *args);
237#ifndef OPENSSL_NO_WHIRLPOOL
238static int WHIRLPOOL_loop(void *args);
239#endif
240#ifndef OPENSSL_NO_RMD160
241static int EVP_Digest_RMD160_loop(void *args);
242#endif
243#ifndef OPENSSL_NO_RC4
244static int RC4_loop(void *args);
245#endif
246#ifndef OPENSSL_NO_DES
247static int DES_ncbc_encrypt_loop(void *args);
248static int DES_ede3_cbc_encrypt_loop(void *args);
249#endif
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000250static int AES_cbc_128_encrypt_loop(void *args);
251static int AES_cbc_192_encrypt_loop(void *args);
252static int AES_ige_128_encrypt_loop(void *args);
253static int AES_cbc_256_encrypt_loop(void *args);
254static int AES_ige_192_encrypt_loop(void *args);
255static int AES_ige_256_encrypt_loop(void *args);
256static int CRYPTO_gcm128_aad_loop(void *args);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000257static int EVP_Update_loop(void *args);
258static int EVP_Digest_loop(void *args);
259#ifndef OPENSSL_NO_RSA
260static int RSA_sign_loop(void *args);
261static int RSA_verify_loop(void *args);
262#endif
263#ifndef OPENSSL_NO_DSA
264static int DSA_sign_loop(void *args);
265static int DSA_verify_loop(void *args);
266#endif
267#ifndef OPENSSL_NO_EC
268static int ECDSA_sign_loop(void *args);
269static int ECDSA_verify_loop(void *args);
270static int ECDH_compute_key_loop(void *args);
271#endif
272static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs);
273
Ben Laurie0e211562001-10-25 14:27:17 +0000274static double Time_F(int s);
Matt Caswell0f113f32015-01-22 03:40:55 +0000275static void print_message(const char *s, long num, int length);
Nils Larsch689c6f22005-03-20 23:12:13 +0000276static void pkey_print_message(const char *str, const char *str2,
Matt Caswell0f113f32015-01-22 03:40:55 +0000277 long num, int bits, int sec);
278static void print_result(int alg, int run_no, int count, double time_used);
Rich Salza00ae6c2015-01-27 10:06:22 -0500279#ifndef NO_FORK
Ben Laurie0e211562001-10-25 14:27:17 +0000280static int do_multi(int multi);
Rich Salza00ae6c2015-01-27 10:06:22 -0500281#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000282
Matt Caswell0f113f32015-01-22 03:40:55 +0000283static const char *names[ALGOR_NUM] = {
284 "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
285 "des cbc", "des ede3", "idea cbc", "seed cbc",
286 "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
287 "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
288 "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
289 "evp", "sha256", "sha512", "whirlpool",
290 "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash"
291};
292
Ben Laurie0e211562001-10-25 14:27:17 +0000293static double results[ALGOR_NUM][SIZE_NUM];
Rich Salz7e1b7482015-04-24 15:26:15 -0400294static int lengths[SIZE_NUM] = {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000295 16, 64, 256, 1024, 8 * 1024, 16 * 1024
Rich Salz7e1b7482015-04-24 15:26:15 -0400296};
Matt Caswell0f113f32015-01-22 03:40:55 +0000297
Rich Salza00ae6c2015-01-27 10:06:22 -0500298#ifndef OPENSSL_NO_RSA
Ben Laurie0e211562001-10-25 14:27:17 +0000299static double rsa_results[RSA_NUM][2];
Rich Salza00ae6c2015-01-27 10:06:22 -0500300#endif
301#ifndef OPENSSL_NO_DSA
Ben Laurie0e211562001-10-25 14:27:17 +0000302static double dsa_results[DSA_NUM][2];
Rich Salza00ae6c2015-01-27 10:06:22 -0500303#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -0400304#ifndef OPENSSL_NO_EC
Bodo Möllere172d602002-08-09 08:43:04 +0000305static double ecdsa_results[EC_NUM][2];
306static double ecdh_results[EC_NUM][1];
Rich Salza00ae6c2015-01-27 10:06:22 -0500307#endif
Bodo Möllere172d602002-08-09 08:43:04 +0000308
Matt Caswellb22234d2016-04-06 11:17:44 +0100309#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
Matt Caswell0f113f32015-01-22 03:40:55 +0000310static const char rnd_seed[] =
311 "string to make the random number generator think it has entropy";
Rich Salza00ae6c2015-01-27 10:06:22 -0500312#endif
Ben Laurie0e211562001-10-25 14:27:17 +0000313
Rich Salza00ae6c2015-01-27 10:06:22 -0500314#ifdef SIGALRM
315# if defined(__STDC__) || defined(sgi) || defined(_AIX)
316# define SIGRETTYPE void
317# else
318# define SIGRETTYPE int
319# endif
Dr. Stephen Hensonb83eddc2001-11-06 13:40:27 +0000320
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000321static SIGRETTYPE sig_done(int sig);
Ulf Möller6b691a51999-04-19 21:31:43 +0000322static SIGRETTYPE sig_done(int sig)
Matt Caswell0f113f32015-01-22 03:40:55 +0000323{
324 signal(SIGALRM, sig_done);
325 run = 0;
326}
Rich Salza00ae6c2015-01-27 10:06:22 -0500327#endif
328
329#define START 0
330#define STOP 1
331
332#if defined(_WIN32)
333
334# if !defined(SIGALRM)
335# define SIGALRM
Matt Caswell0f113f32015-01-22 03:40:55 +0000336# endif
Matt Caswell0f113f32015-01-22 03:40:55 +0000337static unsigned int lapse, schlock;
338static void alarm_win32(unsigned int secs)
339{
340 lapse = secs * 1000;
341}
Andy Polyakov0a39d8f2005-11-06 11:40:59 +0000342
Rich Salza00ae6c2015-01-27 10:06:22 -0500343# define alarm alarm_win32
Matt Caswell0f113f32015-01-22 03:40:55 +0000344
345static DWORD WINAPI sleepy(VOID * arg)
346{
347 schlock = 1;
348 Sleep(lapse);
349 run = 0;
350 return 0;
351}
Andy Polyakov0a39d8f2005-11-06 11:40:59 +0000352
Richard Levitte4d8743f2003-11-28 13:10:58 +0000353static double Time_F(int s)
Matt Caswell0f113f32015-01-22 03:40:55 +0000354{
355 double ret;
356 static HANDLE thr;
Andy Polyakovd582c982010-01-17 17:31:38 +0000357
Matt Caswell0f113f32015-01-22 03:40:55 +0000358 if (s == START) {
359 schlock = 0;
360 thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
361 if (thr == NULL) {
Andy Polyakovdb40a142015-09-28 16:05:32 +0200362 DWORD err = GetLastError();
363 BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
364 ExitProcess(err);
Matt Caswell0f113f32015-01-22 03:40:55 +0000365 }
366 while (!schlock)
367 Sleep(0); /* scheduler spinlock */
368 ret = app_tminterval(s, usertime);
369 } else {
370 ret = app_tminterval(s, usertime);
371 if (run)
372 TerminateThread(thr, 0);
373 CloseHandle(thr);
374 }
Richard Levitte4d8743f2003-11-28 13:10:58 +0000375
Matt Caswell0f113f32015-01-22 03:40:55 +0000376 return ret;
377}
Rich Salza00ae6c2015-01-27 10:06:22 -0500378#else
Richard Levitte4d8743f2003-11-28 13:10:58 +0000379
Ben Laurie0e211562001-10-25 14:27:17 +0000380static double Time_F(int s)
Matt Caswell0f113f32015-01-22 03:40:55 +0000381{
382 double ret = app_tminterval(s, usertime);
383 if (s == STOP)
384 alarm(0);
385 return ret;
386}
Rich Salza00ae6c2015-01-27 10:06:22 -0500387#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +0000388
Rich Salz10bf4fc2015-03-10 19:09:27 -0400389#ifndef OPENSSL_NO_EC
Bodo Möller176f31d2003-02-28 15:37:10 +0000390static const int KDF1_SHA1_len = 20;
Matt Caswell0f113f32015-01-22 03:40:55 +0000391static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
392 size_t *outlen)
393{
Matt Caswell0f113f32015-01-22 03:40:55 +0000394 if (*outlen < SHA_DIGEST_LENGTH)
395 return NULL;
Rich Salz474e4692015-01-27 12:34:45 -0500396 *outlen = SHA_DIGEST_LENGTH;
Matt Caswell0f113f32015-01-22 03:40:55 +0000397 return SHA1(in, inlen, out);
Matt Caswell0f113f32015-01-22 03:40:55 +0000398}
Rich Salz10bf4fc2015-03-10 19:09:27 -0400399#endif /* OPENSSL_NO_EC */
Bodo Möller176f31d2003-02-28 15:37:10 +0000400
Andy Polyakov375a64e2014-07-05 23:53:55 +0200401static void multiblock_speed(const EVP_CIPHER *evp_cipher);
Bodo Möller176f31d2003-02-28 15:37:10 +0000402
Rich Salz7e1b7482015-04-24 15:26:15 -0400403static int found(const char *name, const OPT_PAIR * pairs, int *result)
Matt Caswell0f113f32015-01-22 03:40:55 +0000404{
Rich Salz7e1b7482015-04-24 15:26:15 -0400405 for (; pairs->name; pairs++)
406 if (strcmp(name, pairs->name) == 0) {
407 *result = pairs->retval;
408 return 1;
409 }
410 return 0;
411}
412
413typedef enum OPTION_choice {
414 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
415 OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000416 OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS
Rich Salz7e1b7482015-04-24 15:26:15 -0400417} OPTION_CHOICE;
418
419OPTIONS speed_options[] = {
420 {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
421 {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
422 {"help", OPT_HELP, '-', "Display this summary"},
Rich Salz9c3bcfa2015-05-15 13:50:38 -0400423 {"evp", OPT_EVP, 's', "Use specified EVP cipher"},
424 {"decrypt", OPT_DECRYPT, '-',
425 "Time decryption instead of encryption (only EVP)"},
426 {"mr", OPT_MR, '-', "Produce machine readable output"},
427 {"mb", OPT_MB, '-'},
428 {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"},
Rich Salz7e1b7482015-04-24 15:26:15 -0400429 {"elapsed", OPT_ELAPSED, '-',
430 "Measure time in real time instead of CPU user time"},
Rich Salz7e1b7482015-04-24 15:26:15 -0400431#ifndef NO_FORK
432 {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
433#endif
Matt Caswell667867c2016-03-07 16:55:39 +0000434#ifndef OPENSSL_NO_ASYNC
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000435 {"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
436#endif
Rich Salz7e1b7482015-04-24 15:26:15 -0400437#ifndef OPENSSL_NO_ENGINE
438 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
439#endif
Kurt Cancemi77860052015-05-07 18:19:20 -0400440 {NULL},
Rich Salz7e1b7482015-04-24 15:26:15 -0400441};
442
443#define D_MD2 0
444#define D_MDC2 1
445#define D_MD4 2
446#define D_MD5 3
447#define D_HMAC 4
448#define D_SHA1 5
449#define D_RMD160 6
450#define D_RC4 7
451#define D_CBC_DES 8
452#define D_EDE3_DES 9
453#define D_CBC_IDEA 10
454#define D_CBC_SEED 11
455#define D_CBC_RC2 12
456#define D_CBC_RC5 13
457#define D_CBC_BF 14
458#define D_CBC_CAST 15
459#define D_CBC_128_AES 16
460#define D_CBC_192_AES 17
461#define D_CBC_256_AES 18
462#define D_CBC_128_CML 19
463#define D_CBC_192_CML 20
464#define D_CBC_256_CML 21
465#define D_EVP 22
466#define D_SHA256 23
467#define D_SHA512 24
468#define D_WHIRLPOOL 25
469#define D_IGE_128_AES 26
470#define D_IGE_192_AES 27
471#define D_IGE_256_AES 28
472#define D_GHASH 29
Ben Lauriedf2ee0e2015-09-05 13:32:58 +0100473static OPT_PAIR doit_choices[] = {
Rich Salz7e1b7482015-04-24 15:26:15 -0400474#ifndef OPENSSL_NO_MD2
475 {"md2", D_MD2},
476#endif
477#ifndef OPENSSL_NO_MDC2
478 {"mdc2", D_MDC2},
479#endif
480#ifndef OPENSSL_NO_MD4
481 {"md4", D_MD4},
482#endif
483#ifndef OPENSSL_NO_MD5
484 {"md5", D_MD5},
485#endif
486#ifndef OPENSSL_NO_MD5
487 {"hmac", D_HMAC},
488#endif
489 {"sha1", D_SHA1},
490 {"sha256", D_SHA256},
491 {"sha512", D_SHA512},
492#ifndef OPENSSL_NO_WHIRLPOOL
493 {"whirlpool", D_WHIRLPOOL},
494#endif
Rich Salzfd682e42015-08-06 12:22:31 -0400495#ifndef OPENSSL_NO_RMD160
Rich Salz7e1b7482015-04-24 15:26:15 -0400496 {"ripemd", D_RMD160},
497 {"rmd160", D_RMD160},
498 {"ripemd160", D_RMD160},
499#endif
500#ifndef OPENSSL_NO_RC4
501 {"rc4", D_RC4},
502#endif
503#ifndef OPENSSL_NO_DES
504 {"des-cbc", D_CBC_DES},
505 {"des-ede3", D_EDE3_DES},
506#endif
Rich Salz7e1b7482015-04-24 15:26:15 -0400507 {"aes-128-cbc", D_CBC_128_AES},
508 {"aes-192-cbc", D_CBC_192_AES},
509 {"aes-256-cbc", D_CBC_256_AES},
510 {"aes-128-ige", D_IGE_128_AES},
511 {"aes-192-ige", D_IGE_192_AES},
512 {"aes-256-ige", D_IGE_256_AES},
Rich Salz7e1b7482015-04-24 15:26:15 -0400513#ifndef OPENSSL_NO_RC2
514 {"rc2-cbc", D_CBC_RC2},
515 {"rc2", D_CBC_RC2},
516#endif
517#ifndef OPENSSL_NO_RC5
518 {"rc5-cbc", D_CBC_RC5},
519 {"rc5", D_CBC_RC5},
520#endif
521#ifndef OPENSSL_NO_IDEA
522 {"idea-cbc", D_CBC_IDEA},
523 {"idea", D_CBC_IDEA},
524#endif
525#ifndef OPENSSL_NO_SEED
526 {"seed-cbc", D_CBC_SEED},
527 {"seed", D_CBC_SEED},
528#endif
529#ifndef OPENSSL_NO_BF
530 {"bf-cbc", D_CBC_BF},
531 {"blowfish", D_CBC_BF},
532 {"bf", D_CBC_BF},
533#endif
534#ifndef OPENSSL_NO_CAST
535 {"cast-cbc", D_CBC_CAST},
536 {"cast", D_CBC_CAST},
537 {"cast5", D_CBC_CAST},
538#endif
539 {"ghash", D_GHASH},
540 {NULL}
541};
542
Matt Caswell83ae8122016-03-18 17:43:58 +0000543#ifndef OPENSSL_NO_DSA
544# define R_DSA_512 0
545# define R_DSA_1024 1
546# define R_DSA_2048 2
Rich Salz7e1b7482015-04-24 15:26:15 -0400547static OPT_PAIR dsa_choices[] = {
548 {"dsa512", R_DSA_512},
549 {"dsa1024", R_DSA_1024},
550 {"dsa2048", R_DSA_2048},
551 {NULL},
552};
Matt Caswell83ae8122016-03-18 17:43:58 +0000553#endif
Rich Salz7e1b7482015-04-24 15:26:15 -0400554
555#define R_RSA_512 0
556#define R_RSA_1024 1
557#define R_RSA_2048 2
558#define R_RSA_3072 3
559#define R_RSA_4096 4
560#define R_RSA_7680 5
561#define R_RSA_15360 6
562static OPT_PAIR rsa_choices[] = {
563 {"rsa512", R_RSA_512},
564 {"rsa1024", R_RSA_1024},
565 {"rsa2048", R_RSA_2048},
566 {"rsa3072", R_RSA_3072},
567 {"rsa4096", R_RSA_4096},
568 {"rsa7680", R_RSA_7680},
569 {"rsa15360", R_RSA_15360},
570 {NULL}
571};
572
573#define R_EC_P160 0
574#define R_EC_P192 1
575#define R_EC_P224 2
576#define R_EC_P256 3
577#define R_EC_P384 4
578#define R_EC_P521 5
579#define R_EC_K163 6
580#define R_EC_K233 7
581#define R_EC_K283 8
582#define R_EC_K409 9
583#define R_EC_K571 10
584#define R_EC_B163 11
585#define R_EC_B233 12
586#define R_EC_B283 13
587#define R_EC_B409 14
588#define R_EC_B571 15
Dr. Stephen Hensondb50c1d2016-02-12 14:11:47 +0000589#define R_EC_X25519 16
Richard Levittef5349f82015-09-20 00:46:44 +0200590#ifndef OPENSSL_NO_EC
Rich Salz7e1b7482015-04-24 15:26:15 -0400591static OPT_PAIR ecdsa_choices[] = {
592 {"ecdsap160", R_EC_P160},
593 {"ecdsap192", R_EC_P192},
594 {"ecdsap224", R_EC_P224},
595 {"ecdsap256", R_EC_P256},
596 {"ecdsap384", R_EC_P384},
597 {"ecdsap521", R_EC_P521},
598 {"ecdsak163", R_EC_K163},
599 {"ecdsak233", R_EC_K233},
600 {"ecdsak283", R_EC_K283},
601 {"ecdsak409", R_EC_K409},
602 {"ecdsak571", R_EC_K571},
603 {"ecdsab163", R_EC_B163},
604 {"ecdsab233", R_EC_B233},
605 {"ecdsab283", R_EC_B283},
606 {"ecdsab409", R_EC_B409},
607 {"ecdsab571", R_EC_B571},
608 {NULL}
609};
610static OPT_PAIR ecdh_choices[] = {
611 {"ecdhp160", R_EC_P160},
612 {"ecdhp192", R_EC_P192},
613 {"ecdhp224", R_EC_P224},
614 {"ecdhp256", R_EC_P256},
615 {"ecdhp384", R_EC_P384},
616 {"ecdhp521", R_EC_P521},
617 {"ecdhk163", R_EC_K163},
618 {"ecdhk233", R_EC_K233},
619 {"ecdhk283", R_EC_K283},
620 {"ecdhk409", R_EC_K409},
621 {"ecdhk571", R_EC_K571},
622 {"ecdhb163", R_EC_B163},
623 {"ecdhb233", R_EC_B233},
624 {"ecdhb283", R_EC_B283},
625 {"ecdhb409", R_EC_B409},
626 {"ecdhb571", R_EC_B571},
Dr. Stephen Hensondb50c1d2016-02-12 14:11:47 +0000627 {"ecdhx25519", R_EC_X25519},
Rich Salz7e1b7482015-04-24 15:26:15 -0400628 {NULL}
629};
630#endif
631
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000632#ifndef SIGALRM
633# define COND(d) (count < (d))
634# define COUNT(d) (d)
635#else
636# define COND(c) (run && count<0x7fffffff)
637# define COUNT(d) (count)
638#endif /* SIGALRM */
639
640static int testnum;
641static char *engine_id = NULL;
642
643
644#ifndef OPENSSL_NO_MD2
645static int EVP_Digest_MD2_loop(void *args)
646{
647 loopargs_t *tempargs = (loopargs_t *)args;
648 unsigned char *buf = tempargs->buf;
649 unsigned char md2[MD2_DIGEST_LENGTH];
650 int count;
651 for (count = 0; COND(c[D_MD2][testnum]); count++)
652 EVP_Digest(buf, (unsigned long)lengths[testnum], &(md2[0]), NULL,
653 EVP_md2(), NULL);
654 return count;
655}
656#endif
657
658#ifndef OPENSSL_NO_MDC2
659static int EVP_Digest_MDC2_loop(void *args)
660{
661 loopargs_t *tempargs = (loopargs_t *)args;
662 unsigned char *buf = tempargs->buf;
663 unsigned char mdc2[MDC2_DIGEST_LENGTH];
664 int count;
665 for (count = 0; COND(c[D_MDC2][testnum]); count++)
666 EVP_Digest(buf, (unsigned long)lengths[testnum], &(mdc2[0]), NULL,
667 EVP_mdc2(), NULL);
668 return count;
669}
670#endif
671
672#ifndef OPENSSL_NO_MD4
673static int EVP_Digest_MD4_loop(void *args)
674{
675 loopargs_t *tempargs = (loopargs_t *)args;
676 unsigned char *buf = tempargs->buf;
677 unsigned char md4[MD4_DIGEST_LENGTH];
678 int count;
679 for (count = 0; COND(c[D_MD4][testnum]); count++)
680 EVP_Digest(&(buf[0]), (unsigned long)lengths[testnum], &(md4[0]),
681 NULL, EVP_md4(), NULL);
682 return count;
683}
684#endif
685
686#ifndef OPENSSL_NO_MD5
687static int MD5_loop(void *args)
688{
689 loopargs_t *tempargs = (loopargs_t *)args;
690 unsigned char *buf = tempargs->buf;
691 unsigned char md5[MD5_DIGEST_LENGTH];
692 int count;
693 for (count = 0; COND(c[D_MD5][testnum]); count++)
694 MD5(buf, lengths[testnum], md5);
695 return count;
696}
697
698static int HMAC_loop(void *args)
699{
700 loopargs_t *tempargs = (loopargs_t *)args;
701 unsigned char *buf = tempargs->buf;
702 HMAC_CTX *hctx = tempargs->hctx;
703 unsigned char hmac[MD5_DIGEST_LENGTH];
704 int count;
705 for (count = 0; COND(c[D_HMAC][testnum]); count++) {
706 HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
707 HMAC_Update(hctx, buf, lengths[testnum]);
708 HMAC_Final(hctx, &(hmac[0]), NULL);
709 }
710 return count;
711}
712#endif
713
714static int SHA1_loop(void *args)
715{
716 loopargs_t *tempargs = (loopargs_t *)args;
717 unsigned char *buf = tempargs->buf;
718 unsigned char sha[SHA_DIGEST_LENGTH];
719 int count;
720 for (count = 0; COND(c[D_SHA1][testnum]); count++)
721 SHA1(buf, lengths[testnum], sha);
722 return count;
723}
724
725static int SHA256_loop(void *args)
726{
727 loopargs_t *tempargs = (loopargs_t *)args;
728 unsigned char *buf = tempargs->buf;
729 unsigned char sha256[SHA256_DIGEST_LENGTH];
730 int count;
731 for (count = 0; COND(c[D_SHA256][testnum]); count++)
732 SHA256(buf, lengths[testnum], sha256);
733 return count;
734}
735
736static int SHA512_loop(void *args)
737{
738 loopargs_t *tempargs = (loopargs_t *)args;
739 unsigned char *buf = tempargs->buf;
740 unsigned char sha512[SHA512_DIGEST_LENGTH];
741 int count;
742 for (count = 0; COND(c[D_SHA512][testnum]); count++)
743 SHA512(buf, lengths[testnum], sha512);
744 return count;
745}
746
747#ifndef OPENSSL_NO_WHIRLPOOL
748static int WHIRLPOOL_loop(void *args)
749{
750 loopargs_t *tempargs = (loopargs_t *)args;
751 unsigned char *buf = tempargs->buf;
752 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
753 int count;
754 for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
755 WHIRLPOOL(buf, lengths[testnum], whirlpool);
756 return count;
757}
758#endif
759
760#ifndef OPENSSL_NO_RMD160
761static int EVP_Digest_RMD160_loop(void *args)
762{
763 loopargs_t *tempargs = (loopargs_t *)args;
764 unsigned char *buf = tempargs->buf;
765 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
766 int count;
767 for (count = 0; COND(c[D_RMD160][testnum]); count++)
768 EVP_Digest(buf, (unsigned long)lengths[testnum], &(rmd160[0]), NULL,
769 EVP_ripemd160(), NULL);
770 return count;
771}
772#endif
773
774#ifndef OPENSSL_NO_RC4
775static RC4_KEY rc4_ks;
776static int RC4_loop(void *args)
777{
778 loopargs_t *tempargs = (loopargs_t *)args;
779 unsigned char *buf = tempargs->buf;
780 int count;
781 for (count = 0; COND(c[D_RC4][testnum]); count++)
782 RC4(&rc4_ks, (unsigned int)lengths[testnum], buf, buf);
783 return count;
784}
785#endif
786
787#ifndef OPENSSL_NO_DES
788static unsigned char DES_iv[8];
789static DES_key_schedule sch;
790static DES_key_schedule sch2;
791static DES_key_schedule sch3;
792static int DES_ncbc_encrypt_loop(void *args)
793{
794 loopargs_t *tempargs = (loopargs_t *)args;
795 unsigned char *buf = tempargs->buf;
796 int count;
797 for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
798 DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
799 &DES_iv, DES_ENCRYPT);
800 return count;
801}
802
803static int DES_ede3_cbc_encrypt_loop(void *args)
804{
805 loopargs_t *tempargs = (loopargs_t *)args;
806 unsigned char *buf = tempargs->buf;
807 int count;
808 for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
809 DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
810 &sch, &sch2, &sch3,
811 &DES_iv, DES_ENCRYPT);
812 return count;
813}
814#endif
815
Matt Caswell5158c762016-04-13 11:28:45 +0100816#define MAX_BLOCK_SIZE 128
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000817
818static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000819static AES_KEY aes_ks1, aes_ks2, aes_ks3;
820static int AES_cbc_128_encrypt_loop(void *args)
821{
822 loopargs_t *tempargs = (loopargs_t *)args;
823 unsigned char *buf = tempargs->buf;
824 int count;
825 for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
826 AES_cbc_encrypt(buf, buf,
827 (unsigned long)lengths[testnum], &aes_ks1,
828 iv, AES_ENCRYPT);
829 return count;
830}
831
832static int AES_cbc_192_encrypt_loop(void *args)
833{
834 loopargs_t *tempargs = (loopargs_t *)args;
835 unsigned char *buf = tempargs->buf;
836 int count;
837 for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
838 AES_cbc_encrypt(buf, buf,
839 (unsigned long)lengths[testnum], &aes_ks2,
840 iv, AES_ENCRYPT);
841 return count;
842}
843
844static int AES_cbc_256_encrypt_loop(void *args)
845{
846 loopargs_t *tempargs = (loopargs_t *)args;
847 unsigned char *buf = tempargs->buf;
848 int count;
849 for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
850 AES_cbc_encrypt(buf, buf,
851 (unsigned long)lengths[testnum], &aes_ks3,
852 iv, AES_ENCRYPT);
853 return count;
854}
855
856static int AES_ige_128_encrypt_loop(void *args)
857{
858 loopargs_t *tempargs = (loopargs_t *)args;
859 unsigned char *buf = tempargs->buf;
860 unsigned char *buf2 = tempargs->buf2;
861 int count;
862 for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
863 AES_ige_encrypt(buf, buf2,
864 (unsigned long)lengths[testnum], &aes_ks1,
865 iv, AES_ENCRYPT);
866 return count;
867}
868
869static int AES_ige_192_encrypt_loop(void *args)
870{
871 loopargs_t *tempargs = (loopargs_t *)args;
872 unsigned char *buf = tempargs->buf;
873 unsigned char *buf2 = tempargs->buf2;
874 int count;
875 for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
876 AES_ige_encrypt(buf, buf2,
877 (unsigned long)lengths[testnum], &aes_ks2,
878 iv, AES_ENCRYPT);
879 return count;
880}
881
882static int AES_ige_256_encrypt_loop(void *args)
883{
884 loopargs_t *tempargs = (loopargs_t *)args;
885 unsigned char *buf = tempargs->buf;
886 unsigned char *buf2 = tempargs->buf2;
887 int count;
888 for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
889 AES_ige_encrypt(buf, buf2,
890 (unsigned long)lengths[testnum], &aes_ks3,
891 iv, AES_ENCRYPT);
892 return count;
893}
894
895static int CRYPTO_gcm128_aad_loop(void *args)
896{
897 loopargs_t *tempargs = (loopargs_t *)args;
898 unsigned char *buf = tempargs->buf;
899 GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
900 int count;
901 for (count = 0; COND(c[D_GHASH][testnum]); count++)
902 CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
903 return count;
904}
905
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000906static int decrypt = 0;
907static int EVP_Update_loop(void *args)
908{
909 loopargs_t *tempargs = (loopargs_t *)args;
910 unsigned char *buf = tempargs->buf;
911 EVP_CIPHER_CTX *ctx = tempargs->ctx;
912 int outl, count;
913 if (decrypt)
914 for (count = 0;
915 COND(save_count * 4 * lengths[0] / lengths[testnum]);
916 count++)
917 EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
918 else
919 for (count = 0;
920 COND(save_count * 4 * lengths[0] / lengths[testnum]);
921 count++)
922 EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
923 if (decrypt)
924 EVP_DecryptFinal_ex(ctx, buf, &outl);
925 else
926 EVP_EncryptFinal_ex(ctx, buf, &outl);
927 return count;
928}
929
930static const EVP_MD *evp_md = NULL;
931static int EVP_Digest_loop(void *args)
932{
933 loopargs_t *tempargs = (loopargs_t *)args;
934 unsigned char *buf = tempargs->buf;
935 unsigned char md[EVP_MAX_MD_SIZE];
936 int count;
937 for (count = 0;
938 COND(save_count * 4 * lengths[0] / lengths[testnum]); count++)
939 EVP_Digest(buf, lengths[testnum], &(md[0]), NULL, evp_md, NULL);
940
941 return count;
942}
943
944#ifndef OPENSSL_NO_RSA
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000945static long rsa_c[RSA_NUM][2];
946
947static int RSA_sign_loop(void *args)
948{
949 loopargs_t *tempargs = (loopargs_t *)args;
950 unsigned char *buf = tempargs->buf;
951 unsigned char *buf2 = tempargs->buf2;
Andrea Grandi0ff43432016-02-18 10:56:53 +0000952 unsigned int *rsa_num = tempargs->siglen;
953 RSA **rsa_key = tempargs->rsa_key;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000954 int ret, count;
955 for (count = 0; COND(rsa_c[testnum][0]); count++) {
Andrea Grandi0ff43432016-02-18 10:56:53 +0000956 ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000957 if (ret == 0) {
958 BIO_printf(bio_err, "RSA sign failure\n");
959 ERR_print_errors(bio_err);
960 count = -1;
961 break;
962 }
963 }
964 return count;
965}
966
967static int RSA_verify_loop(void *args)
968{
969 loopargs_t *tempargs = (loopargs_t *)args;
970 unsigned char *buf = tempargs->buf;
971 unsigned char *buf2 = tempargs->buf2;
Andrea Grandi0ff43432016-02-18 10:56:53 +0000972 unsigned int rsa_num = *(tempargs->siglen);
973 RSA **rsa_key = tempargs->rsa_key;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000974 int ret, count;
975 for (count = 0; COND(rsa_c[testnum][1]); count++) {
976 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
977 if (ret <= 0) {
978 BIO_printf(bio_err, "RSA verify failure\n");
979 ERR_print_errors(bio_err);
980 count = -1;
981 break;
982 }
983 }
984 return count;
985}
986#endif
987
988#ifndef OPENSSL_NO_DSA
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000989static long dsa_c[DSA_NUM][2];
990static int DSA_sign_loop(void *args)
991{
992 loopargs_t *tempargs = (loopargs_t *)args;
993 unsigned char *buf = tempargs->buf;
994 unsigned char *buf2 = tempargs->buf2;
Andrea Grandi0ff43432016-02-18 10:56:53 +0000995 DSA **dsa_key = tempargs->dsa_key;
996 unsigned int *siglen = tempargs->siglen;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +0000997 int ret, count;
998 for (count = 0; COND(dsa_c[testnum][0]); count++) {
999 ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1000 if (ret == 0) {
1001 BIO_printf(bio_err, "DSA sign failure\n");
1002 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00001003 count = -1;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001004 break;
1005 }
1006 }
1007 return count;
1008}
1009
1010static int DSA_verify_loop(void *args)
1011{
1012 loopargs_t *tempargs = (loopargs_t *)args;
1013 unsigned char *buf = tempargs->buf;
1014 unsigned char *buf2 = tempargs->buf2;
Andrea Grandi0ff43432016-02-18 10:56:53 +00001015 DSA **dsa_key = tempargs->dsa_key;
1016 unsigned int siglen = *(tempargs->siglen);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001017 int ret, count;
1018 for (count = 0; COND(dsa_c[testnum][1]); count++) {
1019 ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
1020 if (ret <= 0) {
1021 BIO_printf(bio_err, "DSA verify failure\n");
1022 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00001023 count = -1;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001024 break;
1025 }
1026 }
1027 return count;
1028}
1029#endif
1030
1031#ifndef OPENSSL_NO_EC
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001032static long ecdsa_c[EC_NUM][2];
1033static int ECDSA_sign_loop(void *args)
1034{
1035 loopargs_t *tempargs = (loopargs_t *)args;
1036 unsigned char *buf = tempargs->buf;
Andrea Grandi0ff43432016-02-18 10:56:53 +00001037 EC_KEY **ecdsa = tempargs->ecdsa;
1038 unsigned char *ecdsasig = tempargs->buf2;
1039 unsigned int *ecdsasiglen = tempargs->siglen;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001040 int ret, count;
1041 for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
1042 ret = ECDSA_sign(0, buf, 20,
1043 ecdsasig, ecdsasiglen, ecdsa[testnum]);
1044 if (ret == 0) {
1045 BIO_printf(bio_err, "ECDSA sign failure\n");
1046 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00001047 count = -1;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001048 break;
1049 }
1050 }
1051 return count;
1052}
1053
1054static int ECDSA_verify_loop(void *args)
1055{
1056 loopargs_t *tempargs = (loopargs_t *)args;
1057 unsigned char *buf = tempargs->buf;
Andrea Grandi0ff43432016-02-18 10:56:53 +00001058 EC_KEY **ecdsa = tempargs->ecdsa;
1059 unsigned char *ecdsasig = tempargs->buf2;
1060 unsigned int ecdsasiglen = *(tempargs->siglen);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001061 int ret, count;
1062 for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
1063 ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
1064 ecdsa[testnum]);
1065 if (ret != 1) {
1066 BIO_printf(bio_err, "ECDSA verify failure\n");
1067 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00001068 count = -1;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001069 break;
1070 }
1071 }
1072 return count;
1073}
1074
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001075static int outlen;
1076static void *(*kdf) (const void *in, size_t inlen, void *out,
1077 size_t *xoutlen);
1078
1079static int ECDH_compute_key_loop(void *args)
1080{
Andrea Grandi0ff43432016-02-18 10:56:53 +00001081 loopargs_t *tempargs = (loopargs_t *)args;
1082 EC_KEY **ecdh_a = tempargs->ecdh_a;
1083 EC_KEY **ecdh_b = tempargs->ecdh_b;
1084 unsigned char *secret_a = tempargs->secret_a;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001085 int count;
1086 for (count = 0; COND(ecdh_c[testnum][0]); count++) {
1087 ECDH_compute_key(secret_a, outlen,
1088 EC_KEY_get0_public_key(ecdh_b[testnum]),
1089 ecdh_a[testnum], kdf);
1090 }
1091 return count;
1092}
1093#endif
1094
1095
1096static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs)
1097{
1098 int job_op_count = 0;
1099 int total_op_count = 0;
1100 int num_inprogress = 0;
1101 int error = 0;
1102 int i = 0;
Andrea Grandi1e613922016-02-29 11:28:55 +00001103 OSSL_ASYNC_FD job_fd = 0;
1104 size_t num_job_fds = 0;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001105
1106 run = 1;
1107
Andrea Grandi0ff43432016-02-18 10:56:53 +00001108 if (async_jobs == 0) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001109 return loop_function((void *)loopargs);
1110 }
1111
Andrea Grandi1e613922016-02-29 11:28:55 +00001112
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001113 for (i = 0; i < async_jobs && !error; i++) {
Andrea Grandi1e613922016-02-29 11:28:55 +00001114 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
1115 &job_op_count, loop_function,
1116 (void *)(loopargs + i), sizeof(loopargs_t))) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001117 case ASYNC_PAUSE:
1118 ++num_inprogress;
1119 break;
1120 case ASYNC_FINISH:
1121 if (job_op_count == -1) {
1122 error = 1;
1123 } else {
1124 total_op_count += job_op_count;
1125 }
1126 break;
1127 case ASYNC_NO_JOBS:
1128 case ASYNC_ERR:
1129 BIO_printf(bio_err, "Failure in the job\n");
1130 ERR_print_errors(bio_err);
1131 error = 1;
1132 break;
1133 }
1134 }
1135
Andrea Grandi1e613922016-02-29 11:28:55 +00001136 while (num_inprogress > 0) {
Andrea Grandi2ea92602016-03-08 04:51:04 +00001137#if defined(OPENSSL_SYS_WINDOWS)
Andrea Grandi564e1022016-03-03 07:09:00 +00001138 DWORD avail = 0;
Andrea Grandi2ea92602016-03-08 04:51:04 +00001139#elif defined(OPENSSL_SYS_UNIX)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001140 int select_result = 0;
Andrea Grandi564e1022016-03-03 07:09:00 +00001141 OSSL_ASYNC_FD max_fd = 0;
1142 fd_set waitfdset;
Andrea Grandi363a1fc2016-03-07 11:20:01 +00001143
Andrea Grandi564e1022016-03-03 07:09:00 +00001144 FD_ZERO(&waitfdset);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001145
Andrea Grandi564e1022016-03-03 07:09:00 +00001146 for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
1147 if (loopargs[i].inprogress_job == NULL)
1148 continue;
Andrea Grandi1e613922016-02-29 11:28:55 +00001149
Andrea Grandi564e1022016-03-03 07:09:00 +00001150 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1151 || num_job_fds > 1) {
1152 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1153 ERR_print_errors(bio_err);
1154 error = 1;
1155 break;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001156 }
Andrea Grandi564e1022016-03-03 07:09:00 +00001157 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
1158 FD_SET(job_fd, &waitfdset);
1159 if (job_fd > max_fd)
1160 max_fd = job_fd;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001161 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001162
Ben Laurie402ec2f2016-04-15 09:45:25 +01001163 if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
Andrea Grandi570c0712016-03-25 04:19:30 +00001164 BIO_printf(bio_err,
1165 "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
1166 "Decrease the value of async_jobs\n",
1167 max_fd, FD_SETSIZE);
1168 ERR_print_errors(bio_err);
1169 error = 1;
1170 break;
1171 }
1172
Andrea Grandi564e1022016-03-03 07:09:00 +00001173 select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001174 if (select_result == -1 && errno == EINTR)
1175 continue;
1176
1177 if (select_result == -1) {
Andrea Grandi564e1022016-03-03 07:09:00 +00001178 BIO_printf(bio_err, "Failure in the select\n");
1179 ERR_print_errors(bio_err);
1180 error = 1;
1181 break;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001182 }
1183
1184 if (select_result == 0)
1185 continue;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001186#endif
1187
1188 for (i = 0; i < async_jobs; i++) {
1189 if (loopargs[i].inprogress_job == NULL)
1190 continue;
1191
Andrea Grandi1e613922016-02-29 11:28:55 +00001192 if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds)
1193 || num_job_fds > 1) {
1194 BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
1195 ERR_print_errors(bio_err);
1196 error = 1;
1197 break;
1198 }
1199 ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001200
Matt Caswell667867c2016-03-07 16:55:39 +00001201#if defined(OPENSSL_SYS_UNIX)
Andrea Grandi1e613922016-02-29 11:28:55 +00001202 if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001203 continue;
Matt Caswell667867c2016-03-07 16:55:39 +00001204#elif defined(OPENSSL_SYS_WINDOWS)
Andrea Grandi1e613922016-02-29 11:28:55 +00001205 if (num_job_fds == 1 &&
1206 !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001207 continue;
1208#endif
1209
Andrea Grandi1e613922016-02-29 11:28:55 +00001210 switch (ASYNC_start_job(&(loopargs[i].inprogress_job), loopargs[i].wait_ctx,
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001211 &job_op_count, loop_function, (void *)(loopargs + i),
1212 sizeof(loopargs_t))) {
1213 case ASYNC_PAUSE:
1214 break;
1215 case ASYNC_FINISH:
1216 if (job_op_count == -1) {
1217 error = 1;
1218 } else {
1219 total_op_count += job_op_count;
1220 }
1221 --num_inprogress;
1222 loopargs[i].inprogress_job = NULL;
1223 break;
1224 case ASYNC_NO_JOBS:
1225 case ASYNC_ERR:
1226 --num_inprogress;
1227 loopargs[i].inprogress_job = NULL;
1228 BIO_printf(bio_err, "Failure in the job\n");
1229 ERR_print_errors(bio_err);
1230 error = 1;
1231 break;
1232 }
1233 }
1234 }
1235
1236 return error ? -1 : total_op_count;
1237}
1238
Rich Salz7e1b7482015-04-24 15:26:15 -04001239int speed_main(int argc, char **argv)
1240{
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001241 loopargs_t *loopargs = NULL;
1242 int loopargs_len = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001243 char *prog;
1244 const EVP_CIPHER *evp_cipher = NULL;
Rich Salz7e1b7482015-04-24 15:26:15 -04001245 double d = 0.0;
1246 OPTION_CHOICE o;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001247 int multiblock = 0, doit[ALGOR_NUM], pr_header = 0;
Matt Caswell83ae8122016-03-18 17:43:58 +00001248#ifndef OPENSSL_NO_DSA
1249 int dsa_doit[DSA_NUM];
1250#endif
1251 int rsa_doit[RSA_NUM];
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001252 int ret = 1, i, k, misalign = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001253 long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001254#ifndef NO_FORK
1255 int multi = 0;
1256#endif
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001257 int async_jobs = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001258 /* What follows are the buffers and key material. */
Rich Salza00ae6c2015-01-27 10:06:22 -05001259#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
Andrea Grandi0ff43432016-02-18 10:56:53 +00001260 long rsa_count = 1;
Rich Salza00ae6c2015-01-27 10:06:22 -05001261#endif
Rich Salza00ae6c2015-01-27 10:06:22 -05001262#ifndef OPENSSL_NO_RC5
Matt Caswell0f113f32015-01-22 03:40:55 +00001263 RC5_32_KEY rc5_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001264#endif
1265#ifndef OPENSSL_NO_RC2
Matt Caswell0f113f32015-01-22 03:40:55 +00001266 RC2_KEY rc2_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001267#endif
1268#ifndef OPENSSL_NO_IDEA
Matt Caswell0f113f32015-01-22 03:40:55 +00001269 IDEA_KEY_SCHEDULE idea_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001270#endif
1271#ifndef OPENSSL_NO_SEED
Matt Caswell0f113f32015-01-22 03:40:55 +00001272 SEED_KEY_SCHEDULE seed_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001273#endif
1274#ifndef OPENSSL_NO_BF
Matt Caswell0f113f32015-01-22 03:40:55 +00001275 BF_KEY bf_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001276#endif
1277#ifndef OPENSSL_NO_CAST
Matt Caswell0f113f32015-01-22 03:40:55 +00001278 CAST_KEY cast_ks;
Rich Salza00ae6c2015-01-27 10:06:22 -05001279#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001280 static const unsigned char key16[16] = {
1281 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1282 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1283 };
Matt Caswell0f113f32015-01-22 03:40:55 +00001284 static const unsigned char key24[24] = {
1285 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1286 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1287 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1288 };
1289 static const unsigned char key32[32] = {
1290 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1291 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1292 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1293 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1294 };
Rich Salza00ae6c2015-01-27 10:06:22 -05001295#ifndef OPENSSL_NO_CAMELLIA
Matt Caswell0f113f32015-01-22 03:40:55 +00001296 static const unsigned char ckey24[24] = {
1297 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1298 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1299 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1300 };
1301 static const unsigned char ckey32[32] = {
1302 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
1303 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
1304 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
1305 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
1306 };
Rich Salz7e1b7482015-04-24 15:26:15 -04001307 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
Rich Salza00ae6c2015-01-27 10:06:22 -05001308#endif
Rich Salza00ae6c2015-01-27 10:06:22 -05001309#ifndef OPENSSL_NO_DES
Rich Salz7e1b7482015-04-24 15:26:15 -04001310 static DES_cblock key = {
1311 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
1312 };
1313 static DES_cblock key2 = {
1314 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
1315 };
1316 static DES_cblock key3 = {
1317 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
1318 };
Rich Salza00ae6c2015-01-27 10:06:22 -05001319#endif
Rich Salza00ae6c2015-01-27 10:06:22 -05001320#ifndef OPENSSL_NO_RSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001321 static unsigned int rsa_bits[RSA_NUM] = {
1322 512, 1024, 2048, 3072, 4096, 7680, 15360
1323 };
1324 static unsigned char *rsa_data[RSA_NUM] = {
1325 test512, test1024, test2048, test3072, test4096, test7680, test15360
1326 };
1327 static int rsa_data_length[RSA_NUM] = {
1328 sizeof(test512), sizeof(test1024),
1329 sizeof(test2048), sizeof(test3072),
1330 sizeof(test4096), sizeof(test7680),
1331 sizeof(test15360)
1332 };
Rich Salza00ae6c2015-01-27 10:06:22 -05001333#endif
1334#ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001335 static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
Rich Salza00ae6c2015-01-27 10:06:22 -05001336#endif
1337#ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00001338 /*
1339 * We only test over the following curves as they are representative, To
1340 * add tests over more curves, simply add the curve NID and curve name to
1341 * the following arrays and increase the EC_NUM value accordingly.
1342 */
1343 static unsigned int test_curves[EC_NUM] = {
1344 /* Prime Curves */
Rich Salz7e1b7482015-04-24 15:26:15 -04001345 NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1,
1346 NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1,
Matt Caswell0f113f32015-01-22 03:40:55 +00001347 /* Binary Curves */
Rich Salz7e1b7482015-04-24 15:26:15 -04001348 NID_sect163k1, NID_sect233k1, NID_sect283k1,
1349 NID_sect409k1, NID_sect571k1, NID_sect163r2,
1350 NID_sect233r1, NID_sect283r1, NID_sect409r1,
Dr. Stephen Hensondb50c1d2016-02-12 14:11:47 +00001351 NID_sect571r1,
1352 /* Other */
1353 NID_X25519
Matt Caswell0f113f32015-01-22 03:40:55 +00001354 };
1355 static const char *test_curves_names[EC_NUM] = {
1356 /* Prime Curves */
Rich Salz7e1b7482015-04-24 15:26:15 -04001357 "secp160r1", "nistp192", "nistp224",
1358 "nistp256", "nistp384", "nistp521",
Matt Caswell0f113f32015-01-22 03:40:55 +00001359 /* Binary Curves */
Rich Salz7e1b7482015-04-24 15:26:15 -04001360 "nistk163", "nistk233", "nistk283",
1361 "nistk409", "nistk571", "nistb163",
1362 "nistb233", "nistb283", "nistb409",
Dr. Stephen Hensondb50c1d2016-02-12 14:11:47 +00001363 "nistb571",
1364 /* Other */
1365 "X25519"
Matt Caswell0f113f32015-01-22 03:40:55 +00001366 };
1367 static int test_curves_bits[EC_NUM] = {
Rich Salz7e1b7482015-04-24 15:26:15 -04001368 160, 192, 224,
1369 256, 384, 521,
1370 163, 233, 283,
1371 409, 571, 163,
1372 233, 283, 409,
Dr. Stephen Hensondb50c1d2016-02-12 14:11:47 +00001373 571, 253 /* X25519 */
Matt Caswell0f113f32015-01-22 03:40:55 +00001374 };
Rich Salza00ae6c2015-01-27 10:06:22 -05001375#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04001376#ifndef OPENSSL_NO_EC
Rich Salz7e1b7482015-04-24 15:26:15 -04001377 int ecdsa_doit[EC_NUM];
Matt Caswell0f113f32015-01-22 03:40:55 +00001378 int secret_size_a, secret_size_b;
Andrea Grandi0ff43432016-02-18 10:56:53 +00001379 int ecdh_checks = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00001380 int secret_idx = 0;
1381 long ecdh_c[EC_NUM][2];
Rich Salz10bf4fc2015-03-10 19:09:27 -04001382 int ecdh_doit[EC_NUM];
Rich Salza00ae6c2015-01-27 10:06:22 -05001383#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001384
Matt Caswell0f113f32015-01-22 03:40:55 +00001385 memset(results, 0, sizeof(results));
Dr. Stephen Henson3647bee2002-02-22 14:01:21 +00001386
Matt Caswell0f113f32015-01-22 03:40:55 +00001387 memset(c, 0, sizeof(c));
Matt Caswell96bea002016-03-18 15:56:06 +00001388#ifndef OPENSSL_NO_DES
Matt Caswell0f113f32015-01-22 03:40:55 +00001389 memset(DES_iv, 0, sizeof(DES_iv));
Matt Caswell96bea002016-03-18 15:56:06 +00001390#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001391 memset(iv, 0, sizeof(iv));
Andy Polyakove2d03db2014-08-30 10:25:32 +02001392
Matt Caswell0f113f32015-01-22 03:40:55 +00001393 for (i = 0; i < ALGOR_NUM; i++)
1394 doit[i] = 0;
1395 for (i = 0; i < RSA_NUM; i++)
1396 rsa_doit[i] = 0;
Matt Caswell83ae8122016-03-18 17:43:58 +00001397#ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001398 for (i = 0; i < DSA_NUM; i++)
1399 dsa_doit[i] = 0;
Matt Caswell83ae8122016-03-18 17:43:58 +00001400#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04001401#ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00001402 for (i = 0; i < EC_NUM; i++)
1403 ecdsa_doit[i] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00001404 for (i = 0; i < EC_NUM; i++)
1405 ecdh_doit[i] = 0;
Rich Salza00ae6c2015-01-27 10:06:22 -05001406#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001407
Rich Salz7e1b7482015-04-24 15:26:15 -04001408 misalign = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001409
1410 prog = opt_init(argc, argv, speed_options);
1411 while ((o = opt_next()) != OPT_EOF) {
1412 switch (o) {
1413 case OPT_EOF:
1414 case OPT_ERR:
1415 opterr:
1416 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1417 goto end;
1418 case OPT_HELP:
1419 opt_help(speed_options);
1420 ret = 0;
1421 goto end;
1422 case OPT_ELAPSED:
Matt Caswell0f113f32015-01-22 03:40:55 +00001423 usertime = 0;
Rich Salz7e1b7482015-04-24 15:26:15 -04001424 break;
1425 case OPT_EVP:
1426 evp_cipher = EVP_get_cipherbyname(opt_arg());
1427 if (evp_cipher == NULL)
1428 evp_md = EVP_get_digestbyname(opt_arg());
1429 if (evp_cipher == NULL && evp_md == NULL) {
1430 BIO_printf(bio_err,
1431 "%s: %s an unknown cipher or digest\n",
1432 prog, opt_arg());
Matt Caswell0f113f32015-01-22 03:40:55 +00001433 goto end;
1434 }
1435 doit[D_EVP] = 1;
Rich Salz7e1b7482015-04-24 15:26:15 -04001436 break;
1437 case OPT_DECRYPT:
Matt Caswell0f113f32015-01-22 03:40:55 +00001438 decrypt = 1;
Rich Salz7e1b7482015-04-24 15:26:15 -04001439 break;
Rich Salz7e1b7482015-04-24 15:26:15 -04001440 case OPT_ENGINE:
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001441 /*
1442 * In a forked execution, an engine might need to be
1443 * initialised by each child process, not by the parent.
1444 * So store the name here and run setup_engine() later on.
1445 */
1446 engine_id = opt_arg();
Rich Salz7e1b7482015-04-24 15:26:15 -04001447 break;
Rich Salz7e1b7482015-04-24 15:26:15 -04001448 case OPT_MULTI:
Rich Salz9c3bcfa2015-05-15 13:50:38 -04001449#ifndef NO_FORK
Rich Salz7e1b7482015-04-24 15:26:15 -04001450 multi = atoi(opt_arg());
Rich Salza00ae6c2015-01-27 10:06:22 -05001451#endif
Rich Salz9c3bcfa2015-05-15 13:50:38 -04001452 break;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001453 case OPT_ASYNCJOBS:
Matt Caswell667867c2016-03-07 16:55:39 +00001454#ifndef OPENSSL_NO_ASYNC
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001455 async_jobs = atoi(opt_arg());
Matt Caswell667867c2016-03-07 16:55:39 +00001456 if (!ASYNC_is_capable()) {
1457 BIO_printf(bio_err,
1458 "%s: async_jobs specified but async not supported\n",
1459 prog);
1460 goto opterr;
1461 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001462#endif
1463 break;
Rich Salz7e1b7482015-04-24 15:26:15 -04001464 case OPT_MISALIGN:
1465 if (!opt_int(opt_arg(), &misalign))
Matt Caswell0f113f32015-01-22 03:40:55 +00001466 goto end;
Rich Salz7e1b7482015-04-24 15:26:15 -04001467 if (misalign > MISALIGN) {
Matt Caswell0f113f32015-01-22 03:40:55 +00001468 BIO_printf(bio_err,
Rich Salz7e1b7482015-04-24 15:26:15 -04001469 "%s: Maximum offset is %d\n", prog, MISALIGN);
1470 goto opterr;
Matt Caswell0f113f32015-01-22 03:40:55 +00001471 }
Rich Salz7e1b7482015-04-24 15:26:15 -04001472 break;
1473 case OPT_MR:
1474 mr = 1;
1475 break;
1476 case OPT_MB:
1477 multiblock = 1;
1478 break;
1479 }
1480 }
1481 argc = opt_num_rest();
1482 argv = opt_rest();
1483
1484 /* Remaining arguments are algorithms. */
1485 for ( ; *argv; argv++) {
1486 if (found(*argv, doit_choices, &i)) {
1487 doit[i] = 1;
1488 continue;
1489 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001490#ifndef OPENSSL_NO_DES
Rich Salz7e1b7482015-04-24 15:26:15 -04001491 if (strcmp(*argv, "des") == 0) {
1492 doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
1493 continue;
1494 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001495#endif
Rich Salz7e1b7482015-04-24 15:26:15 -04001496 if (strcmp(*argv, "sha") == 0) {
1497 doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
1498 continue;
1499 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001500#ifndef OPENSSL_NO_RSA
Rich Salza00ae6c2015-01-27 10:06:22 -05001501# ifndef RSA_NULL
Matt Caswell0f113f32015-01-22 03:40:55 +00001502 if (strcmp(*argv, "openssl") == 0) {
Rich Salzb0700d22015-10-27 15:11:48 -04001503 RSA_set_default_method(RSA_PKCS1_OpenSSL());
Rich Salz7e1b7482015-04-24 15:26:15 -04001504 continue;
1505 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001506# endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001507 if (strcmp(*argv, "rsa") == 0) {
Rich Salz7e1b7482015-04-24 15:26:15 -04001508 rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] =
1509 rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] =
1510 rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] =
1511 rsa_doit[R_RSA_15360] = 1;
1512 continue;
1513 }
1514 if (found(*argv, rsa_choices, &i)) {
1515 rsa_doit[i] = 1;
1516 continue;
1517 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001518#endif
1519#ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001520 if (strcmp(*argv, "dsa") == 0) {
Rich Salz7e1b7482015-04-24 15:26:15 -04001521 dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] =
1522 dsa_doit[R_DSA_2048] = 1;
1523 continue;
1524 }
1525 if (found(*argv, dsa_choices, &i)) {
1526 dsa_doit[i] = 2;
1527 continue;
1528 }
1529#endif
Rich Salz7e1b7482015-04-24 15:26:15 -04001530 if (strcmp(*argv, "aes") == 0) {
1531 doit[D_CBC_128_AES] = doit[D_CBC_192_AES] =
1532 doit[D_CBC_256_AES] = 1;
1533 continue;
1534 }
Rich Salz7e1b7482015-04-24 15:26:15 -04001535#ifndef OPENSSL_NO_CAMELLIA
1536 if (strcmp(*argv, "camellia") == 0) {
1537 doit[D_CBC_128_CML] = doit[D_CBC_192_CML] =
1538 doit[D_CBC_256_CML] = 1;
1539 continue;
1540 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001541#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04001542#ifndef OPENSSL_NO_EC
Rich Salz7e1b7482015-04-24 15:26:15 -04001543 if (strcmp(*argv, "ecdsa") == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00001544 for (i = 0; i < EC_NUM; i++)
1545 ecdsa_doit[i] = 1;
Rich Salz7e1b7482015-04-24 15:26:15 -04001546 continue;
1547 }
1548 if (found(*argv, ecdsa_choices, &i)) {
1549 ecdsa_doit[i] = 2;
1550 continue;
1551 }
1552 if (strcmp(*argv, "ecdh") == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00001553 for (i = 0; i < EC_NUM; i++)
1554 ecdh_doit[i] = 1;
Rich Salz7e1b7482015-04-24 15:26:15 -04001555 continue;
Matt Caswell0f113f32015-01-22 03:40:55 +00001556 }
Rich Salz7e1b7482015-04-24 15:26:15 -04001557 if (found(*argv, ecdh_choices, &i)) {
1558 ecdh_doit[i] = 2;
1559 continue;
1560 }
1561#endif
1562 BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
1563 goto end;
Matt Caswell0f113f32015-01-22 03:40:55 +00001564 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001565
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001566 /* Initialize the job pool if async mode is enabled */
1567 if (async_jobs > 0) {
1568 if (!ASYNC_init_thread(async_jobs, async_jobs)) {
1569 BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
1570 goto end;
1571 }
1572 }
1573
1574 loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
1575 loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
1576 memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
1577
Andrea Grandi0ff43432016-02-18 10:56:53 +00001578 for (i = 0; i < loopargs_len; i++) {
Andrea Grandi1e613922016-02-29 11:28:55 +00001579 if (async_jobs > 0) {
1580 loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
1581 if (loopargs[i].wait_ctx == NULL) {
1582 BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
1583 goto end;
1584 }
1585 }
1586
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001587 loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1588 loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer");
1589 /* Align the start of buffers on a 64 byte boundary */
1590 loopargs[i].buf = loopargs[i].buf_malloc + misalign;
1591 loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
Andrea Grandi0ff43432016-02-18 10:56:53 +00001592 loopargs[i].siglen = app_malloc(sizeof(unsigned int), "signature length");
Andrea Grandi0ff43432016-02-18 10:56:53 +00001593#ifndef OPENSSL_NO_EC
Andrea Grandi0ff43432016-02-18 10:56:53 +00001594 loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
1595 loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
1596#endif
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001597 }
1598
Rich Salza00ae6c2015-01-27 10:06:22 -05001599#ifndef NO_FORK
Matt Caswell0f113f32015-01-22 03:40:55 +00001600 if (multi && do_multi(multi))
1601 goto show_res;
Rich Salza00ae6c2015-01-27 10:06:22 -05001602#endif
Ben Laurie0e211562001-10-25 14:27:17 +00001603
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001604 /* Initialize the engine after the fork */
1605 (void)setup_engine(engine_id, 0);
1606
Rich Salz7e1b7482015-04-24 15:26:15 -04001607 /* No parameters; turn on everything. */
Tim Hudsondfba17b2015-08-17 22:20:06 +10001608 if ((argc == 0) && !doit[D_EVP]) {
Rich Salz7e1b7482015-04-24 15:26:15 -04001609 for (i = 0; i < ALGOR_NUM; i++)
Matt Caswell0f113f32015-01-22 03:40:55 +00001610 if (i != D_EVP)
1611 doit[i] = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00001612 for (i = 0; i < RSA_NUM; i++)
1613 rsa_doit[i] = 1;
Matt Caswell83ae8122016-03-18 17:43:58 +00001614#ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001615 for (i = 0; i < DSA_NUM; i++)
1616 dsa_doit[i] = 1;
Matt Caswell83ae8122016-03-18 17:43:58 +00001617#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04001618#ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00001619 for (i = 0; i < EC_NUM; i++)
1620 ecdsa_doit[i] = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00001621 for (i = 0; i < EC_NUM; i++)
1622 ecdh_doit[i] = 1;
Rich Salza00ae6c2015-01-27 10:06:22 -05001623#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001624 }
1625 for (i = 0; i < ALGOR_NUM; i++)
1626 if (doit[i])
1627 pr_header++;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001628
Matt Caswell0f113f32015-01-22 03:40:55 +00001629 if (usertime == 0 && !mr)
1630 BIO_printf(bio_err,
1631 "You have chosen to measure elapsed time "
1632 "instead of user CPU time.\n");
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001633
Rich Salza00ae6c2015-01-27 10:06:22 -05001634#ifndef OPENSSL_NO_RSA
Andrea Grandi0ff43432016-02-18 10:56:53 +00001635 for (i = 0; i < loopargs_len; i++) {
1636 for (k = 0; k < RSA_NUM; k++) {
1637 const unsigned char *p;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001638
Andrea Grandi0ff43432016-02-18 10:56:53 +00001639 p = rsa_data[k];
1640 loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
1641 if (loopargs[i].rsa_key[k] == NULL) {
1642 BIO_printf(bio_err, "internal error loading RSA key number %d\n",
1643 k);
1644 goto end;
1645 }
Matt Caswell0f113f32015-01-22 03:40:55 +00001646 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001647 }
1648#endif
Rich Salza00ae6c2015-01-27 10:06:22 -05001649#ifndef OPENSSL_NO_DSA
Andrea Grandi0ff43432016-02-18 10:56:53 +00001650 for (i = 0; i < loopargs_len; i++) {
1651 loopargs[i].dsa_key[0] = get_dsa512();
1652 loopargs[i].dsa_key[1] = get_dsa1024();
1653 loopargs[i].dsa_key[2] = get_dsa2048();
1654 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001655#endif
Rich Salza00ae6c2015-01-27 10:06:22 -05001656#ifndef OPENSSL_NO_DES
Matt Caswell0f113f32015-01-22 03:40:55 +00001657 DES_set_key_unchecked(&key, &sch);
1658 DES_set_key_unchecked(&key2, &sch2);
1659 DES_set_key_unchecked(&key3, &sch3);
Rich Salza00ae6c2015-01-27 10:06:22 -05001660#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001661 AES_set_encrypt_key(key16, 128, &aes_ks1);
1662 AES_set_encrypt_key(key24, 192, &aes_ks2);
1663 AES_set_encrypt_key(key32, 256, &aes_ks3);
Rich Salza00ae6c2015-01-27 10:06:22 -05001664#ifndef OPENSSL_NO_CAMELLIA
Matt Caswell0f113f32015-01-22 03:40:55 +00001665 Camellia_set_key(key16, 128, &camellia_ks1);
1666 Camellia_set_key(ckey24, 192, &camellia_ks2);
1667 Camellia_set_key(ckey32, 256, &camellia_ks3);
Rich Salza00ae6c2015-01-27 10:06:22 -05001668#endif
1669#ifndef OPENSSL_NO_IDEA
Matt Caswell0f113f32015-01-22 03:40:55 +00001670 idea_set_encrypt_key(key16, &idea_ks);
Rich Salza00ae6c2015-01-27 10:06:22 -05001671#endif
1672#ifndef OPENSSL_NO_SEED
Matt Caswell0f113f32015-01-22 03:40:55 +00001673 SEED_set_key(key16, &seed_ks);
Rich Salza00ae6c2015-01-27 10:06:22 -05001674#endif
1675#ifndef OPENSSL_NO_RC4
Matt Caswell0f113f32015-01-22 03:40:55 +00001676 RC4_set_key(&rc4_ks, 16, key16);
Rich Salza00ae6c2015-01-27 10:06:22 -05001677#endif
1678#ifndef OPENSSL_NO_RC2
Matt Caswell0f113f32015-01-22 03:40:55 +00001679 RC2_set_key(&rc2_ks, 16, key16, 128);
Rich Salza00ae6c2015-01-27 10:06:22 -05001680#endif
1681#ifndef OPENSSL_NO_RC5
Matt Caswell0f113f32015-01-22 03:40:55 +00001682 RC5_32_set_key(&rc5_ks, 16, key16, 12);
Rich Salza00ae6c2015-01-27 10:06:22 -05001683#endif
1684#ifndef OPENSSL_NO_BF
Matt Caswell0f113f32015-01-22 03:40:55 +00001685 BF_set_key(&bf_ks, 16, key16);
Rich Salza00ae6c2015-01-27 10:06:22 -05001686#endif
1687#ifndef OPENSSL_NO_CAST
Matt Caswell0f113f32015-01-22 03:40:55 +00001688 CAST_set_key(&cast_ks, 16, key16);
Rich Salza00ae6c2015-01-27 10:06:22 -05001689#endif
1690#ifndef OPENSSL_NO_RSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001691 memset(rsa_c, 0, sizeof(rsa_c));
Rich Salza00ae6c2015-01-27 10:06:22 -05001692#endif
1693#ifndef SIGALRM
1694# ifndef OPENSSL_NO_DES
Matt Caswell0f113f32015-01-22 03:40:55 +00001695 BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
1696 count = 10;
1697 do {
1698 long it;
1699 count *= 2;
1700 Time_F(START);
1701 for (it = count; it; it--)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001702 DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
1703 (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
Matt Caswell0f113f32015-01-22 03:40:55 +00001704 d = Time_F(STOP);
1705 } while (d < 3);
1706 save_count = count;
1707 c[D_MD2][0] = count / 10;
1708 c[D_MDC2][0] = count / 10;
1709 c[D_MD4][0] = count;
1710 c[D_MD5][0] = count;
1711 c[D_HMAC][0] = count;
1712 c[D_SHA1][0] = count;
1713 c[D_RMD160][0] = count;
1714 c[D_RC4][0] = count * 5;
1715 c[D_CBC_DES][0] = count;
1716 c[D_EDE3_DES][0] = count / 3;
1717 c[D_CBC_IDEA][0] = count;
1718 c[D_CBC_SEED][0] = count;
1719 c[D_CBC_RC2][0] = count;
1720 c[D_CBC_RC5][0] = count;
1721 c[D_CBC_BF][0] = count;
1722 c[D_CBC_CAST][0] = count;
1723 c[D_CBC_128_AES][0] = count;
1724 c[D_CBC_192_AES][0] = count;
1725 c[D_CBC_256_AES][0] = count;
1726 c[D_CBC_128_CML][0] = count;
1727 c[D_CBC_192_CML][0] = count;
1728 c[D_CBC_256_CML][0] = count;
1729 c[D_SHA256][0] = count;
1730 c[D_SHA512][0] = count;
1731 c[D_WHIRLPOOL][0] = count;
1732 c[D_IGE_128_AES][0] = count;
1733 c[D_IGE_192_AES][0] = count;
1734 c[D_IGE_256_AES][0] = count;
1735 c[D_GHASH][0] = count;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001736
Matt Caswell0f113f32015-01-22 03:40:55 +00001737 for (i = 1; i < SIZE_NUM; i++) {
1738 long l0, l1;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001739
Matt Caswell0f113f32015-01-22 03:40:55 +00001740 l0 = (long)lengths[0];
1741 l1 = (long)lengths[i];
Felix Laurie von Massenbach8c9336c2014-05-26 21:58:55 +01001742
Matt Caswell0f113f32015-01-22 03:40:55 +00001743 c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
1744 c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
1745 c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
1746 c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
1747 c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
1748 c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
1749 c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
1750 c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
1751 c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
1752 c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
Andy Polyakov6d9843e2016-02-12 14:53:51 +01001753 c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
Matt Caswelldd703de2014-11-24 10:05:04 +00001754
Matt Caswell0f113f32015-01-22 03:40:55 +00001755 l0 = (long)lengths[i - 1];
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001756
Matt Caswell0f113f32015-01-22 03:40:55 +00001757 c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
1758 c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
1759 c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
1760 c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
1761 c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
1762 c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
1763 c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
1764 c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
1765 c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
1766 c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
1767 c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
1768 c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
1769 c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
1770 c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
1771 c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
1772 c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
1773 c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
1774 c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
1775 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001776
Rich Salza00ae6c2015-01-27 10:06:22 -05001777# ifndef OPENSSL_NO_RSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001778 rsa_c[R_RSA_512][0] = count / 2000;
1779 rsa_c[R_RSA_512][1] = count / 400;
1780 for (i = 1; i < RSA_NUM; i++) {
1781 rsa_c[i][0] = rsa_c[i - 1][0] / 8;
1782 rsa_c[i][1] = rsa_c[i - 1][1] / 4;
1783 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1784 rsa_doit[i] = 0;
1785 else {
1786 if (rsa_c[i][0] == 0) {
1787 rsa_c[i][0] = 1;
1788 rsa_c[i][1] = 20;
1789 }
1790 }
1791 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001792# endif
Bodo Möllere172d602002-08-09 08:43:04 +00001793
Rich Salza00ae6c2015-01-27 10:06:22 -05001794# ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00001795 dsa_c[R_DSA_512][0] = count / 1000;
1796 dsa_c[R_DSA_512][1] = count / 1000 / 2;
1797 for (i = 1; i < DSA_NUM; i++) {
1798 dsa_c[i][0] = dsa_c[i - 1][0] / 4;
1799 dsa_c[i][1] = dsa_c[i - 1][1] / 4;
1800 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1801 dsa_doit[i] = 0;
1802 else {
1803 if (dsa_c[i] == 0) {
1804 dsa_c[i][0] = 1;
1805 dsa_c[i][1] = 1;
1806 }
1807 }
1808 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001809# endif
Bodo Möllere172d602002-08-09 08:43:04 +00001810
Rich Salz10bf4fc2015-03-10 19:09:27 -04001811# ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00001812 ecdsa_c[R_EC_P160][0] = count / 1000;
1813 ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
1814 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1815 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1816 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1817 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1818 ecdsa_doit[i] = 0;
1819 else {
1820 if (ecdsa_c[i] == 0) {
1821 ecdsa_c[i][0] = 1;
1822 ecdsa_c[i][1] = 1;
1823 }
1824 }
1825 }
1826 ecdsa_c[R_EC_K163][0] = count / 1000;
1827 ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
1828 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1829 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1830 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1831 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1832 ecdsa_doit[i] = 0;
1833 else {
1834 if (ecdsa_c[i] == 0) {
1835 ecdsa_c[i][0] = 1;
1836 ecdsa_c[i][1] = 1;
1837 }
1838 }
1839 }
1840 ecdsa_c[R_EC_B163][0] = count / 1000;
1841 ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
1842 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1843 ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
1844 ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
1845 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1846 ecdsa_doit[i] = 0;
1847 else {
1848 if (ecdsa_c[i] == 0) {
1849 ecdsa_c[i][0] = 1;
1850 ecdsa_c[i][1] = 1;
1851 }
1852 }
1853 }
Rich Salz7e1b7482015-04-24 15:26:15 -04001854
Matt Caswell0f113f32015-01-22 03:40:55 +00001855 ecdh_c[R_EC_P160][0] = count / 1000;
1856 ecdh_c[R_EC_P160][1] = count / 1000;
1857 for (i = R_EC_P192; i <= R_EC_P521; i++) {
1858 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1859 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1860 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1861 ecdh_doit[i] = 0;
1862 else {
1863 if (ecdh_c[i] == 0) {
1864 ecdh_c[i][0] = 1;
1865 ecdh_c[i][1] = 1;
1866 }
1867 }
1868 }
1869 ecdh_c[R_EC_K163][0] = count / 1000;
1870 ecdh_c[R_EC_K163][1] = count / 1000;
1871 for (i = R_EC_K233; i <= R_EC_K571; i++) {
1872 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1873 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1874 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1875 ecdh_doit[i] = 0;
1876 else {
1877 if (ecdh_c[i] == 0) {
1878 ecdh_c[i][0] = 1;
1879 ecdh_c[i][1] = 1;
1880 }
1881 }
1882 }
1883 ecdh_c[R_EC_B163][0] = count / 1000;
1884 ecdh_c[R_EC_B163][1] = count / 1000;
1885 for (i = R_EC_B233; i <= R_EC_B571; i++) {
1886 ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
1887 ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
1888 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1889 ecdh_doit[i] = 0;
1890 else {
1891 if (ecdh_c[i] == 0) {
1892 ecdh_c[i][0] = 1;
1893 ecdh_c[i][1] = 1;
1894 }
1895 }
1896 }
Matt Caswell0f113f32015-01-22 03:40:55 +00001897# endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001898
Rich Salza00ae6c2015-01-27 10:06:22 -05001899# else
1900/* not worth fixing */
1901# error "You cannot disable DES on systems without SIGALRM."
1902# endif /* OPENSSL_NO_DES */
1903#else
Rich Salza00ae6c2015-01-27 10:06:22 -05001904# ifndef _WIN32
1905 signal(SIGALRM, sig_done);
1906# endif
1907#endif /* SIGALRM */
1908
1909#ifndef OPENSSL_NO_MD2
Matt Caswell0f113f32015-01-22 03:40:55 +00001910 if (doit[D_MD2]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001911 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1912 print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001913 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001914 count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001915 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001916 print_result(D_MD2, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001917 }
1918 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001919#endif
1920#ifndef OPENSSL_NO_MDC2
Matt Caswell0f113f32015-01-22 03:40:55 +00001921 if (doit[D_MDC2]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001922 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1923 print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001924 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001925 count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001926 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001927 print_result(D_MDC2, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001928 }
1929 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001930#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001931
Rich Salza00ae6c2015-01-27 10:06:22 -05001932#ifndef OPENSSL_NO_MD4
Matt Caswell0f113f32015-01-22 03:40:55 +00001933 if (doit[D_MD4]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001934 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1935 print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001936 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001937 count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001938 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001939 print_result(D_MD4, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001940 }
1941 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001942#endif
Richard Levitte30094582000-08-14 14:05:53 +00001943
Rich Salza00ae6c2015-01-27 10:06:22 -05001944#ifndef OPENSSL_NO_MD5
Matt Caswell0f113f32015-01-22 03:40:55 +00001945 if (doit[D_MD5]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001946 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1947 print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001948 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001949 count = run_benchmark(async_jobs, MD5_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001950 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001951 print_result(D_MD5, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001952 }
1953 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001954#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00001955
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001956#ifndef OPENSSL_NO_MD5
Matt Caswell0f113f32015-01-22 03:40:55 +00001957 if (doit[D_HMAC]) {
Andrea Grandi0ff43432016-02-18 10:56:53 +00001958 for (i = 0; i < loopargs_len; i++) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001959 loopargs[i].hctx = HMAC_CTX_new();
1960 if (loopargs[i].hctx == NULL) {
1961 BIO_printf(bio_err, "HMAC malloc failure, exiting...");
1962 exit(1);
Matt Caswell0f113f32015-01-22 03:40:55 +00001963 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001964
1965 HMAC_Init_ex(loopargs[i].hctx, (unsigned char *)"This is a key...",
1966 16, EVP_md5(), NULL);
Matt Caswell0f113f32015-01-22 03:40:55 +00001967 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001968 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1969 print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]);
1970 Time_F(START);
1971 count = run_benchmark(async_jobs, HMAC_loop, loopargs);
1972 d = Time_F(STOP);
1973 print_result(D_HMAC, testnum, count, d);
1974 }
Andrea Grandi0ff43432016-02-18 10:56:53 +00001975 for (i = 0; i < loopargs_len; i++) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001976 HMAC_CTX_free(loopargs[i].hctx);
1977 }
Matt Caswell0f113f32015-01-22 03:40:55 +00001978 }
Rich Salza00ae6c2015-01-27 10:06:22 -05001979#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00001980 if (doit[D_SHA1]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001981 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1982 print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001983 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001984 count = run_benchmark(async_jobs, SHA1_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001985 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001986 print_result(D_SHA1, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001987 }
1988 }
Matt Caswell0f113f32015-01-22 03:40:55 +00001989 if (doit[D_SHA256]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001990 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
1991 print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00001992 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001993 count = run_benchmark(async_jobs, SHA256_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00001994 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001995 print_result(D_SHA256, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00001996 }
1997 }
Matt Caswell0f113f32015-01-22 03:40:55 +00001998 if (doit[D_SHA512]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00001999 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2000 print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002001 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002002 count = run_benchmark(async_jobs, SHA512_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002003 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002004 print_result(D_SHA512, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002005 }
2006 }
Andy Polyakov46ceb152004-05-20 21:49:38 +00002007
Rich Salza00ae6c2015-01-27 10:06:22 -05002008#ifndef OPENSSL_NO_WHIRLPOOL
Matt Caswell0f113f32015-01-22 03:40:55 +00002009 if (doit[D_WHIRLPOOL]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002010 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2011 print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002012 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002013 count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002014 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002015 print_result(D_WHIRLPOOL, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002016 }
2017 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002018#endif
Nils Larschae93dc132006-12-01 21:42:55 +00002019
Rich Salza00ae6c2015-01-27 10:06:22 -05002020#ifndef OPENSSL_NO_RMD160
Matt Caswell0f113f32015-01-22 03:40:55 +00002021 if (doit[D_RMD160]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002022 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2023 print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002024 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002025 count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002026 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002027 print_result(D_RMD160, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002028 }
2029 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002030#endif
2031#ifndef OPENSSL_NO_RC4
Matt Caswell0f113f32015-01-22 03:40:55 +00002032 if (doit[D_RC4]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002033 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2034 print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002035 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002036 count = run_benchmark(async_jobs, RC4_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002037 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002038 print_result(D_RC4, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002039 }
2040 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002041#endif
2042#ifndef OPENSSL_NO_DES
Matt Caswell0f113f32015-01-22 03:40:55 +00002043 if (doit[D_CBC_DES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002044 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2045 print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002046 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002047 count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002048 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002049 print_result(D_CBC_DES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002050 }
2051 }
Nils Larschae93dc132006-12-01 21:42:55 +00002052
Matt Caswell0f113f32015-01-22 03:40:55 +00002053 if (doit[D_EDE3_DES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002054 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2055 print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002056 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002057 count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002058 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002059 print_result(D_EDE3_DES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002060 }
2061 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002062#endif
Matt Caswell5158c762016-04-13 11:28:45 +01002063
Matt Caswell0f113f32015-01-22 03:40:55 +00002064 if (doit[D_CBC_128_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002065 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2066 print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
2067 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002068 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002069 count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002070 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002071 print_result(D_CBC_128_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002072 }
2073 }
2074 if (doit[D_CBC_192_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002075 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2076 print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
2077 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002078 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002079 count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002080 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002081 print_result(D_CBC_192_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002082 }
2083 }
2084 if (doit[D_CBC_256_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002085 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2086 print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
2087 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002088 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002089 count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002090 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002091 print_result(D_CBC_256_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002092 }
2093 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002094
Matt Caswell0f113f32015-01-22 03:40:55 +00002095 if (doit[D_IGE_128_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002096 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2097 print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
2098 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002099 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002100 count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002101 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002102 print_result(D_IGE_128_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002103 }
2104 }
2105 if (doit[D_IGE_192_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002106 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2107 print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
2108 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002109 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002110 count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002111 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002112 print_result(D_IGE_192_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002113 }
2114 }
2115 if (doit[D_IGE_256_AES]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002116 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2117 print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
2118 lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002119 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002120 count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002121 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002122 print_result(D_IGE_256_AES, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002123 }
2124 }
2125 if (doit[D_GHASH]) {
Andrea Grandi0ff43432016-02-18 10:56:53 +00002126 for (i = 0; i < loopargs_len; i++) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002127 loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
2128 CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12);
Matt Caswell0f113f32015-01-22 03:40:55 +00002129 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002130
2131 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2132 print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]);
2133 Time_F(START);
2134 count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
2135 d = Time_F(STOP);
2136 print_result(D_GHASH, testnum, count, d);
2137 }
Andrea Grandi0ff43432016-02-18 10:56:53 +00002138 for (i = 0; i < loopargs_len; i++)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002139 CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
Matt Caswell0f113f32015-01-22 03:40:55 +00002140 }
Matt Caswell5158c762016-04-13 11:28:45 +01002141
Rich Salza00ae6c2015-01-27 10:06:22 -05002142#ifndef OPENSSL_NO_CAMELLIA
Matt Caswell0f113f32015-01-22 03:40:55 +00002143 if (doit[D_CBC_128_CML]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002144 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2145 print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
2146 lengths[testnum]);
2147 if (async_jobs > 0) {
2148 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2149 exit(1);
2150 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002151 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002152 for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++)
2153 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2154 (unsigned long)lengths[testnum], &camellia_ks1,
Matt Caswell0f113f32015-01-22 03:40:55 +00002155 iv, CAMELLIA_ENCRYPT);
2156 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002157 print_result(D_CBC_128_CML, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002158 }
2159 }
2160 if (doit[D_CBC_192_CML]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002161 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2162 print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
2163 lengths[testnum]);
2164 if (async_jobs > 0) {
2165 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2166 exit(1);
2167 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002168 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002169 for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++)
2170 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2171 (unsigned long)lengths[testnum], &camellia_ks2,
Matt Caswell0f113f32015-01-22 03:40:55 +00002172 iv, CAMELLIA_ENCRYPT);
2173 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002174 print_result(D_CBC_192_CML, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002175 }
2176 }
2177 if (doit[D_CBC_256_CML]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002178 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2179 print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
2180 lengths[testnum]);
2181 if (async_jobs > 0) {
2182 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2183 exit(1);
2184 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002185 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002186 for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++)
2187 Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2188 (unsigned long)lengths[testnum], &camellia_ks3,
Matt Caswell0f113f32015-01-22 03:40:55 +00002189 iv, CAMELLIA_ENCRYPT);
2190 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002191 print_result(D_CBC_256_CML, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002192 }
2193 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002194#endif
2195#ifndef OPENSSL_NO_IDEA
Matt Caswell0f113f32015-01-22 03:40:55 +00002196 if (doit[D_CBC_IDEA]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002197 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2198 print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]);
2199 if (async_jobs > 0) {
2200 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2201 exit(1);
2202 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002203 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002204 for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++)
2205 idea_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2206 (unsigned long)lengths[testnum], &idea_ks,
Matt Caswell0f113f32015-01-22 03:40:55 +00002207 iv, IDEA_ENCRYPT);
2208 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002209 print_result(D_CBC_IDEA, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002210 }
2211 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002212#endif
2213#ifndef OPENSSL_NO_SEED
Matt Caswell0f113f32015-01-22 03:40:55 +00002214 if (doit[D_CBC_SEED]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002215 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2216 print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]);
2217 if (async_jobs > 0) {
2218 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2219 exit(1);
2220 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002221 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002222 for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++)
2223 SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2224 (unsigned long)lengths[testnum], &seed_ks, iv, 1);
Matt Caswell0f113f32015-01-22 03:40:55 +00002225 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002226 print_result(D_CBC_SEED, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002227 }
2228 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002229#endif
2230#ifndef OPENSSL_NO_RC2
Matt Caswell0f113f32015-01-22 03:40:55 +00002231 if (doit[D_CBC_RC2]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002232 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2233 print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]);
2234 if (async_jobs > 0) {
2235 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2236 exit(1);
2237 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002238 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002239 for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++)
2240 RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2241 (unsigned long)lengths[testnum], &rc2_ks,
Matt Caswell0f113f32015-01-22 03:40:55 +00002242 iv, RC2_ENCRYPT);
2243 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002244 print_result(D_CBC_RC2, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002245 }
2246 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002247#endif
2248#ifndef OPENSSL_NO_RC5
Matt Caswell0f113f32015-01-22 03:40:55 +00002249 if (doit[D_CBC_RC5]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002250 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2251 print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]);
2252 if (async_jobs > 0) {
2253 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2254 exit(1);
2255 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002256 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002257 for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++)
2258 RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2259 (unsigned long)lengths[testnum], &rc5_ks,
Matt Caswell0f113f32015-01-22 03:40:55 +00002260 iv, RC5_ENCRYPT);
2261 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002262 print_result(D_CBC_RC5, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002263 }
2264 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002265#endif
2266#ifndef OPENSSL_NO_BF
Matt Caswell0f113f32015-01-22 03:40:55 +00002267 if (doit[D_CBC_BF]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002268 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2269 print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]);
2270 if (async_jobs > 0) {
2271 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2272 exit(1);
2273 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002274 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002275 for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++)
2276 BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2277 (unsigned long)lengths[testnum], &bf_ks,
Matt Caswell0f113f32015-01-22 03:40:55 +00002278 iv, BF_ENCRYPT);
2279 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002280 print_result(D_CBC_BF, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002281 }
2282 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002283#endif
2284#ifndef OPENSSL_NO_CAST
Matt Caswell0f113f32015-01-22 03:40:55 +00002285 if (doit[D_CBC_CAST]) {
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002286 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2287 print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]);
2288 if (async_jobs > 0) {
2289 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2290 exit(1);
2291 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002292 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002293 for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++)
2294 CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
2295 (unsigned long)lengths[testnum], &cast_ks,
Matt Caswell0f113f32015-01-22 03:40:55 +00002296 iv, CAST_ENCRYPT);
2297 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002298 print_result(D_CBC_CAST, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002299 }
2300 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002301#endif
Ben Laurie5f09d0e2007-05-13 12:57:59 +00002302
Matt Caswell0f113f32015-01-22 03:40:55 +00002303 if (doit[D_EVP]) {
Rich Salza00ae6c2015-01-27 10:06:22 -05002304#ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
Matt Caswell0f113f32015-01-22 03:40:55 +00002305 if (multiblock && evp_cipher) {
2306 if (!
2307 (EVP_CIPHER_flags(evp_cipher) &
2308 EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
Rich Salz7768e112015-06-04 14:26:55 -04002309 BIO_printf(bio_err, "%s is not multi-block capable\n",
Richard Levitte6c2ff562015-12-18 17:08:49 +01002310 OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
Matt Caswell0f113f32015-01-22 03:40:55 +00002311 goto end;
2312 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002313 if (async_jobs > 0) {
2314 BIO_printf(bio_err, "Async mode is not supported, exiting...");
2315 exit(1);
2316 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002317 multiblock_speed(evp_cipher);
Rich Salz7e1b7482015-04-24 15:26:15 -04002318 ret = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002319 goto end;
2320 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002321#endif
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002322 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002323 if (evp_cipher) {
Ben Laurie5f09d0e2007-05-13 12:57:59 +00002324
Richard Levitte6c2ff562015-12-18 17:08:49 +01002325 names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
Matt Caswell0f113f32015-01-22 03:40:55 +00002326 /*
2327 * -O3 -fschedule-insns messes up an optimization here!
2328 * names[D_EVP] somehow becomes NULL
2329 */
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002330 print_message(names[D_EVP], save_count, lengths[testnum]);
Bodo Möllerf3dea9a2006-06-09 15:44:59 +00002331
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002332 for (k = 0; k < loopargs_len; k++) {
2333 loopargs[k].ctx = EVP_CIPHER_CTX_new();
2334 if (decrypt)
2335 EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2336 else
2337 EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv);
2338 EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
2339 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002340
Matt Caswell0f113f32015-01-22 03:40:55 +00002341 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002342 count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002343 d = Time_F(STOP);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002344 for (k = 0; k < loopargs_len; k++) {
2345 EVP_CIPHER_CTX_free(loopargs[k].ctx);
2346 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002347 }
2348 if (evp_md) {
Richard Levittecc9d6652015-11-29 20:12:35 +01002349 names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002350 print_message(names[D_EVP], save_count, lengths[testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002351 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002352 count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002353 d = Time_F(STOP);
2354 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002355 print_result(D_EVP, testnum, count, d);
Matt Caswell0f113f32015-01-22 03:40:55 +00002356 }
2357 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002358
Andrea Grandi0ff43432016-02-18 10:56:53 +00002359 for (i = 0; i < loopargs_len; i++)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002360 RAND_bytes(loopargs[i].buf, 36);
2361
Rich Salza00ae6c2015-01-27 10:06:22 -05002362#ifndef OPENSSL_NO_RSA
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002363 for (testnum = 0; testnum < RSA_NUM; testnum++) {
2364 int st = 0;
2365 if (!rsa_doit[testnum])
Matt Caswell0f113f32015-01-22 03:40:55 +00002366 continue;
Andrea Grandi0ff43432016-02-18 10:56:53 +00002367 for (i = 0; i < loopargs_len; i++) {
2368 st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2369 loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002370 if (st == 0)
2371 break;
2372 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002373 if (st == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002374 BIO_printf(bio_err,
2375 "RSA sign failure. No RSA sign will be done.\n");
2376 ERR_print_errors(bio_err);
2377 rsa_count = 1;
2378 } else {
2379 pkey_print_message("private", "rsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002380 rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS);
2381 /* RSA_blinding_on(rsa_key[testnum],NULL); */
Matt Caswell0f113f32015-01-22 03:40:55 +00002382 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002383 count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002384 d = Time_F(STOP);
2385 BIO_printf(bio_err,
2386 mr ? "+R1:%ld:%d:%.2f\n"
2387 : "%ld %d bit private RSA's in %.2fs\n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002388 count, rsa_bits[testnum], d);
2389 rsa_results[testnum][0] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002390 rsa_count = count;
2391 }
Richard Levitte83c40e72001-11-15 20:19:40 +00002392
Andrea Grandi0ff43432016-02-18 10:56:53 +00002393 for (i = 0; i < loopargs_len; i++) {
2394 st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
2395 *(loopargs[i].siglen), loopargs[i].rsa_key[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002396 if (st <= 0)
2397 break;
2398 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002399 if (st <= 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002400 BIO_printf(bio_err,
2401 "RSA verify failure. No RSA verify will be done.\n");
2402 ERR_print_errors(bio_err);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002403 rsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002404 } else {
2405 pkey_print_message("public", "rsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002406 rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS);
Matt Caswell0f113f32015-01-22 03:40:55 +00002407 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002408 count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002409 d = Time_F(STOP);
2410 BIO_printf(bio_err,
2411 mr ? "+R2:%ld:%d:%.2f\n"
2412 : "%ld %d bit public RSA's in %.2fs\n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002413 count, rsa_bits[testnum], d);
2414 rsa_results[testnum][1] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002415 }
Richard Levitte83c40e72001-11-15 20:19:40 +00002416
Matt Caswell0f113f32015-01-22 03:40:55 +00002417 if (rsa_count <= 1) {
2418 /* if longer than 10s, don't do any more */
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002419 for (testnum++; testnum < RSA_NUM; testnum++)
2420 rsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002421 }
2422 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002423#endif
Richard Levitte83c40e72001-11-15 20:19:40 +00002424
Andrea Grandi0ff43432016-02-18 10:56:53 +00002425 for (i = 0; i < loopargs_len; i++)
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002426 RAND_bytes(loopargs[i].buf, 36);
2427
Rich Salza00ae6c2015-01-27 10:06:22 -05002428#ifndef OPENSSL_NO_DSA
Matt Caswell0f113f32015-01-22 03:40:55 +00002429 if (RAND_status() != 1) {
2430 RAND_seed(rnd_seed, sizeof rnd_seed);
Matt Caswell0f113f32015-01-22 03:40:55 +00002431 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002432 for (testnum = 0; testnum < DSA_NUM; testnum++) {
2433 int st = 0;
2434 if (!dsa_doit[testnum])
Matt Caswell0f113f32015-01-22 03:40:55 +00002435 continue;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002436
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002437 /* DSA_generate_key(dsa_key[testnum]); */
2438 /* DSA_sign_setup(dsa_key[testnum],NULL); */
Andrea Grandi0ff43432016-02-18 10:56:53 +00002439 for (i = 0; i < loopargs_len; i++) {
2440 st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2441 loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002442 if (st == 0)
2443 break;
2444 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002445 if (st == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002446 BIO_printf(bio_err,
2447 "DSA sign failure. No DSA sign will be done.\n");
2448 ERR_print_errors(bio_err);
2449 rsa_count = 1;
2450 } else {
2451 pkey_print_message("sign", "dsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002452 dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS);
Matt Caswell0f113f32015-01-22 03:40:55 +00002453 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002454 count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002455 d = Time_F(STOP);
2456 BIO_printf(bio_err,
2457 mr ? "+R3:%ld:%d:%.2f\n"
2458 : "%ld %d bit DSA signs in %.2fs\n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002459 count, dsa_bits[testnum], d);
2460 dsa_results[testnum][0] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002461 rsa_count = count;
2462 }
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002463
Andrea Grandi0ff43432016-02-18 10:56:53 +00002464 for (i = 0; i < loopargs_len; i++) {
2465 st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2466 *(loopargs[i].siglen), loopargs[i].dsa_key[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002467 if (st <= 0)
2468 break;
2469 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002470 if (st <= 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002471 BIO_printf(bio_err,
2472 "DSA verify failure. No DSA verify will be done.\n");
2473 ERR_print_errors(bio_err);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002474 dsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002475 } else {
2476 pkey_print_message("verify", "dsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002477 dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS);
Matt Caswell0f113f32015-01-22 03:40:55 +00002478 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002479 count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002480 d = Time_F(STOP);
2481 BIO_printf(bio_err,
2482 mr ? "+R4:%ld:%d:%.2f\n"
2483 : "%ld %d bit DSA verify in %.2fs\n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002484 count, dsa_bits[testnum], d);
2485 dsa_results[testnum][1] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002486 }
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00002487
Matt Caswell0f113f32015-01-22 03:40:55 +00002488 if (rsa_count <= 1) {
2489 /* if longer than 10s, don't do any more */
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002490 for (testnum++; testnum < DSA_NUM; testnum++)
2491 dsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002492 }
2493 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002494#endif
Andy Polyakove751bba2015-01-20 14:15:44 +01002495
Rich Salz10bf4fc2015-03-10 19:09:27 -04002496#ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00002497 if (RAND_status() != 1) {
2498 RAND_seed(rnd_seed, sizeof rnd_seed);
Matt Caswell0f113f32015-01-22 03:40:55 +00002499 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002500 for (testnum = 0; testnum < EC_NUM; testnum++) {
Andrea Grandi0ff43432016-02-18 10:56:53 +00002501 int st = 1;
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002502
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002503 if (!ecdsa_doit[testnum])
Matt Caswell0f113f32015-01-22 03:40:55 +00002504 continue; /* Ignore Curve */
Andrea Grandi0ff43432016-02-18 10:56:53 +00002505 for (i = 0; i < loopargs_len; i++) {
2506 loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2507 if (loopargs[i].ecdsa[testnum] == NULL) {
2508 st = 0;
2509 break;
2510 }
2511 }
2512 if (st == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002513 BIO_printf(bio_err, "ECDSA failure.\n");
2514 ERR_print_errors(bio_err);
2515 rsa_count = 1;
2516 } else {
Andrea Grandi0ff43432016-02-18 10:56:53 +00002517 for (i = 0; i < loopargs_len; i++) {
2518 EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
2519 /* Perform ECDSA signature test */
2520 EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
2521 st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
2522 loopargs[i].siglen, loopargs[i].ecdsa[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002523 if (st == 0)
2524 break;
2525 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002526 if (st == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002527 BIO_printf(bio_err,
2528 "ECDSA sign failure. No ECDSA sign will be done.\n");
2529 ERR_print_errors(bio_err);
2530 rsa_count = 1;
2531 } else {
2532 pkey_print_message("sign", "ecdsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002533 ecdsa_c[testnum][0],
2534 test_curves_bits[testnum], ECDSA_SECONDS);
Matt Caswell0f113f32015-01-22 03:40:55 +00002535 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002536 count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002537 d = Time_F(STOP);
Bodo Möllere172d602002-08-09 08:43:04 +00002538
Matt Caswell0f113f32015-01-22 03:40:55 +00002539 BIO_printf(bio_err,
2540 mr ? "+R5:%ld:%d:%.2f\n" :
2541 "%ld %d bit ECDSA signs in %.2fs \n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002542 count, test_curves_bits[testnum], d);
2543 ecdsa_results[testnum][0] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002544 rsa_count = count;
2545 }
Bodo Möllere172d602002-08-09 08:43:04 +00002546
Matt Caswell0f113f32015-01-22 03:40:55 +00002547 /* Perform ECDSA verification test */
Andrea Grandi0ff43432016-02-18 10:56:53 +00002548 for (i = 0; i < loopargs_len; i++) {
2549 st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
2550 *(loopargs[i].siglen), loopargs[i].ecdsa[testnum]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002551 if (st != 1)
2552 break;
2553 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002554 if (st != 1) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002555 BIO_printf(bio_err,
2556 "ECDSA verify failure. No ECDSA verify will be done.\n");
2557 ERR_print_errors(bio_err);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002558 ecdsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002559 } else {
2560 pkey_print_message("verify", "ecdsa",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002561 ecdsa_c[testnum][1],
2562 test_curves_bits[testnum], ECDSA_SECONDS);
Matt Caswell0f113f32015-01-22 03:40:55 +00002563 Time_F(START);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002564 count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
Matt Caswell0f113f32015-01-22 03:40:55 +00002565 d = Time_F(STOP);
2566 BIO_printf(bio_err,
2567 mr ? "+R6:%ld:%d:%.2f\n"
2568 : "%ld %d bit ECDSA verify in %.2fs\n",
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002569 count, test_curves_bits[testnum], d);
2570 ecdsa_results[testnum][1] = d / (double)count;
Matt Caswell0f113f32015-01-22 03:40:55 +00002571 }
Bodo Möllere172d602002-08-09 08:43:04 +00002572
Matt Caswell0f113f32015-01-22 03:40:55 +00002573 if (rsa_count <= 1) {
2574 /* if longer than 10s, don't do any more */
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002575 for (testnum++; testnum < EC_NUM; testnum++)
2576 ecdsa_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002577 }
2578 }
2579 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002580#endif
2581
2582#ifndef OPENSSL_NO_EC
Matt Caswell0f113f32015-01-22 03:40:55 +00002583 if (RAND_status() != 1) {
2584 RAND_seed(rnd_seed, sizeof rnd_seed);
Matt Caswell0f113f32015-01-22 03:40:55 +00002585 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002586 for (testnum = 0; testnum < EC_NUM; testnum++) {
2587 if (!ecdh_doit[testnum])
Matt Caswell0f113f32015-01-22 03:40:55 +00002588 continue;
Andrea Grandi0ff43432016-02-18 10:56:53 +00002589 for (i = 0; i < loopargs_len; i++) {
2590 loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2591 loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]);
2592 if (loopargs[i].ecdh_a[testnum] == NULL ||
2593 loopargs[i].ecdh_b[testnum] == NULL) {
2594 ecdh_checks = 0;
2595 break;
2596 }
2597 }
2598 if (ecdh_checks == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002599 BIO_printf(bio_err, "ECDH failure.\n");
2600 ERR_print_errors(bio_err);
2601 rsa_count = 1;
2602 } else {
Andrea Grandi0ff43432016-02-18 10:56:53 +00002603 for (i = 0; i < loopargs_len; i++) {
2604 /* generate two ECDH key pairs */
2605 if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) ||
2606 !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) {
2607 BIO_printf(bio_err, "ECDH key generation failure.\n");
Matt Caswell0f113f32015-01-22 03:40:55 +00002608 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00002609 ecdh_checks = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002610 rsa_count = 1;
Andrea Grandi0ff43432016-02-18 10:56:53 +00002611 } else {
2612 /*
2613 * If field size is not more than 24 octets, then use SHA-1
2614 * hash of result; otherwise, use result (see section 4.8 of
2615 * draft-ietf-tls-ecc-03.txt).
2616 */
2617 int field_size;
2618 field_size =
2619 EC_GROUP_get_degree(EC_KEY_get0_group(loopargs[i].ecdh_a[testnum]));
2620 if (field_size <= 24 * 8) {
2621 outlen = KDF1_SHA1_len;
2622 kdf = KDF1_SHA1;
2623 } else {
2624 outlen = (field_size + 7) / 8;
2625 kdf = NULL;
2626 }
2627 secret_size_a =
2628 ECDH_compute_key(loopargs[i].secret_a, outlen,
2629 EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]),
2630 loopargs[i].ecdh_a[testnum], kdf);
2631 secret_size_b =
2632 ECDH_compute_key(loopargs[i].secret_b, outlen,
2633 EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]),
2634 loopargs[i].ecdh_b[testnum], kdf);
2635 if (secret_size_a != secret_size_b)
2636 ecdh_checks = 0;
2637 else
2638 ecdh_checks = 1;
Bodo Möllere172d602002-08-09 08:43:04 +00002639
Andrea Grandi0ff43432016-02-18 10:56:53 +00002640 for (secret_idx = 0; (secret_idx < secret_size_a)
2641 && (ecdh_checks == 1); secret_idx++) {
2642 if (loopargs[i].secret_a[secret_idx] != loopargs[i].secret_b[secret_idx])
2643 ecdh_checks = 0;
2644 }
2645
2646 if (ecdh_checks == 0) {
2647 BIO_printf(bio_err, "ECDH computations don't match.\n");
2648 ERR_print_errors(bio_err);
2649 rsa_count = 1;
2650 break;
2651 }
2652 }
2653 if (ecdh_checks != 0) {
2654 pkey_print_message("", "ecdh",
2655 ecdh_c[testnum][0],
2656 test_curves_bits[testnum], ECDH_SECONDS);
2657 Time_F(START);
2658 count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs);
2659 d = Time_F(STOP);
2660 BIO_printf(bio_err,
2661 mr ? "+R7:%ld:%d:%.2f\n" :
2662 "%ld %d-bit ECDH ops in %.2fs\n", count,
2663 test_curves_bits[testnum], d);
2664 ecdh_results[testnum][0] = d / (double)count;
2665 rsa_count = count;
2666 }
Matt Caswell0f113f32015-01-22 03:40:55 +00002667 }
2668 }
Nils Larsch9dd84052005-05-16 10:11:04 +00002669
Matt Caswell0f113f32015-01-22 03:40:55 +00002670 if (rsa_count <= 1) {
2671 /* if longer than 10s, don't do any more */
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002672 for (testnum++; testnum < EC_NUM; testnum++)
2673 ecdh_doit[testnum] = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002674 }
2675 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002676#endif
2677#ifndef NO_FORK
Matt Caswell0f113f32015-01-22 03:40:55 +00002678 show_res:
Rich Salza00ae6c2015-01-27 10:06:22 -05002679#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00002680 if (!mr) {
Rich Salzb0700d22015-10-27 15:11:48 -04002681 printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
2682 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
Matt Caswell0f113f32015-01-22 03:40:55 +00002683 printf("options:");
2684 printf("%s ", BN_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002685#ifndef OPENSSL_NO_MD2
Matt Caswell0f113f32015-01-22 03:40:55 +00002686 printf("%s ", MD2_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002687#endif
2688#ifndef OPENSSL_NO_RC4
Matt Caswell0f113f32015-01-22 03:40:55 +00002689 printf("%s ", RC4_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002690#endif
2691#ifndef OPENSSL_NO_DES
Matt Caswell0f113f32015-01-22 03:40:55 +00002692 printf("%s ", DES_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002693#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00002694 printf("%s ", AES_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002695#ifndef OPENSSL_NO_IDEA
Matt Caswell0f113f32015-01-22 03:40:55 +00002696 printf("%s ", idea_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002697#endif
2698#ifndef OPENSSL_NO_BF
Matt Caswell0f113f32015-01-22 03:40:55 +00002699 printf("%s ", BF_options());
Rich Salza00ae6c2015-01-27 10:06:22 -05002700#endif
Rich Salzb0700d22015-10-27 15:11:48 -04002701 printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
Matt Caswell0f113f32015-01-22 03:40:55 +00002702 }
Nils Larsch9dd84052005-05-16 10:11:04 +00002703
Matt Caswell0f113f32015-01-22 03:40:55 +00002704 if (pr_header) {
2705 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002706 printf("+H");
Matt Caswell0f113f32015-01-22 03:40:55 +00002707 else {
Rich Salz7e1b7482015-04-24 15:26:15 -04002708 printf
2709 ("The 'numbers' are in 1000s of bytes per second processed.\n");
2710 printf("type ");
Matt Caswell0f113f32015-01-22 03:40:55 +00002711 }
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002712 for (testnum = 0; testnum < SIZE_NUM; testnum++)
2713 printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
Rich Salz7e1b7482015-04-24 15:26:15 -04002714 printf("\n");
Matt Caswell0f113f32015-01-22 03:40:55 +00002715 }
Nils Larsch9dd84052005-05-16 10:11:04 +00002716
Matt Caswell0f113f32015-01-22 03:40:55 +00002717 for (k = 0; k < ALGOR_NUM; k++) {
2718 if (!doit[k])
2719 continue;
2720 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002721 printf("+F:%d:%s", k, names[k]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002722 else
Rich Salz7e1b7482015-04-24 15:26:15 -04002723 printf("%-13s", names[k]);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002724 for (testnum = 0; testnum < SIZE_NUM; testnum++) {
2725 if (results[k][testnum] > 10000 && !mr)
2726 printf(" %11.2fk", results[k][testnum] / 1e3);
Matt Caswell0f113f32015-01-22 03:40:55 +00002727 else
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002728 printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002729 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002730 printf("\n");
Matt Caswell0f113f32015-01-22 03:40:55 +00002731 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002732#ifndef OPENSSL_NO_RSA
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002733 testnum = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00002734 for (k = 0; k < RSA_NUM; k++) {
2735 if (!rsa_doit[k])
2736 continue;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002737 if (testnum && !mr) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002738 printf("%18ssign verify sign/s verify/s\n", " ");
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002739 testnum = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002740 }
2741 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002742 printf("+F2:%u:%u:%f:%f\n",
2743 k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002744 else
Rich Salz7e1b7482015-04-24 15:26:15 -04002745 printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2746 rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
2747 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002748 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002749#endif
2750#ifndef OPENSSL_NO_DSA
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002751 testnum = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00002752 for (k = 0; k < DSA_NUM; k++) {
2753 if (!dsa_doit[k])
2754 continue;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002755 if (testnum && !mr) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002756 printf("%18ssign verify sign/s verify/s\n", " ");
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002757 testnum = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002758 }
2759 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002760 printf("+F3:%u:%u:%f:%f\n",
2761 k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002762 else
Rich Salz7e1b7482015-04-24 15:26:15 -04002763 printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2764 dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
2765 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002766 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002767#endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04002768#ifndef OPENSSL_NO_EC
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002769 testnum = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00002770 for (k = 0; k < EC_NUM; k++) {
2771 if (!ecdsa_doit[k])
2772 continue;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002773 if (testnum && !mr) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002774 printf("%30ssign verify sign/s verify/s\n", " ");
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002775 testnum = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002776 }
Bodo Möllere172d602002-08-09 08:43:04 +00002777
Matt Caswell0f113f32015-01-22 03:40:55 +00002778 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002779 printf("+F4:%u:%u:%f:%f\n",
2780 k, test_curves_bits[k],
2781 ecdsa_results[k][0], ecdsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002782 else
Rich Salz7e1b7482015-04-24 15:26:15 -04002783 printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2784 test_curves_bits[k],
2785 test_curves_names[k],
2786 ecdsa_results[k][0], ecdsa_results[k][1],
2787 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002788 }
Rich Salz7e1b7482015-04-24 15:26:15 -04002789#endif
2790
2791#ifndef OPENSSL_NO_EC
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002792 testnum = 1;
Matt Caswell0f113f32015-01-22 03:40:55 +00002793 for (k = 0; k < EC_NUM; k++) {
2794 if (!ecdh_doit[k])
2795 continue;
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002796 if (testnum && !mr) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002797 printf("%30sop op/s\n", " ");
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002798 testnum = 0;
Matt Caswell0f113f32015-01-22 03:40:55 +00002799 }
2800 if (mr)
Rich Salz7e1b7482015-04-24 15:26:15 -04002801 printf("+F5:%u:%u:%f:%f\n",
2802 k, test_curves_bits[k],
2803 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002804
Matt Caswell0f113f32015-01-22 03:40:55 +00002805 else
Rich Salz7e1b7482015-04-24 15:26:15 -04002806 printf("%4u bit ecdh (%s) %8.4fs %8.1f\n",
2807 test_curves_bits[k],
2808 test_curves_names[k],
2809 ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
Matt Caswell0f113f32015-01-22 03:40:55 +00002810 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002811#endif
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002812
Rich Salz7e1b7482015-04-24 15:26:15 -04002813 ret = 0;
Bodo Möllere172d602002-08-09 08:43:04 +00002814
Matt Caswell0f113f32015-01-22 03:40:55 +00002815 end:
2816 ERR_print_errors(bio_err);
Andrea Grandi0ff43432016-02-18 10:56:53 +00002817 for (i = 0; i < loopargs_len; i++) {
Andrea Grandib2839682016-02-27 06:14:49 +00002818 OPENSSL_free(loopargs[i].buf_malloc);
2819 OPENSSL_free(loopargs[i].buf2_malloc);
2820 OPENSSL_free(loopargs[i].siglen);
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002821 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002822#ifndef OPENSSL_NO_RSA
Andrea Grandi0ff43432016-02-18 10:56:53 +00002823 for (i = 0; i < loopargs_len; i++) {
2824 for (k = 0; k < RSA_NUM; k++)
2825 RSA_free(loopargs[i].rsa_key[k]);
2826 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002827#endif
2828#ifndef OPENSSL_NO_DSA
Andrea Grandi0ff43432016-02-18 10:56:53 +00002829 for (i = 0; i < loopargs_len; i++) {
2830 for (k = 0; k < DSA_NUM; k++)
2831 DSA_free(loopargs[i].dsa_key[k]);
2832 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002833#endif
Bodo Möllere172d602002-08-09 08:43:04 +00002834
Rich Salz10bf4fc2015-03-10 19:09:27 -04002835#ifndef OPENSSL_NO_EC
Andrea Grandi0ff43432016-02-18 10:56:53 +00002836 for (i = 0; i < loopargs_len; i++) {
2837 for (k = 0; k < EC_NUM; k++) {
2838 EC_KEY_free(loopargs[i].ecdsa[k]);
2839 EC_KEY_free(loopargs[i].ecdh_a[k]);
2840 EC_KEY_free(loopargs[i].ecdh_b[k]);
2841 }
Andrea Grandib2839682016-02-27 06:14:49 +00002842 OPENSSL_free(loopargs[i].secret_a);
2843 OPENSSL_free(loopargs[i].secret_b);
Matt Caswell0f113f32015-01-22 03:40:55 +00002844 }
Rich Salza00ae6c2015-01-27 10:06:22 -05002845#endif
Andrea Grandi1e613922016-02-29 11:28:55 +00002846 if (async_jobs > 0) {
2847 for (i = 0; i < loopargs_len; i++)
2848 ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx);
2849
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00002850 ASYNC_cleanup_thread();
Andrea Grandi1e613922016-02-29 11:28:55 +00002851 }
2852 OPENSSL_free(loopargs);
Rich Salz7e1b7482015-04-24 15:26:15 -04002853 return (ret);
Matt Caswell0f113f32015-01-22 03:40:55 +00002854}
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002855
Ben Laurie646d5692000-11-20 04:14:19 +00002856static void print_message(const char *s, long num, int length)
Matt Caswell0f113f32015-01-22 03:40:55 +00002857{
Rich Salza00ae6c2015-01-27 10:06:22 -05002858#ifdef SIGALRM
Matt Caswell0f113f32015-01-22 03:40:55 +00002859 BIO_printf(bio_err,
2860 mr ? "+DT:%s:%d:%d\n"
2861 : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
2862 (void)BIO_flush(bio_err);
2863 alarm(SECONDS);
Rich Salza00ae6c2015-01-27 10:06:22 -05002864#else
Matt Caswell0f113f32015-01-22 03:40:55 +00002865 BIO_printf(bio_err,
2866 mr ? "+DN:%s:%ld:%d\n"
2867 : "Doing %s %ld times on %d size blocks: ", s, num, length);
2868 (void)BIO_flush(bio_err);
Rich Salza00ae6c2015-01-27 10:06:22 -05002869#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00002870}
Ralf S. Engelschalld02b48c1998-12-21 10:52:47 +00002871
Nils Larsch689c6f22005-03-20 23:12:13 +00002872static void pkey_print_message(const char *str, const char *str2, long num,
Matt Caswell0f113f32015-01-22 03:40:55 +00002873 int bits, int tm)
2874{
Rich Salza00ae6c2015-01-27 10:06:22 -05002875#ifdef SIGALRM
Matt Caswell0f113f32015-01-22 03:40:55 +00002876 BIO_printf(bio_err,
2877 mr ? "+DTP:%d:%s:%s:%d\n"
2878 : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
2879 (void)BIO_flush(bio_err);
2880 alarm(tm);
Rich Salza00ae6c2015-01-27 10:06:22 -05002881#else
Matt Caswell0f113f32015-01-22 03:40:55 +00002882 BIO_printf(bio_err,
2883 mr ? "+DNP:%ld:%d:%s:%s\n"
2884 : "Doing %ld %d bit %s %s's: ", num, bits, str, str2);
2885 (void)BIO_flush(bio_err);
Rich Salza00ae6c2015-01-27 10:06:22 -05002886#endif
Matt Caswell0f113f32015-01-22 03:40:55 +00002887}
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00002888
Matt Caswell0f113f32015-01-22 03:40:55 +00002889static void print_result(int alg, int run_no, int count, double time_used)
2890{
2891 BIO_printf(bio_err,
2892 mr ? "+R:%d:%s:%f\n"
2893 : "%d %s's in %.2fs\n", count, names[alg], time_used);
2894 results[alg][run_no] = ((double)count) / time_used * lengths[run_no];
2895}
Ben Laurie0e211562001-10-25 14:27:17 +00002896
Rich Salza00ae6c2015-01-27 10:06:22 -05002897#ifndef NO_FORK
Ben Laurie0e211562001-10-25 14:27:17 +00002898static char *sstrsep(char **string, const char *delim)
Matt Caswell0f113f32015-01-22 03:40:55 +00002899{
Ben Laurie0e211562001-10-25 14:27:17 +00002900 char isdelim[256];
2901 char *token = *string;
2902
2903 if (**string == 0)
2904 return NULL;
2905
Ben Laurie54a656e2002-11-13 15:43:43 +00002906 memset(isdelim, 0, sizeof isdelim);
Ben Laurie0e211562001-10-25 14:27:17 +00002907 isdelim[0] = 1;
2908
Matt Caswell0f113f32015-01-22 03:40:55 +00002909 while (*delim) {
Ben Laurie0e211562001-10-25 14:27:17 +00002910 isdelim[(unsigned char)(*delim)] = 1;
2911 delim++;
Ben Laurie0e211562001-10-25 14:27:17 +00002912 }
2913
Matt Caswell0f113f32015-01-22 03:40:55 +00002914 while (!isdelim[(unsigned char)(**string)]) {
2915 (*string)++;
2916 }
2917
2918 if (**string) {
2919 **string = 0;
2920 (*string)++;
2921 }
2922
2923 return token;
2924}
2925
Ben Laurie0e211562001-10-25 14:27:17 +00002926static int do_multi(int multi)
Matt Caswell0f113f32015-01-22 03:40:55 +00002927{
2928 int n;
2929 int fd[2];
2930 int *fds;
2931 static char sep[] = ":";
Ben Laurie0e211562001-10-25 14:27:17 +00002932
Rich Salzb4faea52015-05-01 23:10:31 -04002933 fds = malloc(sizeof(*fds) * multi);
Matt Caswell0f113f32015-01-22 03:40:55 +00002934 for (n = 0; n < multi; ++n) {
2935 if (pipe(fd) == -1) {
Rich Salz7768e112015-06-04 14:26:55 -04002936 BIO_printf(bio_err, "pipe failure\n");
Matt Caswell0f113f32015-01-22 03:40:55 +00002937 exit(1);
2938 }
2939 fflush(stdout);
Rich Salz7768e112015-06-04 14:26:55 -04002940 (void)BIO_flush(bio_err);
Matt Caswell0f113f32015-01-22 03:40:55 +00002941 if (fork()) {
2942 close(fd[1]);
2943 fds[n] = fd[0];
2944 } else {
2945 close(fd[0]);
2946 close(1);
2947 if (dup(fd[1]) == -1) {
Rich Salz7768e112015-06-04 14:26:55 -04002948 BIO_printf(bio_err, "dup failed\n");
Matt Caswell0f113f32015-01-22 03:40:55 +00002949 exit(1);
2950 }
2951 close(fd[1]);
2952 mr = 1;
2953 usertime = 0;
2954 free(fds);
2955 return 0;
2956 }
2957 printf("Forked child %d\n", n);
2958 }
Ben Laurie0e211562001-10-25 14:27:17 +00002959
Matt Caswell0f113f32015-01-22 03:40:55 +00002960 /* for now, assume the pipe is long enough to take all the output */
2961 for (n = 0; n < multi; ++n) {
2962 FILE *f;
2963 char buf[1024];
2964 char *p;
Ben Laurie0e211562001-10-25 14:27:17 +00002965
Matt Caswell0f113f32015-01-22 03:40:55 +00002966 f = fdopen(fds[n], "r");
2967 while (fgets(buf, sizeof buf, f)) {
2968 p = strchr(buf, '\n');
2969 if (p)
2970 *p = '\0';
2971 if (buf[0] != '+') {
Rich Salz7768e112015-06-04 14:26:55 -04002972 BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
Matt Caswell0f113f32015-01-22 03:40:55 +00002973 buf, n);
2974 continue;
2975 }
2976 printf("Got: %s from %d\n", buf, n);
Rich Salz86885c22015-05-06 14:56:14 -04002977 if (strncmp(buf, "+F:", 3) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002978 int alg;
2979 int j;
Ben Laurie0e211562001-10-25 14:27:17 +00002980
Matt Caswell0f113f32015-01-22 03:40:55 +00002981 p = buf + 3;
2982 alg = atoi(sstrsep(&p, sep));
2983 sstrsep(&p, sep);
2984 for (j = 0; j < SIZE_NUM; ++j)
2985 results[alg][j] += atof(sstrsep(&p, sep));
Rich Salz86885c22015-05-06 14:56:14 -04002986 } else if (strncmp(buf, "+F2:", 4) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00002987 int k;
2988 double d;
Ben Laurie0e211562001-10-25 14:27:17 +00002989
Matt Caswell0f113f32015-01-22 03:40:55 +00002990 p = buf + 4;
2991 k = atoi(sstrsep(&p, sep));
2992 sstrsep(&p, sep);
Ben Laurie0e211562001-10-25 14:27:17 +00002993
Matt Caswell0f113f32015-01-22 03:40:55 +00002994 d = atof(sstrsep(&p, sep));
2995 if (n)
2996 rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2997 else
2998 rsa_results[k][0] = d;
Ben Laurie0e211562001-10-25 14:27:17 +00002999
Matt Caswell0f113f32015-01-22 03:40:55 +00003000 d = atof(sstrsep(&p, sep));
3001 if (n)
3002 rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
3003 else
3004 rsa_results[k][1] = d;
Matt Caswell0f113f32015-01-22 03:40:55 +00003005 }
Rich Salza00ae6c2015-01-27 10:06:22 -05003006# ifndef OPENSSL_NO_DSA
Rich Salz86885c22015-05-06 14:56:14 -04003007 else if (strncmp(buf, "+F3:", 4) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00003008 int k;
3009 double d;
Bodo Möllere172d602002-08-09 08:43:04 +00003010
Matt Caswell0f113f32015-01-22 03:40:55 +00003011 p = buf + 4;
3012 k = atoi(sstrsep(&p, sep));
3013 sstrsep(&p, sep);
Bodo Möllere172d602002-08-09 08:43:04 +00003014
Matt Caswell0f113f32015-01-22 03:40:55 +00003015 d = atof(sstrsep(&p, sep));
3016 if (n)
3017 dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
3018 else
3019 dsa_results[k][0] = d;
Bodo Möllere172d602002-08-09 08:43:04 +00003020
Matt Caswell0f113f32015-01-22 03:40:55 +00003021 d = atof(sstrsep(&p, sep));
3022 if (n)
3023 dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
3024 else
3025 dsa_results[k][1] = d;
3026 }
Rich Salza00ae6c2015-01-27 10:06:22 -05003027# endif
Rich Salz10bf4fc2015-03-10 19:09:27 -04003028# ifndef OPENSSL_NO_EC
Rich Salz86885c22015-05-06 14:56:14 -04003029 else if (strncmp(buf, "+F4:", 4) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00003030 int k;
3031 double d;
Bodo Möllere172d602002-08-09 08:43:04 +00003032
Matt Caswell0f113f32015-01-22 03:40:55 +00003033 p = buf + 4;
3034 k = atoi(sstrsep(&p, sep));
3035 sstrsep(&p, sep);
Bodo Möllere172d602002-08-09 08:43:04 +00003036
Matt Caswell0f113f32015-01-22 03:40:55 +00003037 d = atof(sstrsep(&p, sep));
3038 if (n)
3039 ecdsa_results[k][0] =
3040 1 / (1 / ecdsa_results[k][0] + 1 / d);
3041 else
3042 ecdsa_results[k][0] = d;
Bodo Möllere172d602002-08-09 08:43:04 +00003043
Matt Caswell0f113f32015-01-22 03:40:55 +00003044 d = atof(sstrsep(&p, sep));
3045 if (n)
3046 ecdsa_results[k][1] =
3047 1 / (1 / ecdsa_results[k][1] + 1 / d);
3048 else
3049 ecdsa_results[k][1] = d;
3050 }
Rich Salz7e1b7482015-04-24 15:26:15 -04003051# endif
3052
3053# ifndef OPENSSL_NO_EC
Rich Salz86885c22015-05-06 14:56:14 -04003054 else if (strncmp(buf, "+F5:", 4) == 0) {
Matt Caswell0f113f32015-01-22 03:40:55 +00003055 int k;
3056 double d;
3057
3058 p = buf + 4;
3059 k = atoi(sstrsep(&p, sep));
3060 sstrsep(&p, sep);
3061
3062 d = atof(sstrsep(&p, sep));
3063 if (n)
3064 ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
3065 else
3066 ecdh_results[k][0] = d;
3067
3068 }
Rich Salza00ae6c2015-01-27 10:06:22 -05003069# endif
Matt Caswell0f113f32015-01-22 03:40:55 +00003070
Rich Salz86885c22015-05-06 14:56:14 -04003071 else if (strncmp(buf, "+H:", 3) == 0) {
Rich Salz7e1b7482015-04-24 15:26:15 -04003072 ;
Matt Caswell0f113f32015-01-22 03:40:55 +00003073 } else
Rich Salz7768e112015-06-04 14:26:55 -04003074 BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
Matt Caswell0f113f32015-01-22 03:40:55 +00003075 }
3076
3077 fclose(f);
3078 }
3079 free(fds);
3080 return 1;
3081}
Rich Salza00ae6c2015-01-27 10:06:22 -05003082#endif
Andy Polyakov375a64e2014-07-05 23:53:55 +02003083
3084static void multiblock_speed(const EVP_CIPHER *evp_cipher)
Matt Caswell0f113f32015-01-22 03:40:55 +00003085{
3086 static int mblengths[] =
3087 { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 };
Andrea Grandi8b0b80d2015-12-09 07:26:38 +00003088 int j, count, num = OSSL_NELEM(mblengths);
Matt Caswell0f113f32015-01-22 03:40:55 +00003089 const char *alg_name;
3090 unsigned char *inp, *out, no_key[32], no_iv[16];
Richard Levitte846ec072015-12-13 22:08:41 +01003091 EVP_CIPHER_CTX *ctx;
Matt Caswell0f113f32015-01-22 03:40:55 +00003092 double d = 0.0;
Andy Polyakov375a64e2014-07-05 23:53:55 +02003093
Rich Salz68dc6822015-04-30 17:48:31 -04003094 inp = app_malloc(mblengths[num - 1], "multiblock input buffer");
3095 out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer");
Richard Levitte846ec072015-12-13 22:08:41 +01003096 ctx = EVP_CIPHER_CTX_new();
3097 EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv);
3098 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key),
Matt Caswell0f113f32015-01-22 03:40:55 +00003099 no_key);
Richard Levitte6c2ff562015-12-18 17:08:49 +01003100 alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
Andy Polyakov375a64e2014-07-05 23:53:55 +02003101
Matt Caswell0f113f32015-01-22 03:40:55 +00003102 for (j = 0; j < num; j++) {
3103 print_message(alg_name, 0, mblengths[j]);
3104 Time_F(START);
3105 for (count = 0, run = 1; run && count < 0x7fffffff; count++) {
Matt Caswellc8269882015-04-27 11:07:06 +01003106 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
Matt Caswell0f113f32015-01-22 03:40:55 +00003107 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
3108 size_t len = mblengths[j];
3109 int packlen;
Andy Polyakov375a64e2014-07-05 23:53:55 +02003110
Matt Caswell0f113f32015-01-22 03:40:55 +00003111 memset(aad, 0, 8); /* avoid uninitialized values */
3112 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
3113 aad[9] = 3; /* version */
3114 aad[10] = 2;
3115 aad[11] = 0; /* length */
3116 aad[12] = 0;
3117 mb_param.out = NULL;
3118 mb_param.inp = aad;
3119 mb_param.len = len;
3120 mb_param.interleave = 8;
Andy Polyakov375a64e2014-07-05 23:53:55 +02003121
Richard Levitte846ec072015-12-13 22:08:41 +01003122 packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
Matt Caswell0f113f32015-01-22 03:40:55 +00003123 sizeof(mb_param), &mb_param);
Andy Polyakov375a64e2014-07-05 23:53:55 +02003124
Matt Caswell0f113f32015-01-22 03:40:55 +00003125 if (packlen > 0) {
3126 mb_param.out = out;
3127 mb_param.inp = inp;
3128 mb_param.len = len;
Richard Levitte846ec072015-12-13 22:08:41 +01003129 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
Matt Caswell0f113f32015-01-22 03:40:55 +00003130 sizeof(mb_param), &mb_param);
3131 } else {
3132 int pad;
Andy Polyakov375a64e2014-07-05 23:53:55 +02003133
Matt Caswell0f113f32015-01-22 03:40:55 +00003134 RAND_bytes(out, 16);
3135 len += 16;
3136 aad[11] = len >> 8;
3137 aad[12] = len;
Richard Levitte846ec072015-12-13 22:08:41 +01003138 pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
Matt Caswellc8269882015-04-27 11:07:06 +01003139 EVP_AEAD_TLS1_AAD_LEN, aad);
Richard Levitte846ec072015-12-13 22:08:41 +01003140 EVP_Cipher(ctx, out, inp, len + pad);
Matt Caswell0f113f32015-01-22 03:40:55 +00003141 }
3142 }
3143 d = Time_F(STOP);
Rich Salz7e1b7482015-04-24 15:26:15 -04003144 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
Matt Caswell0f113f32015-01-22 03:40:55 +00003145 : "%d %s's in %.2fs\n", count, "evp", d);
3146 results[D_EVP][j] = ((double)count) / d * mblengths[j];
3147 }
Andy Polyakov375a64e2014-07-05 23:53:55 +02003148
Matt Caswell0f113f32015-01-22 03:40:55 +00003149 if (mr) {
3150 fprintf(stdout, "+H");
3151 for (j = 0; j < num; j++)
3152 fprintf(stdout, ":%d", mblengths[j]);
3153 fprintf(stdout, "\n");
3154 fprintf(stdout, "+F:%d:%s", D_EVP, alg_name);
3155 for (j = 0; j < num; j++)
3156 fprintf(stdout, ":%.2f", results[D_EVP][j]);
3157 fprintf(stdout, "\n");
3158 } else {
3159 fprintf(stdout,
3160 "The 'numbers' are in 1000s of bytes per second processed.\n");
3161 fprintf(stdout, "type ");
3162 for (j = 0; j < num; j++)
3163 fprintf(stdout, "%7d bytes", mblengths[j]);
3164 fprintf(stdout, "\n");
3165 fprintf(stdout, "%-24s", alg_name);
Andy Polyakov375a64e2014-07-05 23:53:55 +02003166
Matt Caswell0f113f32015-01-22 03:40:55 +00003167 for (j = 0; j < num; j++) {
3168 if (results[D_EVP][j] > 10000)
3169 fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3);
3170 else
3171 fprintf(stdout, " %11.2f ", results[D_EVP][j]);
3172 }
3173 fprintf(stdout, "\n");
3174 }
Andy Polyakov375a64e2014-07-05 23:53:55 +02003175
Rich Salzb548a1f2015-05-01 10:02:07 -04003176 OPENSSL_free(inp);
3177 OPENSSL_free(out);
Richard Levitte846ec072015-12-13 22:08:41 +01003178 EVP_CIPHER_CTX_free(ctx);
Matt Caswell0f113f32015-01-22 03:40:55 +00003179}