Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 3 | * |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 4 | * Licensed under the OpenSSL license (the "License"). You may not use |
| 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 8 | */ |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 9 | |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 10 | /* ==================================================================== |
Felix Laurie von Massenbach | 7e965dc | 2014-05-27 12:41:20 +0100 | [diff] [blame] | 11 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 12 | * |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 13 | * Portions of the attached software ("Contribution") are developed by |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 14 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. |
| 15 | * |
| 16 | * The Contribution is licensed pursuant to the OpenSSL open source |
| 17 | * license provided above. |
| 18 | * |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 19 | * The ECDH and ECDSA speed test software is originally written by |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 20 | * Sumit Gupta of Sun Microsystems Laboratories. |
| 21 | * |
| 22 | */ |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 23 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 24 | #undef SECONDS |
| 25 | #define SECONDS 3 |
| 26 | #define PRIME_SECONDS 10 |
| 27 | #define RSA_SECONDS 10 |
| 28 | #define DSA_SECONDS 10 |
| 29 | #define ECDSA_SECONDS 10 |
| 30 | #define ECDH_SECONDS 10 |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 31 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 34 | #include <string.h> |
| 35 | #include <math.h> |
| 36 | #include "apps.h" |
| 37 | #include <openssl/crypto.h> |
| 38 | #include <openssl/rand.h> |
| 39 | #include <openssl/err.h> |
| 40 | #include <openssl/evp.h> |
| 41 | #include <openssl/objects.h> |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 42 | #include <openssl/async.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 43 | #if !defined(OPENSSL_SYS_MSDOS) |
| 44 | # include OPENSSL_UNISTD |
| 45 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 46 | |
Corinna Vinschen | 8d35ceb | 2016-01-16 19:30:48 +0100 | [diff] [blame] | 47 | #if defined(_WIN32) |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 48 | # include <windows.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 49 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 50 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 51 | #include <openssl/bn.h> |
| 52 | #ifndef OPENSSL_NO_DES |
| 53 | # include <openssl/des.h> |
| 54 | #endif |
Matt Caswell | 5158c76 | 2016-04-13 11:28:45 +0100 | [diff] [blame] | 55 | #include <openssl/aes.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 56 | #ifndef OPENSSL_NO_CAMELLIA |
| 57 | # include <openssl/camellia.h> |
| 58 | #endif |
| 59 | #ifndef OPENSSL_NO_MD2 |
| 60 | # include <openssl/md2.h> |
| 61 | #endif |
| 62 | #ifndef OPENSSL_NO_MDC2 |
| 63 | # include <openssl/mdc2.h> |
| 64 | #endif |
| 65 | #ifndef OPENSSL_NO_MD4 |
| 66 | # include <openssl/md4.h> |
| 67 | #endif |
| 68 | #ifndef OPENSSL_NO_MD5 |
| 69 | # include <openssl/md5.h> |
| 70 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 71 | #include <openssl/hmac.h> |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 72 | #include <openssl/sha.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 73 | #ifndef OPENSSL_NO_RMD160 |
| 74 | # include <openssl/ripemd.h> |
| 75 | #endif |
| 76 | #ifndef OPENSSL_NO_WHIRLPOOL |
| 77 | # include <openssl/whrlpool.h> |
| 78 | #endif |
| 79 | #ifndef OPENSSL_NO_RC4 |
| 80 | # include <openssl/rc4.h> |
| 81 | #endif |
| 82 | #ifndef OPENSSL_NO_RC5 |
| 83 | # include <openssl/rc5.h> |
| 84 | #endif |
| 85 | #ifndef OPENSSL_NO_RC2 |
| 86 | # include <openssl/rc2.h> |
| 87 | #endif |
| 88 | #ifndef OPENSSL_NO_IDEA |
| 89 | # include <openssl/idea.h> |
| 90 | #endif |
| 91 | #ifndef OPENSSL_NO_SEED |
| 92 | # include <openssl/seed.h> |
| 93 | #endif |
| 94 | #ifndef OPENSSL_NO_BF |
| 95 | # include <openssl/blowfish.h> |
| 96 | #endif |
| 97 | #ifndef OPENSSL_NO_CAST |
| 98 | # include <openssl/cast.h> |
| 99 | #endif |
| 100 | #ifndef OPENSSL_NO_RSA |
| 101 | # include <openssl/rsa.h> |
| 102 | # include "./testrsa.h" |
| 103 | #endif |
| 104 | #include <openssl/x509.h> |
| 105 | #ifndef OPENSSL_NO_DSA |
| 106 | # include <openssl/dsa.h> |
| 107 | # include "./testdsa.h" |
| 108 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 109 | #ifndef OPENSSL_NO_EC |
Dr. Stephen Henson | fb29bb5 | 2015-10-27 19:39:32 +0000 | [diff] [blame] | 110 | # include <openssl/ec.h> |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 111 | #endif |
| 112 | #include <openssl/modes.h> |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 113 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 114 | #ifndef HAVE_FORK |
Rich Salz | 1fbab1d | 2016-03-17 12:53:11 -0400 | [diff] [blame] | 115 | # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 116 | # define HAVE_FORK 0 |
Dr. Stephen Henson | ebaa2cf | 2010-03-03 19:56:34 +0000 | [diff] [blame] | 117 | # else |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 118 | # define HAVE_FORK 1 |
Dr. Stephen Henson | ebaa2cf | 2010-03-03 19:56:34 +0000 | [diff] [blame] | 119 | # endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 120 | #endif |
Dr. Stephen Henson | ebaa2cf | 2010-03-03 19:56:34 +0000 | [diff] [blame] | 121 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 122 | #if HAVE_FORK |
| 123 | # undef NO_FORK |
| 124 | #else |
| 125 | # define NO_FORK |
| 126 | #endif |
| 127 | |
| 128 | #undef BUFSIZE |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 129 | #define BUFSIZE (1024*16+1) |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 130 | #define MAX_MISALIGNMENT 63 |
Richard Levitte | 66d3e74 | 2001-10-25 16:08:17 +0000 | [diff] [blame] | 131 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 132 | #define ALGOR_NUM 30 |
| 133 | #define SIZE_NUM 6 |
| 134 | #define PRIME_NUM 3 |
| 135 | #define RSA_NUM 7 |
| 136 | #define DSA_NUM 3 |
| 137 | |
| 138 | #define EC_NUM 17 |
| 139 | #define MAX_ECDH_SIZE 256 |
| 140 | #define MISALIGN 64 |
| 141 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 142 | static volatile int run = 0; |
Andy Polyakov | e2d03db | 2014-08-30 10:25:32 +0200 | [diff] [blame] | 143 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 144 | static int mr = 0; |
| 145 | static int usertime = 1; |
Richard Levitte | 7876e44 | 2001-09-27 15:43:55 +0000 | [diff] [blame] | 146 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 147 | typedef struct loopargs_st { |
| 148 | ASYNC_JOB *inprogress_job; |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 149 | ASYNC_WAIT_CTX *wait_ctx; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 150 | unsigned char *buf; |
| 151 | unsigned char *buf2; |
| 152 | unsigned char *buf_malloc; |
| 153 | unsigned char *buf2_malloc; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 154 | unsigned int siglen; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 155 | #ifndef OPENSSL_NO_RSA |
| 156 | RSA *rsa_key[RSA_NUM]; |
| 157 | #endif |
| 158 | #ifndef OPENSSL_NO_DSA |
| 159 | DSA *dsa_key[DSA_NUM]; |
| 160 | #endif |
| 161 | #ifndef OPENSSL_NO_EC |
| 162 | EC_KEY *ecdsa[EC_NUM]; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 163 | EVP_PKEY_CTX *ecdh_ctx[EC_NUM]; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 164 | unsigned char *secret_a; |
| 165 | unsigned char *secret_b; |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 166 | size_t outlen[EC_NUM]; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 167 | #endif |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 168 | EVP_CIPHER_CTX *ctx; |
| 169 | HMAC_CTX *hctx; |
| 170 | GCM128_CONTEXT *gcm_ctx; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 171 | } loopargs_t; |
| 172 | |
| 173 | #ifndef OPENSSL_NO_MD2 |
| 174 | static int EVP_Digest_MD2_loop(void *args); |
| 175 | #endif |
| 176 | |
| 177 | #ifndef OPENSSL_NO_MDC2 |
| 178 | static int EVP_Digest_MDC2_loop(void *args); |
| 179 | #endif |
| 180 | #ifndef OPENSSL_NO_MD4 |
| 181 | static int EVP_Digest_MD4_loop(void *args); |
| 182 | #endif |
| 183 | #ifndef OPENSSL_NO_MD5 |
| 184 | static int MD5_loop(void *args); |
| 185 | static int HMAC_loop(void *args); |
| 186 | #endif |
| 187 | static int SHA1_loop(void *args); |
| 188 | static int SHA256_loop(void *args); |
| 189 | static int SHA512_loop(void *args); |
| 190 | #ifndef OPENSSL_NO_WHIRLPOOL |
| 191 | static int WHIRLPOOL_loop(void *args); |
| 192 | #endif |
| 193 | #ifndef OPENSSL_NO_RMD160 |
| 194 | static int EVP_Digest_RMD160_loop(void *args); |
| 195 | #endif |
| 196 | #ifndef OPENSSL_NO_RC4 |
| 197 | static int RC4_loop(void *args); |
| 198 | #endif |
| 199 | #ifndef OPENSSL_NO_DES |
| 200 | static int DES_ncbc_encrypt_loop(void *args); |
| 201 | static int DES_ede3_cbc_encrypt_loop(void *args); |
| 202 | #endif |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 203 | static int AES_cbc_128_encrypt_loop(void *args); |
| 204 | static int AES_cbc_192_encrypt_loop(void *args); |
| 205 | static int AES_ige_128_encrypt_loop(void *args); |
| 206 | static int AES_cbc_256_encrypt_loop(void *args); |
| 207 | static int AES_ige_192_encrypt_loop(void *args); |
| 208 | static int AES_ige_256_encrypt_loop(void *args); |
| 209 | static int CRYPTO_gcm128_aad_loop(void *args); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 210 | static int EVP_Update_loop(void *args); |
| 211 | static int EVP_Digest_loop(void *args); |
| 212 | #ifndef OPENSSL_NO_RSA |
| 213 | static int RSA_sign_loop(void *args); |
| 214 | static int RSA_verify_loop(void *args); |
| 215 | #endif |
| 216 | #ifndef OPENSSL_NO_DSA |
| 217 | static int DSA_sign_loop(void *args); |
| 218 | static int DSA_verify_loop(void *args); |
| 219 | #endif |
| 220 | #ifndef OPENSSL_NO_EC |
| 221 | static int ECDSA_sign_loop(void *args); |
| 222 | static int ECDSA_verify_loop(void *args); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 223 | #endif |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 224 | static int run_benchmark(int async_jobs, int (*loop_function) (void *), |
| 225 | loopargs_t * loopargs); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 226 | |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 227 | static double Time_F(int s); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 228 | static void print_message(const char *s, long num, int length); |
Nils Larsch | 689c6f2 | 2005-03-20 23:12:13 +0000 | [diff] [blame] | 229 | static void pkey_print_message(const char *str, const char *str2, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 230 | long num, int bits, int sec); |
| 231 | static void print_result(int alg, int run_no, int count, double time_used); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 232 | #ifndef NO_FORK |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 233 | static int do_multi(int multi); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 234 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 235 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 236 | static const char *names[ALGOR_NUM] = { |
| 237 | "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4", |
| 238 | "des cbc", "des ede3", "idea cbc", "seed cbc", |
| 239 | "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc", |
| 240 | "aes-128 cbc", "aes-192 cbc", "aes-256 cbc", |
| 241 | "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc", |
| 242 | "evp", "sha256", "sha512", "whirlpool", |
| 243 | "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash" |
| 244 | }; |
| 245 | |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 246 | static double results[ALGOR_NUM][SIZE_NUM]; |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 247 | |
| 248 | static const int lengths[SIZE_NUM] = { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 249 | 16, 64, 256, 1024, 8 * 1024, 16 * 1024 |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 250 | }; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 251 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 252 | #ifndef OPENSSL_NO_RSA |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 253 | static double rsa_results[RSA_NUM][2]; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 254 | #endif |
| 255 | #ifndef OPENSSL_NO_DSA |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 256 | static double dsa_results[DSA_NUM][2]; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 257 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 258 | #ifndef OPENSSL_NO_EC |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 259 | static double ecdsa_results[EC_NUM][2]; |
| 260 | static double ecdh_results[EC_NUM][1]; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 261 | #endif |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 262 | |
Matt Caswell | b22234d | 2016-04-06 11:17:44 +0100 | [diff] [blame] | 263 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 264 | static const char rnd_seed[] = |
| 265 | "string to make the random number generator think it has entropy"; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 266 | #endif |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 267 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 268 | #ifdef SIGALRM |
| 269 | # if defined(__STDC__) || defined(sgi) || defined(_AIX) |
| 270 | # define SIGRETTYPE void |
| 271 | # else |
| 272 | # define SIGRETTYPE int |
| 273 | # endif |
Dr. Stephen Henson | b83eddc | 2001-11-06 13:40:27 +0000 | [diff] [blame] | 274 | |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 275 | static SIGRETTYPE sig_done(int sig); |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 276 | static SIGRETTYPE sig_done(int sig) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 277 | { |
| 278 | signal(SIGALRM, sig_done); |
| 279 | run = 0; |
| 280 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 281 | #endif |
| 282 | |
| 283 | #define START 0 |
| 284 | #define STOP 1 |
| 285 | |
| 286 | #if defined(_WIN32) |
| 287 | |
| 288 | # if !defined(SIGALRM) |
| 289 | # define SIGALRM |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 290 | # endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 291 | static unsigned int lapse, schlock; |
| 292 | static void alarm_win32(unsigned int secs) |
| 293 | { |
| 294 | lapse = secs * 1000; |
| 295 | } |
Andy Polyakov | 0a39d8f | 2005-11-06 11:40:59 +0000 | [diff] [blame] | 296 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 297 | # define alarm alarm_win32 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 298 | |
| 299 | static DWORD WINAPI sleepy(VOID * arg) |
| 300 | { |
| 301 | schlock = 1; |
| 302 | Sleep(lapse); |
| 303 | run = 0; |
| 304 | return 0; |
| 305 | } |
Andy Polyakov | 0a39d8f | 2005-11-06 11:40:59 +0000 | [diff] [blame] | 306 | |
Richard Levitte | 4d8743f | 2003-11-28 13:10:58 +0000 | [diff] [blame] | 307 | static double Time_F(int s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 308 | { |
| 309 | double ret; |
| 310 | static HANDLE thr; |
Andy Polyakov | d582c98 | 2010-01-17 17:31:38 +0000 | [diff] [blame] | 311 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 312 | if (s == START) { |
| 313 | schlock = 0; |
| 314 | thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL); |
| 315 | if (thr == NULL) { |
Andy Polyakov | db40a14 | 2015-09-28 16:05:32 +0200 | [diff] [blame] | 316 | DWORD err = GetLastError(); |
| 317 | BIO_printf(bio_err, "unable to CreateThread (%lu)", err); |
Matt Caswell | f219a1b | 2016-06-16 15:59:42 +0100 | [diff] [blame] | 318 | ExitProcess(err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 319 | } |
| 320 | while (!schlock) |
| 321 | Sleep(0); /* scheduler spinlock */ |
| 322 | ret = app_tminterval(s, usertime); |
| 323 | } else { |
| 324 | ret = app_tminterval(s, usertime); |
| 325 | if (run) |
| 326 | TerminateThread(thr, 0); |
| 327 | CloseHandle(thr); |
| 328 | } |
Richard Levitte | 4d8743f | 2003-11-28 13:10:58 +0000 | [diff] [blame] | 329 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 330 | return ret; |
| 331 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 332 | #else |
Richard Levitte | 4d8743f | 2003-11-28 13:10:58 +0000 | [diff] [blame] | 333 | |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 334 | static double Time_F(int s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 335 | { |
| 336 | double ret = app_tminterval(s, usertime); |
| 337 | if (s == STOP) |
| 338 | alarm(0); |
| 339 | return ret; |
| 340 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 341 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 342 | |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 343 | static void multiblock_speed(const EVP_CIPHER *evp_cipher); |
Bodo Möller | 176f31d | 2003-02-28 15:37:10 +0000 | [diff] [blame] | 344 | |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 345 | static int found(const char *name, const OPT_PAIR *pairs, int *result) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 346 | { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 347 | for (; pairs->name; pairs++) |
| 348 | if (strcmp(name, pairs->name) == 0) { |
| 349 | *result = pairs->retval; |
| 350 | return 1; |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | typedef enum OPTION_choice { |
| 356 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, |
| 357 | OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI, |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 358 | OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 359 | } OPTION_CHOICE; |
| 360 | |
FdaSilvaYY | 44c83eb | 2016-03-13 14:07:50 +0100 | [diff] [blame] | 361 | const OPTIONS speed_options[] = { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 362 | {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"}, |
| 363 | {OPT_HELP_STR, 1, '-', "Valid options are:\n"}, |
| 364 | {"help", OPT_HELP, '-', "Display this summary"}, |
Rich Salz | 9c3bcfa | 2015-05-15 13:50:38 -0400 | [diff] [blame] | 365 | {"evp", OPT_EVP, 's', "Use specified EVP cipher"}, |
| 366 | {"decrypt", OPT_DECRYPT, '-', |
| 367 | "Time decryption instead of encryption (only EVP)"}, |
| 368 | {"mr", OPT_MR, '-', "Produce machine readable output"}, |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 369 | {"mb", OPT_MB, '-', |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 370 | "Enable (tls1.1) multi-block mode on evp_cipher requested with -evp"}, |
Rich Salz | 9c3bcfa | 2015-05-15 13:50:38 -0400 | [diff] [blame] | 371 | {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 372 | {"elapsed", OPT_ELAPSED, '-', |
| 373 | "Measure time in real time instead of CPU user time"}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 374 | #ifndef NO_FORK |
| 375 | {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"}, |
| 376 | #endif |
Matt Caswell | 667867c | 2016-03-07 16:55:39 +0000 | [diff] [blame] | 377 | #ifndef OPENSSL_NO_ASYNC |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 378 | {"async_jobs", OPT_ASYNCJOBS, 'p', |
| 379 | "Enable async mode and start pnum jobs"}, |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 380 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 381 | #ifndef OPENSSL_NO_ENGINE |
| 382 | {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, |
| 383 | #endif |
Kurt Cancemi | 7786005 | 2015-05-07 18:19:20 -0400 | [diff] [blame] | 384 | {NULL}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | #define D_MD2 0 |
| 388 | #define D_MDC2 1 |
| 389 | #define D_MD4 2 |
| 390 | #define D_MD5 3 |
| 391 | #define D_HMAC 4 |
| 392 | #define D_SHA1 5 |
| 393 | #define D_RMD160 6 |
| 394 | #define D_RC4 7 |
| 395 | #define D_CBC_DES 8 |
| 396 | #define D_EDE3_DES 9 |
| 397 | #define D_CBC_IDEA 10 |
| 398 | #define D_CBC_SEED 11 |
| 399 | #define D_CBC_RC2 12 |
| 400 | #define D_CBC_RC5 13 |
| 401 | #define D_CBC_BF 14 |
| 402 | #define D_CBC_CAST 15 |
| 403 | #define D_CBC_128_AES 16 |
| 404 | #define D_CBC_192_AES 17 |
| 405 | #define D_CBC_256_AES 18 |
| 406 | #define D_CBC_128_CML 19 |
| 407 | #define D_CBC_192_CML 20 |
| 408 | #define D_CBC_256_CML 21 |
| 409 | #define D_EVP 22 |
| 410 | #define D_SHA256 23 |
| 411 | #define D_SHA512 24 |
| 412 | #define D_WHIRLPOOL 25 |
| 413 | #define D_IGE_128_AES 26 |
| 414 | #define D_IGE_192_AES 27 |
| 415 | #define D_IGE_256_AES 28 |
| 416 | #define D_GHASH 29 |
Ben Laurie | df2ee0e | 2015-09-05 13:32:58 +0100 | [diff] [blame] | 417 | static OPT_PAIR doit_choices[] = { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 418 | #ifndef OPENSSL_NO_MD2 |
| 419 | {"md2", D_MD2}, |
| 420 | #endif |
| 421 | #ifndef OPENSSL_NO_MDC2 |
| 422 | {"mdc2", D_MDC2}, |
| 423 | #endif |
| 424 | #ifndef OPENSSL_NO_MD4 |
| 425 | {"md4", D_MD4}, |
| 426 | #endif |
| 427 | #ifndef OPENSSL_NO_MD5 |
| 428 | {"md5", D_MD5}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 429 | {"hmac", D_HMAC}, |
| 430 | #endif |
| 431 | {"sha1", D_SHA1}, |
| 432 | {"sha256", D_SHA256}, |
| 433 | {"sha512", D_SHA512}, |
| 434 | #ifndef OPENSSL_NO_WHIRLPOOL |
| 435 | {"whirlpool", D_WHIRLPOOL}, |
| 436 | #endif |
Rich Salz | fd682e4 | 2015-08-06 12:22:31 -0400 | [diff] [blame] | 437 | #ifndef OPENSSL_NO_RMD160 |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 438 | {"ripemd", D_RMD160}, |
| 439 | {"rmd160", D_RMD160}, |
| 440 | {"ripemd160", D_RMD160}, |
| 441 | #endif |
| 442 | #ifndef OPENSSL_NO_RC4 |
| 443 | {"rc4", D_RC4}, |
| 444 | #endif |
| 445 | #ifndef OPENSSL_NO_DES |
| 446 | {"des-cbc", D_CBC_DES}, |
| 447 | {"des-ede3", D_EDE3_DES}, |
| 448 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 449 | {"aes-128-cbc", D_CBC_128_AES}, |
| 450 | {"aes-192-cbc", D_CBC_192_AES}, |
| 451 | {"aes-256-cbc", D_CBC_256_AES}, |
| 452 | {"aes-128-ige", D_IGE_128_AES}, |
| 453 | {"aes-192-ige", D_IGE_192_AES}, |
| 454 | {"aes-256-ige", D_IGE_256_AES}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 455 | #ifndef OPENSSL_NO_RC2 |
| 456 | {"rc2-cbc", D_CBC_RC2}, |
| 457 | {"rc2", D_CBC_RC2}, |
| 458 | #endif |
| 459 | #ifndef OPENSSL_NO_RC5 |
| 460 | {"rc5-cbc", D_CBC_RC5}, |
| 461 | {"rc5", D_CBC_RC5}, |
| 462 | #endif |
| 463 | #ifndef OPENSSL_NO_IDEA |
| 464 | {"idea-cbc", D_CBC_IDEA}, |
| 465 | {"idea", D_CBC_IDEA}, |
| 466 | #endif |
| 467 | #ifndef OPENSSL_NO_SEED |
| 468 | {"seed-cbc", D_CBC_SEED}, |
| 469 | {"seed", D_CBC_SEED}, |
| 470 | #endif |
| 471 | #ifndef OPENSSL_NO_BF |
| 472 | {"bf-cbc", D_CBC_BF}, |
| 473 | {"blowfish", D_CBC_BF}, |
| 474 | {"bf", D_CBC_BF}, |
| 475 | #endif |
| 476 | #ifndef OPENSSL_NO_CAST |
| 477 | {"cast-cbc", D_CBC_CAST}, |
| 478 | {"cast", D_CBC_CAST}, |
| 479 | {"cast5", D_CBC_CAST}, |
| 480 | #endif |
| 481 | {"ghash", D_GHASH}, |
| 482 | {NULL} |
| 483 | }; |
| 484 | |
Matt Caswell | 83ae812 | 2016-03-18 17:43:58 +0000 | [diff] [blame] | 485 | #ifndef OPENSSL_NO_DSA |
| 486 | # define R_DSA_512 0 |
| 487 | # define R_DSA_1024 1 |
| 488 | # define R_DSA_2048 2 |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 489 | static OPT_PAIR dsa_choices[] = { |
| 490 | {"dsa512", R_DSA_512}, |
| 491 | {"dsa1024", R_DSA_1024}, |
| 492 | {"dsa2048", R_DSA_2048}, |
| 493 | {NULL}, |
| 494 | }; |
Matt Caswell | 83ae812 | 2016-03-18 17:43:58 +0000 | [diff] [blame] | 495 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 496 | |
| 497 | #define R_RSA_512 0 |
| 498 | #define R_RSA_1024 1 |
| 499 | #define R_RSA_2048 2 |
| 500 | #define R_RSA_3072 3 |
| 501 | #define R_RSA_4096 4 |
| 502 | #define R_RSA_7680 5 |
| 503 | #define R_RSA_15360 6 |
| 504 | static OPT_PAIR rsa_choices[] = { |
| 505 | {"rsa512", R_RSA_512}, |
| 506 | {"rsa1024", R_RSA_1024}, |
| 507 | {"rsa2048", R_RSA_2048}, |
| 508 | {"rsa3072", R_RSA_3072}, |
| 509 | {"rsa4096", R_RSA_4096}, |
| 510 | {"rsa7680", R_RSA_7680}, |
| 511 | {"rsa15360", R_RSA_15360}, |
| 512 | {NULL} |
| 513 | }; |
| 514 | |
| 515 | #define R_EC_P160 0 |
| 516 | #define R_EC_P192 1 |
| 517 | #define R_EC_P224 2 |
| 518 | #define R_EC_P256 3 |
| 519 | #define R_EC_P384 4 |
| 520 | #define R_EC_P521 5 |
| 521 | #define R_EC_K163 6 |
| 522 | #define R_EC_K233 7 |
| 523 | #define R_EC_K283 8 |
| 524 | #define R_EC_K409 9 |
| 525 | #define R_EC_K571 10 |
| 526 | #define R_EC_B163 11 |
| 527 | #define R_EC_B233 12 |
| 528 | #define R_EC_B283 13 |
| 529 | #define R_EC_B409 14 |
| 530 | #define R_EC_B571 15 |
Dr. Stephen Henson | db50c1d | 2016-02-12 14:11:47 +0000 | [diff] [blame] | 531 | #define R_EC_X25519 16 |
Richard Levitte | f5349f8 | 2015-09-20 00:46:44 +0200 | [diff] [blame] | 532 | #ifndef OPENSSL_NO_EC |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 533 | static OPT_PAIR ecdsa_choices[] = { |
| 534 | {"ecdsap160", R_EC_P160}, |
| 535 | {"ecdsap192", R_EC_P192}, |
| 536 | {"ecdsap224", R_EC_P224}, |
| 537 | {"ecdsap256", R_EC_P256}, |
| 538 | {"ecdsap384", R_EC_P384}, |
| 539 | {"ecdsap521", R_EC_P521}, |
| 540 | {"ecdsak163", R_EC_K163}, |
| 541 | {"ecdsak233", R_EC_K233}, |
| 542 | {"ecdsak283", R_EC_K283}, |
| 543 | {"ecdsak409", R_EC_K409}, |
| 544 | {"ecdsak571", R_EC_K571}, |
| 545 | {"ecdsab163", R_EC_B163}, |
| 546 | {"ecdsab233", R_EC_B233}, |
| 547 | {"ecdsab283", R_EC_B283}, |
| 548 | {"ecdsab409", R_EC_B409}, |
| 549 | {"ecdsab571", R_EC_B571}, |
| 550 | {NULL} |
| 551 | }; |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 552 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 553 | static OPT_PAIR ecdh_choices[] = { |
| 554 | {"ecdhp160", R_EC_P160}, |
| 555 | {"ecdhp192", R_EC_P192}, |
| 556 | {"ecdhp224", R_EC_P224}, |
| 557 | {"ecdhp256", R_EC_P256}, |
| 558 | {"ecdhp384", R_EC_P384}, |
| 559 | {"ecdhp521", R_EC_P521}, |
| 560 | {"ecdhk163", R_EC_K163}, |
| 561 | {"ecdhk233", R_EC_K233}, |
| 562 | {"ecdhk283", R_EC_K283}, |
| 563 | {"ecdhk409", R_EC_K409}, |
| 564 | {"ecdhk571", R_EC_K571}, |
| 565 | {"ecdhb163", R_EC_B163}, |
| 566 | {"ecdhb233", R_EC_B233}, |
| 567 | {"ecdhb283", R_EC_B283}, |
| 568 | {"ecdhb409", R_EC_B409}, |
| 569 | {"ecdhb571", R_EC_B571}, |
Dr. Stephen Henson | db50c1d | 2016-02-12 14:11:47 +0000 | [diff] [blame] | 570 | {"ecdhx25519", R_EC_X25519}, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 571 | {NULL} |
| 572 | }; |
| 573 | #endif |
| 574 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 575 | #ifndef SIGALRM |
| 576 | # define COND(d) (count < (d)) |
| 577 | # define COUNT(d) (d) |
| 578 | #else |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 579 | # define COND(unused_cond) (run && count<0x7fffffff) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 580 | # define COUNT(d) (count) |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 581 | #endif /* SIGALRM */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 582 | |
| 583 | static int testnum; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 584 | |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 585 | /* Nb of iterations to do per algorithm and key-size */ |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 586 | static long c[ALGOR_NUM][SIZE_NUM]; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 587 | |
| 588 | #ifndef OPENSSL_NO_MD2 |
| 589 | static int EVP_Digest_MD2_loop(void *args) |
| 590 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 591 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 592 | unsigned char *buf = tempargs->buf; |
| 593 | unsigned char md2[MD2_DIGEST_LENGTH]; |
| 594 | int count; |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 595 | |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 596 | for (count = 0; COND(c[D_MD2][testnum]); count++) { |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 597 | if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(), |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 598 | NULL)) |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 599 | return -1; |
| 600 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 601 | return count; |
| 602 | } |
| 603 | #endif |
| 604 | |
| 605 | #ifndef OPENSSL_NO_MDC2 |
| 606 | static int EVP_Digest_MDC2_loop(void *args) |
| 607 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 608 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 609 | unsigned char *buf = tempargs->buf; |
| 610 | unsigned char mdc2[MDC2_DIGEST_LENGTH]; |
| 611 | int count; |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 612 | |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 613 | for (count = 0; COND(c[D_MDC2][testnum]); count++) { |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 614 | if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(), |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 615 | NULL)) |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 616 | return -1; |
| 617 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 618 | return count; |
| 619 | } |
| 620 | #endif |
| 621 | |
| 622 | #ifndef OPENSSL_NO_MD4 |
| 623 | static int EVP_Digest_MD4_loop(void *args) |
| 624 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 625 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 626 | unsigned char *buf = tempargs->buf; |
| 627 | unsigned char md4[MD4_DIGEST_LENGTH]; |
| 628 | int count; |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 629 | |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 630 | for (count = 0; COND(c[D_MD4][testnum]); count++) { |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 631 | if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(), |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 632 | NULL)) |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 633 | return -1; |
| 634 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 635 | return count; |
| 636 | } |
| 637 | #endif |
| 638 | |
| 639 | #ifndef OPENSSL_NO_MD5 |
| 640 | static int MD5_loop(void *args) |
| 641 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 642 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 643 | unsigned char *buf = tempargs->buf; |
| 644 | unsigned char md5[MD5_DIGEST_LENGTH]; |
| 645 | int count; |
| 646 | for (count = 0; COND(c[D_MD5][testnum]); count++) |
| 647 | MD5(buf, lengths[testnum], md5); |
| 648 | return count; |
| 649 | } |
| 650 | |
| 651 | static int HMAC_loop(void *args) |
| 652 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 653 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 654 | unsigned char *buf = tempargs->buf; |
| 655 | HMAC_CTX *hctx = tempargs->hctx; |
| 656 | unsigned char hmac[MD5_DIGEST_LENGTH]; |
| 657 | int count; |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 658 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 659 | for (count = 0; COND(c[D_HMAC][testnum]); count++) { |
| 660 | HMAC_Init_ex(hctx, NULL, 0, NULL, NULL); |
| 661 | HMAC_Update(hctx, buf, lengths[testnum]); |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 662 | HMAC_Final(hctx, hmac, NULL); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 663 | } |
| 664 | return count; |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | static int SHA1_loop(void *args) |
| 669 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 670 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 671 | unsigned char *buf = tempargs->buf; |
| 672 | unsigned char sha[SHA_DIGEST_LENGTH]; |
| 673 | int count; |
| 674 | for (count = 0; COND(c[D_SHA1][testnum]); count++) |
| 675 | SHA1(buf, lengths[testnum], sha); |
| 676 | return count; |
| 677 | } |
| 678 | |
| 679 | static int SHA256_loop(void *args) |
| 680 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 681 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 682 | unsigned char *buf = tempargs->buf; |
| 683 | unsigned char sha256[SHA256_DIGEST_LENGTH]; |
| 684 | int count; |
| 685 | for (count = 0; COND(c[D_SHA256][testnum]); count++) |
| 686 | SHA256(buf, lengths[testnum], sha256); |
| 687 | return count; |
| 688 | } |
| 689 | |
| 690 | static int SHA512_loop(void *args) |
| 691 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 692 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 693 | unsigned char *buf = tempargs->buf; |
| 694 | unsigned char sha512[SHA512_DIGEST_LENGTH]; |
| 695 | int count; |
| 696 | for (count = 0; COND(c[D_SHA512][testnum]); count++) |
| 697 | SHA512(buf, lengths[testnum], sha512); |
| 698 | return count; |
| 699 | } |
| 700 | |
| 701 | #ifndef OPENSSL_NO_WHIRLPOOL |
| 702 | static int WHIRLPOOL_loop(void *args) |
| 703 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 704 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 705 | unsigned char *buf = tempargs->buf; |
| 706 | unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH]; |
| 707 | int count; |
| 708 | for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++) |
| 709 | WHIRLPOOL(buf, lengths[testnum], whirlpool); |
| 710 | return count; |
| 711 | } |
| 712 | #endif |
| 713 | |
| 714 | #ifndef OPENSSL_NO_RMD160 |
| 715 | static int EVP_Digest_RMD160_loop(void *args) |
| 716 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 717 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 718 | unsigned char *buf = tempargs->buf; |
| 719 | unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; |
| 720 | int count; |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 721 | for (count = 0; COND(c[D_RMD160][testnum]); count++) { |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 722 | if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]), |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 723 | NULL, EVP_ripemd160(), NULL)) |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 724 | return -1; |
| 725 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 726 | return count; |
| 727 | } |
| 728 | #endif |
| 729 | |
| 730 | #ifndef OPENSSL_NO_RC4 |
| 731 | static RC4_KEY rc4_ks; |
| 732 | static int RC4_loop(void *args) |
| 733 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 734 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 735 | unsigned char *buf = tempargs->buf; |
| 736 | int count; |
| 737 | for (count = 0; COND(c[D_RC4][testnum]); count++) |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 738 | RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 739 | return count; |
| 740 | } |
| 741 | #endif |
| 742 | |
| 743 | #ifndef OPENSSL_NO_DES |
| 744 | static unsigned char DES_iv[8]; |
| 745 | static DES_key_schedule sch; |
| 746 | static DES_key_schedule sch2; |
| 747 | static DES_key_schedule sch3; |
| 748 | static int DES_ncbc_encrypt_loop(void *args) |
| 749 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 750 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 751 | unsigned char *buf = tempargs->buf; |
| 752 | int count; |
| 753 | for (count = 0; COND(c[D_CBC_DES][testnum]); count++) |
| 754 | DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 755 | &DES_iv, DES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 756 | return count; |
| 757 | } |
| 758 | |
| 759 | static int DES_ede3_cbc_encrypt_loop(void *args) |
| 760 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 761 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 762 | unsigned char *buf = tempargs->buf; |
| 763 | int count; |
| 764 | for (count = 0; COND(c[D_EDE3_DES][testnum]); count++) |
| 765 | DES_ede3_cbc_encrypt(buf, buf, lengths[testnum], |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 766 | &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 767 | return count; |
| 768 | } |
| 769 | #endif |
| 770 | |
Matt Caswell | 5158c76 | 2016-04-13 11:28:45 +0100 | [diff] [blame] | 771 | #define MAX_BLOCK_SIZE 128 |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 772 | |
| 773 | static unsigned char iv[2 * MAX_BLOCK_SIZE / 8]; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 774 | static AES_KEY aes_ks1, aes_ks2, aes_ks3; |
| 775 | static int AES_cbc_128_encrypt_loop(void *args) |
| 776 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 777 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 778 | unsigned char *buf = tempargs->buf; |
| 779 | int count; |
| 780 | for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++) |
| 781 | AES_cbc_encrypt(buf, buf, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 782 | (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 783 | return count; |
| 784 | } |
| 785 | |
| 786 | static int AES_cbc_192_encrypt_loop(void *args) |
| 787 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 788 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 789 | unsigned char *buf = tempargs->buf; |
| 790 | int count; |
| 791 | for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++) |
| 792 | AES_cbc_encrypt(buf, buf, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 793 | (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 794 | return count; |
| 795 | } |
| 796 | |
| 797 | static int AES_cbc_256_encrypt_loop(void *args) |
| 798 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 799 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 800 | unsigned char *buf = tempargs->buf; |
| 801 | int count; |
| 802 | for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++) |
| 803 | AES_cbc_encrypt(buf, buf, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 804 | (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 805 | return count; |
| 806 | } |
| 807 | |
| 808 | static int AES_ige_128_encrypt_loop(void *args) |
| 809 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 810 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 811 | unsigned char *buf = tempargs->buf; |
| 812 | unsigned char *buf2 = tempargs->buf2; |
| 813 | int count; |
| 814 | for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++) |
| 815 | AES_ige_encrypt(buf, buf2, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 816 | (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 817 | return count; |
| 818 | } |
| 819 | |
| 820 | static int AES_ige_192_encrypt_loop(void *args) |
| 821 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 822 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 823 | unsigned char *buf = tempargs->buf; |
| 824 | unsigned char *buf2 = tempargs->buf2; |
| 825 | int count; |
| 826 | for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++) |
| 827 | AES_ige_encrypt(buf, buf2, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 828 | (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 829 | return count; |
| 830 | } |
| 831 | |
| 832 | static int AES_ige_256_encrypt_loop(void *args) |
| 833 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 834 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 835 | unsigned char *buf = tempargs->buf; |
| 836 | unsigned char *buf2 = tempargs->buf2; |
| 837 | int count; |
| 838 | for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++) |
| 839 | AES_ige_encrypt(buf, buf2, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 840 | (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 841 | return count; |
| 842 | } |
| 843 | |
| 844 | static int CRYPTO_gcm128_aad_loop(void *args) |
| 845 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 846 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 847 | unsigned char *buf = tempargs->buf; |
| 848 | GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx; |
| 849 | int count; |
| 850 | for (count = 0; COND(c[D_GHASH][testnum]); count++) |
| 851 | CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]); |
| 852 | return count; |
| 853 | } |
| 854 | |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 855 | static long save_count = 0; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 856 | static int decrypt = 0; |
| 857 | static int EVP_Update_loop(void *args) |
| 858 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 859 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 860 | unsigned char *buf = tempargs->buf; |
| 861 | EVP_CIPHER_CTX *ctx = tempargs->ctx; |
| 862 | int outl, count; |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 863 | #ifndef SIGALRM |
| 864 | int nb_iter = save_count * 4 * lengths[0] / lengths[testnum]; |
| 865 | #endif |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 866 | if (decrypt) |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 867 | for (count = 0; COND(nb_iter); count++) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 868 | EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); |
| 869 | else |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 870 | for (count = 0; COND(nb_iter); count++) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 871 | EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); |
| 872 | if (decrypt) |
| 873 | EVP_DecryptFinal_ex(ctx, buf, &outl); |
| 874 | else |
| 875 | EVP_EncryptFinal_ex(ctx, buf, &outl); |
| 876 | return count; |
| 877 | } |
| 878 | |
| 879 | static const EVP_MD *evp_md = NULL; |
| 880 | static int EVP_Digest_loop(void *args) |
| 881 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 882 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 883 | unsigned char *buf = tempargs->buf; |
| 884 | unsigned char md[EVP_MAX_MD_SIZE]; |
| 885 | int count; |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 886 | #ifndef SIGALRM |
| 887 | int nb_iter = save_count * 4 * lengths[0] / lengths[testnum]; |
| 888 | #endif |
| 889 | |
| 890 | for (count = 0; COND(nb_iter); count++) { |
| 891 | if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL)) |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 892 | return -1; |
| 893 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 894 | return count; |
| 895 | } |
| 896 | |
| 897 | #ifndef OPENSSL_NO_RSA |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 898 | static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 899 | |
| 900 | static int RSA_sign_loop(void *args) |
| 901 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 902 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 903 | unsigned char *buf = tempargs->buf; |
| 904 | unsigned char *buf2 = tempargs->buf2; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 905 | unsigned int *rsa_num = &tempargs->siglen; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 906 | RSA **rsa_key = tempargs->rsa_key; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 907 | int ret, count; |
| 908 | for (count = 0; COND(rsa_c[testnum][0]); count++) { |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 909 | ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 910 | if (ret == 0) { |
| 911 | BIO_printf(bio_err, "RSA sign failure\n"); |
| 912 | ERR_print_errors(bio_err); |
| 913 | count = -1; |
| 914 | break; |
| 915 | } |
| 916 | } |
| 917 | return count; |
| 918 | } |
| 919 | |
| 920 | static int RSA_verify_loop(void *args) |
| 921 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 922 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 923 | unsigned char *buf = tempargs->buf; |
| 924 | unsigned char *buf2 = tempargs->buf2; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 925 | unsigned int rsa_num = tempargs->siglen; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 926 | RSA **rsa_key = tempargs->rsa_key; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 927 | int ret, count; |
| 928 | for (count = 0; COND(rsa_c[testnum][1]); count++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 929 | ret = |
| 930 | RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 931 | if (ret <= 0) { |
| 932 | BIO_printf(bio_err, "RSA verify failure\n"); |
| 933 | ERR_print_errors(bio_err); |
| 934 | count = -1; |
| 935 | break; |
| 936 | } |
| 937 | } |
| 938 | return count; |
| 939 | } |
| 940 | #endif |
| 941 | |
| 942 | #ifndef OPENSSL_NO_DSA |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 943 | static long dsa_c[DSA_NUM][2]; |
| 944 | static int DSA_sign_loop(void *args) |
| 945 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 946 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 947 | unsigned char *buf = tempargs->buf; |
| 948 | unsigned char *buf2 = tempargs->buf2; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 949 | DSA **dsa_key = tempargs->dsa_key; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 950 | unsigned int *siglen = &tempargs->siglen; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 951 | int ret, count; |
| 952 | for (count = 0; COND(dsa_c[testnum][0]); count++) { |
| 953 | ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]); |
| 954 | if (ret == 0) { |
| 955 | BIO_printf(bio_err, "DSA sign failure\n"); |
| 956 | ERR_print_errors(bio_err); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 957 | count = -1; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 958 | break; |
| 959 | } |
| 960 | } |
| 961 | return count; |
| 962 | } |
| 963 | |
| 964 | static int DSA_verify_loop(void *args) |
| 965 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 966 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 967 | unsigned char *buf = tempargs->buf; |
| 968 | unsigned char *buf2 = tempargs->buf2; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 969 | DSA **dsa_key = tempargs->dsa_key; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 970 | unsigned int siglen = tempargs->siglen; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 971 | int ret, count; |
| 972 | for (count = 0; COND(dsa_c[testnum][1]); count++) { |
| 973 | ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]); |
| 974 | if (ret <= 0) { |
| 975 | BIO_printf(bio_err, "DSA verify failure\n"); |
| 976 | ERR_print_errors(bio_err); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 977 | count = -1; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 978 | break; |
| 979 | } |
| 980 | } |
| 981 | return count; |
| 982 | } |
| 983 | #endif |
| 984 | |
| 985 | #ifndef OPENSSL_NO_EC |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 986 | static long ecdsa_c[EC_NUM][2]; |
| 987 | static int ECDSA_sign_loop(void *args) |
| 988 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 989 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 990 | unsigned char *buf = tempargs->buf; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 991 | EC_KEY **ecdsa = tempargs->ecdsa; |
| 992 | unsigned char *ecdsasig = tempargs->buf2; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 993 | unsigned int *ecdsasiglen = &tempargs->siglen; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 994 | int ret, count; |
| 995 | for (count = 0; COND(ecdsa_c[testnum][0]); count++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 996 | ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 997 | if (ret == 0) { |
| 998 | BIO_printf(bio_err, "ECDSA sign failure\n"); |
| 999 | ERR_print_errors(bio_err); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1000 | count = -1; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | } |
| 1003 | } |
| 1004 | return count; |
| 1005 | } |
| 1006 | |
| 1007 | static int ECDSA_verify_loop(void *args) |
| 1008 | { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1009 | loopargs_t *tempargs = *(loopargs_t **) args; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1010 | unsigned char *buf = tempargs->buf; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1011 | EC_KEY **ecdsa = tempargs->ecdsa; |
| 1012 | unsigned char *ecdsasig = tempargs->buf2; |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 1013 | unsigned int ecdsasiglen = tempargs->siglen; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1014 | int ret, count; |
| 1015 | for (count = 0; COND(ecdsa_c[testnum][1]); count++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1016 | ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1017 | if (ret != 1) { |
| 1018 | BIO_printf(bio_err, "ECDSA verify failure\n"); |
| 1019 | ERR_print_errors(bio_err); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1020 | count = -1; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1021 | break; |
| 1022 | } |
| 1023 | } |
| 1024 | return count; |
| 1025 | } |
| 1026 | |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 1027 | /* ******************************************************************** */ |
FdaSilvaYY | c5baa26 | 2016-07-20 00:16:45 +0200 | [diff] [blame] | 1028 | static long ecdh_c[EC_NUM][1]; |
| 1029 | |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 1030 | static int ECDH_EVP_derive_key_loop(void *args) |
| 1031 | { |
| 1032 | loopargs_t *tempargs = *(loopargs_t **) args; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 1033 | EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum]; |
| 1034 | unsigned char *derived_secret = tempargs->secret_a; |
Cristian Stoica | 358558e | 2016-08-02 12:20:45 +0300 | [diff] [blame] | 1035 | int count; |
Nicola Tuveri | cc98e63 | 2016-10-04 09:17:11 +0300 | [diff] [blame] | 1036 | size_t *outlen = &(tempargs->outlen[testnum]); |
FdaSilvaYY | 3331e43 | 2016-07-12 23:13:20 +0200 | [diff] [blame] | 1037 | |
Nicola Tuveri | db1dd93 | 2016-10-04 15:56:49 +0300 | [diff] [blame] | 1038 | for (count = 0; COND(ecdh_c[testnum][0]); count++) |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 1039 | EVP_PKEY_derive(ctx, derived_secret, outlen); |
| 1040 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1041 | return count; |
| 1042 | } |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 1043 | |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 1044 | #endif /* OPENSSL_NO_EC */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1045 | |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1046 | static int run_benchmark(int async_jobs, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1047 | int (*loop_function) (void *), loopargs_t * loopargs) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1048 | { |
| 1049 | int job_op_count = 0; |
| 1050 | int total_op_count = 0; |
| 1051 | int num_inprogress = 0; |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1052 | int error = 0, i = 0, ret = 0; |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1053 | OSSL_ASYNC_FD job_fd = 0; |
| 1054 | size_t num_job_fds = 0; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1055 | |
| 1056 | run = 1; |
| 1057 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1058 | if (async_jobs == 0) { |
FdaSilvaYY | fb2141c | 2016-08-18 00:51:20 +0200 | [diff] [blame] | 1059 | return loop_function((void *)&loopargs); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | for (i = 0; i < async_jobs && !error; i++) { |
FdaSilvaYY | fb2141c | 2016-08-18 00:51:20 +0200 | [diff] [blame] | 1063 | loopargs_t *looparg_item = loopargs + i; |
| 1064 | |
| 1065 | /* Copy pointer content (looparg_t item address) into async context */ |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1066 | ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx, |
| 1067 | &job_op_count, loop_function, |
FdaSilvaYY | fb2141c | 2016-08-18 00:51:20 +0200 | [diff] [blame] | 1068 | (void *)&looparg_item, sizeof(looparg_item)); |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1069 | switch (ret) { |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1070 | case ASYNC_PAUSE: |
| 1071 | ++num_inprogress; |
| 1072 | break; |
| 1073 | case ASYNC_FINISH: |
| 1074 | if (job_op_count == -1) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1075 | error = 1; |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1076 | } else { |
| 1077 | total_op_count += job_op_count; |
| 1078 | } |
| 1079 | break; |
| 1080 | case ASYNC_NO_JOBS: |
| 1081 | case ASYNC_ERR: |
| 1082 | BIO_printf(bio_err, "Failure in the job\n"); |
| 1083 | ERR_print_errors(bio_err); |
| 1084 | error = 1; |
| 1085 | break; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1089 | while (num_inprogress > 0) { |
Andrea Grandi | 2ea9260 | 2016-03-08 04:51:04 +0000 | [diff] [blame] | 1090 | #if defined(OPENSSL_SYS_WINDOWS) |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1091 | DWORD avail = 0; |
Andrea Grandi | 2ea9260 | 2016-03-08 04:51:04 +0000 | [diff] [blame] | 1092 | #elif defined(OPENSSL_SYS_UNIX) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1093 | int select_result = 0; |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1094 | OSSL_ASYNC_FD max_fd = 0; |
| 1095 | fd_set waitfdset; |
Andrea Grandi | 363a1fc | 2016-03-07 11:20:01 +0000 | [diff] [blame] | 1096 | |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1097 | FD_ZERO(&waitfdset); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1098 | |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1099 | for (i = 0; i < async_jobs && num_inprogress > 0; i++) { |
| 1100 | if (loopargs[i].inprogress_job == NULL) |
| 1101 | continue; |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1102 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1103 | if (!ASYNC_WAIT_CTX_get_all_fds |
| 1104 | (loopargs[i].wait_ctx, NULL, &num_job_fds) |
| 1105 | || num_job_fds > 1) { |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1106 | BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); |
| 1107 | ERR_print_errors(bio_err); |
| 1108 | error = 1; |
| 1109 | break; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1110 | } |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1111 | ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, |
| 1112 | &num_job_fds); |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1113 | FD_SET(job_fd, &waitfdset); |
| 1114 | if (job_fd > max_fd) |
| 1115 | max_fd = job_fd; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1116 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1117 | |
Ben Laurie | 402ec2f | 2016-04-15 09:45:25 +0100 | [diff] [blame] | 1118 | if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) { |
Andrea Grandi | 570c071 | 2016-03-25 04:19:30 +0000 | [diff] [blame] | 1119 | BIO_printf(bio_err, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1120 | "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). " |
| 1121 | "Decrease the value of async_jobs\n", |
| 1122 | max_fd, FD_SETSIZE); |
Andrea Grandi | 570c071 | 2016-03-25 04:19:30 +0000 | [diff] [blame] | 1123 | ERR_print_errors(bio_err); |
| 1124 | error = 1; |
| 1125 | break; |
| 1126 | } |
| 1127 | |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1128 | select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1129 | if (select_result == -1 && errno == EINTR) |
| 1130 | continue; |
| 1131 | |
| 1132 | if (select_result == -1) { |
Andrea Grandi | 564e102 | 2016-03-03 07:09:00 +0000 | [diff] [blame] | 1133 | BIO_printf(bio_err, "Failure in the select\n"); |
| 1134 | ERR_print_errors(bio_err); |
| 1135 | error = 1; |
| 1136 | break; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | if (select_result == 0) |
| 1140 | continue; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1141 | #endif |
| 1142 | |
| 1143 | for (i = 0; i < async_jobs; i++) { |
| 1144 | if (loopargs[i].inprogress_job == NULL) |
| 1145 | continue; |
| 1146 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1147 | if (!ASYNC_WAIT_CTX_get_all_fds |
| 1148 | (loopargs[i].wait_ctx, NULL, &num_job_fds) |
| 1149 | || num_job_fds > 1) { |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1150 | BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); |
| 1151 | ERR_print_errors(bio_err); |
| 1152 | error = 1; |
| 1153 | break; |
| 1154 | } |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1155 | ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, |
| 1156 | &num_job_fds); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1157 | |
Matt Caswell | 667867c | 2016-03-07 16:55:39 +0000 | [diff] [blame] | 1158 | #if defined(OPENSSL_SYS_UNIX) |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1159 | if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset)) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1160 | continue; |
Matt Caswell | 667867c | 2016-03-07 16:55:39 +0000 | [diff] [blame] | 1161 | #elif defined(OPENSSL_SYS_WINDOWS) |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1162 | if (num_job_fds == 1 |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1163 | && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1164 | && avail > 0) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1165 | continue; |
| 1166 | #endif |
| 1167 | |
David Benjamin | 609b085 | 2016-10-10 12:01:24 -0400 | [diff] [blame] | 1168 | ret = ASYNC_start_job(&loopargs[i].inprogress_job, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1169 | loopargs[i].wait_ctx, &job_op_count, |
| 1170 | loop_function, (void *)(loopargs + i), |
| 1171 | sizeof(loopargs_t)); |
FdaSilvaYY | 700b814 | 2016-07-28 21:15:52 +0200 | [diff] [blame] | 1172 | switch (ret) { |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1173 | case ASYNC_PAUSE: |
| 1174 | break; |
| 1175 | case ASYNC_FINISH: |
| 1176 | if (job_op_count == -1) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1177 | error = 1; |
FdaSilvaYY | fd4b0c0 | 2016-07-28 22:51:18 +0200 | [diff] [blame] | 1178 | } else { |
| 1179 | total_op_count += job_op_count; |
| 1180 | } |
| 1181 | --num_inprogress; |
| 1182 | loopargs[i].inprogress_job = NULL; |
| 1183 | break; |
| 1184 | case ASYNC_NO_JOBS: |
| 1185 | case ASYNC_ERR: |
| 1186 | --num_inprogress; |
| 1187 | loopargs[i].inprogress_job = NULL; |
| 1188 | BIO_printf(bio_err, "Failure in the job\n"); |
| 1189 | ERR_print_errors(bio_err); |
| 1190 | error = 1; |
| 1191 | break; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | return error ? -1 : total_op_count; |
| 1197 | } |
| 1198 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1199 | int speed_main(int argc, char **argv) |
| 1200 | { |
Richard Levitte | dd1abd4 | 2016-09-28 23:39:18 +0200 | [diff] [blame] | 1201 | ENGINE *e = NULL; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1202 | loopargs_t *loopargs = NULL; |
Cristian Stoica | dab1f5f | 2016-05-17 18:40:14 +0300 | [diff] [blame] | 1203 | int async_init = 0; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1204 | int loopargs_len = 0; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1205 | char *prog; |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 1206 | const char *engine_id = NULL; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1207 | const EVP_CIPHER *evp_cipher = NULL; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1208 | double d = 0.0; |
| 1209 | OPTION_CHOICE o; |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1210 | int multiblock = 0, pr_header = 0; |
| 1211 | int doit[ALGOR_NUM] = { 0 }; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1212 | int ret = 1, i, k, misalign = 0; |
FdaSilvaYY | 19075d5 | 2016-07-23 14:26:07 +0200 | [diff] [blame] | 1213 | long count = 0; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1214 | #ifndef NO_FORK |
| 1215 | int multi = 0; |
| 1216 | #endif |
Bernd Edlinger | f8aa157 | 2017-02-21 06:58:04 +0100 | [diff] [blame] | 1217 | unsigned int async_jobs = 0; |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 1218 | #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \ |
| 1219 | || !defined(OPENSSL_NO_EC) |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1220 | long rsa_count = 1; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1221 | #endif |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 1222 | |
| 1223 | /* What follows are the buffers and key material. */ |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1224 | #ifndef OPENSSL_NO_RC5 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1225 | RC5_32_KEY rc5_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1226 | #endif |
| 1227 | #ifndef OPENSSL_NO_RC2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1228 | RC2_KEY rc2_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1229 | #endif |
| 1230 | #ifndef OPENSSL_NO_IDEA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1231 | IDEA_KEY_SCHEDULE idea_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1232 | #endif |
| 1233 | #ifndef OPENSSL_NO_SEED |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1234 | SEED_KEY_SCHEDULE seed_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1235 | #endif |
| 1236 | #ifndef OPENSSL_NO_BF |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1237 | BF_KEY bf_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1238 | #endif |
| 1239 | #ifndef OPENSSL_NO_CAST |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1240 | CAST_KEY cast_ks; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1241 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1242 | static const unsigned char key16[16] = { |
| 1243 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, |
| 1244 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 |
| 1245 | }; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1246 | static const unsigned char key24[24] = { |
| 1247 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, |
| 1248 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, |
| 1249 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 |
| 1250 | }; |
| 1251 | static const unsigned char key32[32] = { |
| 1252 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, |
| 1253 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, |
| 1254 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, |
| 1255 | 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 |
| 1256 | }; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1257 | #ifndef OPENSSL_NO_CAMELLIA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1258 | static const unsigned char ckey24[24] = { |
| 1259 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, |
| 1260 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, |
| 1261 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 |
| 1262 | }; |
| 1263 | static const unsigned char ckey32[32] = { |
| 1264 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, |
| 1265 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, |
| 1266 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, |
| 1267 | 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 |
| 1268 | }; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1269 | CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1270 | #endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1271 | #ifndef OPENSSL_NO_DES |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1272 | static DES_cblock key = { |
| 1273 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 |
| 1274 | }; |
| 1275 | static DES_cblock key2 = { |
| 1276 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 |
| 1277 | }; |
| 1278 | static DES_cblock key3 = { |
| 1279 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 |
| 1280 | }; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1281 | #endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1282 | #ifndef OPENSSL_NO_RSA |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1283 | static const unsigned int rsa_bits[RSA_NUM] = { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1284 | 512, 1024, 2048, 3072, 4096, 7680, 15360 |
| 1285 | }; |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1286 | static const unsigned char *rsa_data[RSA_NUM] = { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1287 | test512, test1024, test2048, test3072, test4096, test7680, test15360 |
| 1288 | }; |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1289 | static const int rsa_data_length[RSA_NUM] = { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1290 | sizeof(test512), sizeof(test1024), |
| 1291 | sizeof(test2048), sizeof(test3072), |
| 1292 | sizeof(test4096), sizeof(test7680), |
| 1293 | sizeof(test15360) |
| 1294 | }; |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 1295 | int rsa_doit[RSA_NUM] = { 0 }; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1296 | #endif |
| 1297 | #ifndef OPENSSL_NO_DSA |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1298 | static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 }; |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 1299 | int dsa_doit[DSA_NUM] = { 0 }; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1300 | #endif |
| 1301 | #ifndef OPENSSL_NO_EC |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1302 | /* |
| 1303 | * We only test over the following curves as they are representative, To |
| 1304 | * add tests over more curves, simply add the curve NID and curve name to |
| 1305 | * the following arrays and increase the EC_NUM value accordingly. |
| 1306 | */ |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1307 | static const unsigned int test_curves[EC_NUM] = { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1308 | /* Prime Curves */ |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1309 | NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1, |
| 1310 | NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1311 | /* Binary Curves */ |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1312 | NID_sect163k1, NID_sect233k1, NID_sect283k1, |
| 1313 | NID_sect409k1, NID_sect571k1, NID_sect163r2, |
| 1314 | NID_sect233r1, NID_sect283r1, NID_sect409r1, |
Dr. Stephen Henson | db50c1d | 2016-02-12 14:11:47 +0000 | [diff] [blame] | 1315 | NID_sect571r1, |
| 1316 | /* Other */ |
| 1317 | NID_X25519 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | static const char *test_curves_names[EC_NUM] = { |
| 1320 | /* Prime Curves */ |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1321 | "secp160r1", "nistp192", "nistp224", |
| 1322 | "nistp256", "nistp384", "nistp521", |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1323 | /* Binary Curves */ |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1324 | "nistk163", "nistk233", "nistk283", |
| 1325 | "nistk409", "nistk571", "nistb163", |
| 1326 | "nistb233", "nistb283", "nistb409", |
Dr. Stephen Henson | db50c1d | 2016-02-12 14:11:47 +0000 | [diff] [blame] | 1327 | "nistb571", |
| 1328 | /* Other */ |
| 1329 | "X25519" |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1330 | }; |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1331 | static const int test_curves_bits[EC_NUM] = { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1332 | 160, 192, 224, |
| 1333 | 256, 384, 521, |
| 1334 | 163, 233, 283, |
| 1335 | 409, 571, 163, |
| 1336 | 233, 283, 409, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1337 | 571, 253 /* X25519 */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1338 | }; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1339 | |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 1340 | int ecdsa_doit[EC_NUM] = { 0 }; |
| 1341 | int ecdh_doit[EC_NUM] = { 0 }; |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 1342 | #endif /* ndef OPENSSL_NO_EC */ |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1343 | |
| 1344 | prog = opt_init(argc, argv, speed_options); |
| 1345 | while ((o = opt_next()) != OPT_EOF) { |
| 1346 | switch (o) { |
| 1347 | case OPT_EOF: |
| 1348 | case OPT_ERR: |
| 1349 | opterr: |
| 1350 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); |
| 1351 | goto end; |
| 1352 | case OPT_HELP: |
| 1353 | opt_help(speed_options); |
| 1354 | ret = 0; |
| 1355 | goto end; |
| 1356 | case OPT_ELAPSED: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1357 | usertime = 0; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1358 | break; |
| 1359 | case OPT_EVP: |
| 1360 | evp_cipher = EVP_get_cipherbyname(opt_arg()); |
| 1361 | if (evp_cipher == NULL) |
| 1362 | evp_md = EVP_get_digestbyname(opt_arg()); |
| 1363 | if (evp_cipher == NULL && evp_md == NULL) { |
| 1364 | BIO_printf(bio_err, |
FdaSilvaYY | 55b09fe | 2016-07-23 15:39:49 +0200 | [diff] [blame] | 1365 | "%s: %s is an unknown cipher or digest\n", |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1366 | prog, opt_arg()); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1367 | goto end; |
| 1368 | } |
| 1369 | doit[D_EVP] = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1370 | break; |
| 1371 | case OPT_DECRYPT: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1372 | decrypt = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1373 | break; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1374 | case OPT_ENGINE: |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1375 | /* |
| 1376 | * In a forked execution, an engine might need to be |
| 1377 | * initialised by each child process, not by the parent. |
| 1378 | * So store the name here and run setup_engine() later on. |
| 1379 | */ |
| 1380 | engine_id = opt_arg(); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1381 | break; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1382 | case OPT_MULTI: |
Rich Salz | 9c3bcfa | 2015-05-15 13:50:38 -0400 | [diff] [blame] | 1383 | #ifndef NO_FORK |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1384 | multi = atoi(opt_arg()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1385 | #endif |
Rich Salz | 9c3bcfa | 2015-05-15 13:50:38 -0400 | [diff] [blame] | 1386 | break; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1387 | case OPT_ASYNCJOBS: |
Matt Caswell | 667867c | 2016-03-07 16:55:39 +0000 | [diff] [blame] | 1388 | #ifndef OPENSSL_NO_ASYNC |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1389 | async_jobs = atoi(opt_arg()); |
Matt Caswell | 667867c | 2016-03-07 16:55:39 +0000 | [diff] [blame] | 1390 | if (!ASYNC_is_capable()) { |
| 1391 | BIO_printf(bio_err, |
| 1392 | "%s: async_jobs specified but async not supported\n", |
| 1393 | prog); |
| 1394 | goto opterr; |
| 1395 | } |
Bernd Edlinger | f8aa157 | 2017-02-21 06:58:04 +0100 | [diff] [blame] | 1396 | if (async_jobs > 99999) { |
| 1397 | BIO_printf(bio_err, |
| 1398 | "%s: too many async_jobs\n", |
| 1399 | prog); |
| 1400 | goto opterr; |
| 1401 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1402 | #endif |
| 1403 | break; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1404 | case OPT_MISALIGN: |
| 1405 | if (!opt_int(opt_arg(), &misalign)) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1406 | goto end; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1407 | if (misalign > MISALIGN) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1408 | BIO_printf(bio_err, |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1409 | "%s: Maximum offset is %d\n", prog, MISALIGN); |
| 1410 | goto opterr; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1411 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1412 | break; |
| 1413 | case OPT_MR: |
| 1414 | mr = 1; |
| 1415 | break; |
| 1416 | case OPT_MB: |
| 1417 | multiblock = 1; |
FdaSilvaYY | cfd451d | 2016-08-04 00:23:39 +0200 | [diff] [blame] | 1418 | #ifdef OPENSSL_NO_MULTIBLOCK |
| 1419 | BIO_printf(bio_err, |
| 1420 | "%s: -mb specified but multi-block support is disabled\n", |
| 1421 | prog); |
| 1422 | goto end; |
| 1423 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1424 | break; |
| 1425 | } |
| 1426 | } |
| 1427 | argc = opt_num_rest(); |
| 1428 | argv = opt_rest(); |
| 1429 | |
| 1430 | /* Remaining arguments are algorithms. */ |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1431 | for (; *argv; argv++) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1432 | if (found(*argv, doit_choices, &i)) { |
| 1433 | doit[i] = 1; |
| 1434 | continue; |
| 1435 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1436 | #ifndef OPENSSL_NO_DES |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1437 | if (strcmp(*argv, "des") == 0) { |
| 1438 | doit[D_CBC_DES] = doit[D_EDE3_DES] = 1; |
| 1439 | continue; |
| 1440 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1441 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1442 | if (strcmp(*argv, "sha") == 0) { |
| 1443 | doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1; |
| 1444 | continue; |
| 1445 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1446 | #ifndef OPENSSL_NO_RSA |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1447 | # ifndef RSA_NULL |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1448 | if (strcmp(*argv, "openssl") == 0) { |
Rich Salz | b0700d2 | 2015-10-27 15:11:48 -0400 | [diff] [blame] | 1449 | RSA_set_default_method(RSA_PKCS1_OpenSSL()); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1450 | continue; |
| 1451 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1452 | # endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1453 | if (strcmp(*argv, "rsa") == 0) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1454 | rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] = |
| 1455 | rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] = |
| 1456 | rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] = |
| 1457 | rsa_doit[R_RSA_15360] = 1; |
| 1458 | continue; |
| 1459 | } |
| 1460 | if (found(*argv, rsa_choices, &i)) { |
| 1461 | rsa_doit[i] = 1; |
| 1462 | continue; |
| 1463 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1464 | #endif |
| 1465 | #ifndef OPENSSL_NO_DSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1466 | if (strcmp(*argv, "dsa") == 0) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1467 | dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] = |
| 1468 | dsa_doit[R_DSA_2048] = 1; |
| 1469 | continue; |
| 1470 | } |
| 1471 | if (found(*argv, dsa_choices, &i)) { |
| 1472 | dsa_doit[i] = 2; |
| 1473 | continue; |
| 1474 | } |
| 1475 | #endif |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1476 | if (strcmp(*argv, "aes") == 0) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1477 | doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1478 | continue; |
| 1479 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1480 | #ifndef OPENSSL_NO_CAMELLIA |
| 1481 | if (strcmp(*argv, "camellia") == 0) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1482 | doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1483 | continue; |
| 1484 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1485 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 1486 | #ifndef OPENSSL_NO_EC |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1487 | if (strcmp(*argv, "ecdsa") == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1488 | for (i = 0; i < EC_NUM; i++) |
| 1489 | ecdsa_doit[i] = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1490 | continue; |
| 1491 | } |
| 1492 | if (found(*argv, ecdsa_choices, &i)) { |
| 1493 | ecdsa_doit[i] = 2; |
| 1494 | continue; |
| 1495 | } |
| 1496 | if (strcmp(*argv, "ecdh") == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1497 | for (i = 0; i < EC_NUM; i++) |
| 1498 | ecdh_doit[i] = 1; |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1499 | continue; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1500 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1501 | if (found(*argv, ecdh_choices, &i)) { |
| 1502 | ecdh_doit[i] = 2; |
| 1503 | continue; |
| 1504 | } |
| 1505 | #endif |
| 1506 | BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv); |
| 1507 | goto end; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1508 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1509 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1510 | /* Initialize the job pool if async mode is enabled */ |
| 1511 | if (async_jobs > 0) { |
Cristian Stoica | dab1f5f | 2016-05-17 18:40:14 +0300 | [diff] [blame] | 1512 | async_init = ASYNC_init_thread(async_jobs, async_jobs); |
| 1513 | if (!async_init) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1514 | BIO_printf(bio_err, "Error creating the ASYNC job pool\n"); |
| 1515 | goto end; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | loopargs_len = (async_jobs == 0 ? 1 : async_jobs); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1520 | loopargs = |
| 1521 | app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs"); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1522 | memset(loopargs, 0, loopargs_len * sizeof(loopargs_t)); |
| 1523 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1524 | for (i = 0; i < loopargs_len; i++) { |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 1525 | if (async_jobs > 0) { |
| 1526 | loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new(); |
| 1527 | if (loopargs[i].wait_ctx == NULL) { |
| 1528 | BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n"); |
| 1529 | goto end; |
| 1530 | } |
| 1531 | } |
| 1532 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1533 | loopargs[i].buf_malloc = |
| 1534 | app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer"); |
| 1535 | loopargs[i].buf2_malloc = |
| 1536 | app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer"); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1537 | /* Align the start of buffers on a 64 byte boundary */ |
| 1538 | loopargs[i].buf = loopargs[i].buf_malloc + misalign; |
| 1539 | loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1540 | #ifndef OPENSSL_NO_EC |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1541 | loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a"); |
| 1542 | loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b"); |
| 1543 | #endif |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1546 | #ifndef NO_FORK |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1547 | if (multi && do_multi(multi)) |
| 1548 | goto show_res; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1549 | #endif |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 1550 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1551 | /* Initialize the engine after the fork */ |
Richard Levitte | dd1abd4 | 2016-09-28 23:39:18 +0200 | [diff] [blame] | 1552 | e = setup_engine(engine_id, 0); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1553 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1554 | /* No parameters; turn on everything. */ |
Tim Hudson | dfba17b | 2015-08-17 22:20:06 +1000 | [diff] [blame] | 1555 | if ((argc == 0) && !doit[D_EVP]) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1556 | for (i = 0; i < ALGOR_NUM; i++) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1557 | if (i != D_EVP) |
| 1558 | doit[i] = 1; |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 1559 | #ifndef OPENSSL_NO_RSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1560 | for (i = 0; i < RSA_NUM; i++) |
| 1561 | rsa_doit[i] = 1; |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 1562 | #endif |
Matt Caswell | 83ae812 | 2016-03-18 17:43:58 +0000 | [diff] [blame] | 1563 | #ifndef OPENSSL_NO_DSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1564 | for (i = 0; i < DSA_NUM; i++) |
| 1565 | dsa_doit[i] = 1; |
Matt Caswell | 83ae812 | 2016-03-18 17:43:58 +0000 | [diff] [blame] | 1566 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 1567 | #ifndef OPENSSL_NO_EC |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1568 | for (i = 0; i < EC_NUM; i++) |
| 1569 | ecdsa_doit[i] = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1570 | for (i = 0; i < EC_NUM; i++) |
| 1571 | ecdh_doit[i] = 1; |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1572 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1573 | } |
| 1574 | for (i = 0; i < ALGOR_NUM; i++) |
| 1575 | if (doit[i]) |
| 1576 | pr_header++; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1577 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1578 | if (usertime == 0 && !mr) |
| 1579 | BIO_printf(bio_err, |
| 1580 | "You have chosen to measure elapsed time " |
| 1581 | "instead of user CPU time.\n"); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1582 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1583 | #ifndef OPENSSL_NO_RSA |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1584 | for (i = 0; i < loopargs_len; i++) { |
| 1585 | for (k = 0; k < RSA_NUM; k++) { |
| 1586 | const unsigned char *p; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1587 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1588 | p = rsa_data[k]; |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1589 | loopargs[i].rsa_key[k] = |
| 1590 | d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1591 | if (loopargs[i].rsa_key[k] == NULL) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1592 | BIO_printf(bio_err, |
| 1593 | "internal error loading RSA key number %d\n", k); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1594 | goto end; |
| 1595 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1596 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1597 | } |
| 1598 | #endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1599 | #ifndef OPENSSL_NO_DSA |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1600 | for (i = 0; i < loopargs_len; i++) { |
| 1601 | loopargs[i].dsa_key[0] = get_dsa512(); |
| 1602 | loopargs[i].dsa_key[1] = get_dsa1024(); |
| 1603 | loopargs[i].dsa_key[2] = get_dsa2048(); |
| 1604 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1605 | #endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1606 | #ifndef OPENSSL_NO_DES |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1607 | DES_set_key_unchecked(&key, &sch); |
| 1608 | DES_set_key_unchecked(&key2, &sch2); |
| 1609 | DES_set_key_unchecked(&key3, &sch3); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1610 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1611 | AES_set_encrypt_key(key16, 128, &aes_ks1); |
| 1612 | AES_set_encrypt_key(key24, 192, &aes_ks2); |
| 1613 | AES_set_encrypt_key(key32, 256, &aes_ks3); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1614 | #ifndef OPENSSL_NO_CAMELLIA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1615 | Camellia_set_key(key16, 128, &camellia_ks1); |
| 1616 | Camellia_set_key(ckey24, 192, &camellia_ks2); |
| 1617 | Camellia_set_key(ckey32, 256, &camellia_ks3); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1618 | #endif |
| 1619 | #ifndef OPENSSL_NO_IDEA |
Rich Salz | 9021a5d | 2016-04-18 07:43:54 -0400 | [diff] [blame] | 1620 | IDEA_set_encrypt_key(key16, &idea_ks); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1621 | #endif |
| 1622 | #ifndef OPENSSL_NO_SEED |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1623 | SEED_set_key(key16, &seed_ks); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1624 | #endif |
| 1625 | #ifndef OPENSSL_NO_RC4 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1626 | RC4_set_key(&rc4_ks, 16, key16); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1627 | #endif |
| 1628 | #ifndef OPENSSL_NO_RC2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1629 | RC2_set_key(&rc2_ks, 16, key16, 128); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1630 | #endif |
| 1631 | #ifndef OPENSSL_NO_RC5 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1632 | RC5_32_set_key(&rc5_ks, 16, key16, 12); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1633 | #endif |
| 1634 | #ifndef OPENSSL_NO_BF |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1635 | BF_set_key(&bf_ks, 16, key16); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1636 | #endif |
| 1637 | #ifndef OPENSSL_NO_CAST |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1638 | CAST_set_key(&cast_ks, 16, key16); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1639 | #endif |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1640 | #ifndef SIGALRM |
| 1641 | # ifndef OPENSSL_NO_DES |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1642 | BIO_printf(bio_err, "First we calculate the approximate speed ...\n"); |
| 1643 | count = 10; |
| 1644 | do { |
| 1645 | long it; |
| 1646 | count *= 2; |
| 1647 | Time_F(START); |
| 1648 | for (it = count; it; it--) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1649 | DES_ecb_encrypt((DES_cblock *)loopargs[0].buf, |
| 1650 | (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1651 | d = Time_F(STOP); |
| 1652 | } while (d < 3); |
| 1653 | save_count = count; |
| 1654 | c[D_MD2][0] = count / 10; |
| 1655 | c[D_MDC2][0] = count / 10; |
| 1656 | c[D_MD4][0] = count; |
| 1657 | c[D_MD5][0] = count; |
| 1658 | c[D_HMAC][0] = count; |
| 1659 | c[D_SHA1][0] = count; |
| 1660 | c[D_RMD160][0] = count; |
| 1661 | c[D_RC4][0] = count * 5; |
| 1662 | c[D_CBC_DES][0] = count; |
| 1663 | c[D_EDE3_DES][0] = count / 3; |
| 1664 | c[D_CBC_IDEA][0] = count; |
| 1665 | c[D_CBC_SEED][0] = count; |
| 1666 | c[D_CBC_RC2][0] = count; |
| 1667 | c[D_CBC_RC5][0] = count; |
| 1668 | c[D_CBC_BF][0] = count; |
| 1669 | c[D_CBC_CAST][0] = count; |
| 1670 | c[D_CBC_128_AES][0] = count; |
| 1671 | c[D_CBC_192_AES][0] = count; |
| 1672 | c[D_CBC_256_AES][0] = count; |
| 1673 | c[D_CBC_128_CML][0] = count; |
| 1674 | c[D_CBC_192_CML][0] = count; |
| 1675 | c[D_CBC_256_CML][0] = count; |
| 1676 | c[D_SHA256][0] = count; |
| 1677 | c[D_SHA512][0] = count; |
| 1678 | c[D_WHIRLPOOL][0] = count; |
| 1679 | c[D_IGE_128_AES][0] = count; |
| 1680 | c[D_IGE_192_AES][0] = count; |
| 1681 | c[D_IGE_256_AES][0] = count; |
| 1682 | c[D_GHASH][0] = count; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1683 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1684 | for (i = 1; i < SIZE_NUM; i++) { |
| 1685 | long l0, l1; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1686 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1687 | l0 = (long)lengths[0]; |
| 1688 | l1 = (long)lengths[i]; |
Felix Laurie von Massenbach | 8c9336c | 2014-05-26 21:58:55 +0100 | [diff] [blame] | 1689 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1690 | c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1; |
| 1691 | c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1; |
| 1692 | c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1; |
| 1693 | c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1; |
| 1694 | c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1; |
| 1695 | c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1; |
| 1696 | c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1; |
| 1697 | c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1; |
| 1698 | c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1; |
| 1699 | c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1; |
Andy Polyakov | 6d9843e | 2016-02-12 14:53:51 +0100 | [diff] [blame] | 1700 | c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1; |
Matt Caswell | dd703de | 2014-11-24 10:05:04 +0000 | [diff] [blame] | 1701 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1702 | l0 = (long)lengths[i - 1]; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1703 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1704 | c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1; |
| 1705 | c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1; |
| 1706 | c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1; |
| 1707 | c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1; |
| 1708 | c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1; |
| 1709 | c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1; |
| 1710 | c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1; |
| 1711 | c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1; |
| 1712 | c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1; |
| 1713 | c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1; |
| 1714 | c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1; |
| 1715 | c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1; |
| 1716 | c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1; |
| 1717 | c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1; |
| 1718 | c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1; |
| 1719 | c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1; |
| 1720 | c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1; |
| 1721 | c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1; |
| 1722 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1723 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1724 | # ifndef OPENSSL_NO_RSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1725 | rsa_c[R_RSA_512][0] = count / 2000; |
| 1726 | rsa_c[R_RSA_512][1] = count / 400; |
| 1727 | for (i = 1; i < RSA_NUM; i++) { |
| 1728 | rsa_c[i][0] = rsa_c[i - 1][0] / 8; |
| 1729 | rsa_c[i][1] = rsa_c[i - 1][1] / 4; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1730 | if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1731 | rsa_doit[i] = 0; |
| 1732 | else { |
| 1733 | if (rsa_c[i][0] == 0) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1734 | rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1735 | rsa_c[i][1] = 20; |
| 1736 | } |
| 1737 | } |
| 1738 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1739 | # endif |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 1740 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1741 | # ifndef OPENSSL_NO_DSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1742 | dsa_c[R_DSA_512][0] = count / 1000; |
| 1743 | dsa_c[R_DSA_512][1] = count / 1000 / 2; |
| 1744 | for (i = 1; i < DSA_NUM; i++) { |
| 1745 | dsa_c[i][0] = dsa_c[i - 1][0] / 4; |
| 1746 | dsa_c[i][1] = dsa_c[i - 1][1] / 4; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1747 | if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1748 | dsa_doit[i] = 0; |
| 1749 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1750 | if (dsa_c[i][0] == 0) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1751 | dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1752 | dsa_c[i][1] = 1; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1756 | # endif |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 1757 | |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 1758 | # ifndef OPENSSL_NO_EC |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1759 | ecdsa_c[R_EC_P160][0] = count / 1000; |
| 1760 | ecdsa_c[R_EC_P160][1] = count / 1000 / 2; |
| 1761 | for (i = R_EC_P192; i <= R_EC_P521; i++) { |
| 1762 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; |
| 1763 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1764 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1765 | ecdsa_doit[i] = 0; |
| 1766 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1767 | if (ecdsa_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1768 | ecdsa_c[i][0] = 1; |
| 1769 | ecdsa_c[i][1] = 1; |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | ecdsa_c[R_EC_K163][0] = count / 1000; |
| 1774 | ecdsa_c[R_EC_K163][1] = count / 1000 / 2; |
| 1775 | for (i = R_EC_K233; i <= R_EC_K571; i++) { |
| 1776 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; |
| 1777 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1778 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1779 | ecdsa_doit[i] = 0; |
| 1780 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1781 | if (ecdsa_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1782 | ecdsa_c[i][0] = 1; |
| 1783 | ecdsa_c[i][1] = 1; |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | ecdsa_c[R_EC_B163][0] = count / 1000; |
| 1788 | ecdsa_c[R_EC_B163][1] = count / 1000 / 2; |
| 1789 | for (i = R_EC_B233; i <= R_EC_B571; i++) { |
| 1790 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; |
| 1791 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1792 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1793 | ecdsa_doit[i] = 0; |
| 1794 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1795 | if (ecdsa_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1796 | ecdsa_c[i][0] = 1; |
| 1797 | ecdsa_c[i][1] = 1; |
| 1798 | } |
| 1799 | } |
| 1800 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 1801 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1802 | ecdh_c[R_EC_P160][0] = count / 1000; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1803 | for (i = R_EC_P192; i <= R_EC_P521; i++) { |
| 1804 | ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1805 | if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1806 | ecdh_doit[i] = 0; |
| 1807 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1808 | if (ecdh_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1809 | ecdh_c[i][0] = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | } |
| 1813 | ecdh_c[R_EC_K163][0] = count / 1000; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1814 | for (i = R_EC_K233; i <= R_EC_K571; i++) { |
| 1815 | ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1816 | if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1817 | ecdh_doit[i] = 0; |
| 1818 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1819 | if (ecdh_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1820 | ecdh_c[i][0] = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | ecdh_c[R_EC_B163][0] = count / 1000; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1825 | for (i = R_EC_B233; i <= R_EC_B571; i++) { |
| 1826 | ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1827 | if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1828 | ecdh_doit[i] = 0; |
| 1829 | else { |
FdaSilvaYY | 70c4e15 | 2016-07-23 14:45:08 +0200 | [diff] [blame] | 1830 | if (ecdh_c[i][0] == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1831 | ecdh_c[i][0] = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1835 | # endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1836 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1837 | # else |
| 1838 | /* not worth fixing */ |
| 1839 | # error "You cannot disable DES on systems without SIGALRM." |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1840 | # endif /* OPENSSL_NO_DES */ |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1841 | #else |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1842 | # ifndef _WIN32 |
| 1843 | signal(SIGALRM, sig_done); |
| 1844 | # endif |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1845 | #endif /* SIGALRM */ |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1846 | |
| 1847 | #ifndef OPENSSL_NO_MD2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1848 | if (doit[D_MD2]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1849 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1850 | print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1851 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1852 | count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1853 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1854 | print_result(D_MD2, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1855 | } |
| 1856 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1857 | #endif |
| 1858 | #ifndef OPENSSL_NO_MDC2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1859 | if (doit[D_MDC2]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1860 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1861 | print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1862 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1863 | count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1864 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1865 | print_result(D_MDC2, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1866 | } |
| 1867 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1868 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1869 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1870 | #ifndef OPENSSL_NO_MD4 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1871 | if (doit[D_MD4]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1872 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1873 | print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1874 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1875 | count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1876 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1877 | print_result(D_MD4, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1880 | #endif |
Richard Levitte | 3009458 | 2000-08-14 14:05:53 +0000 | [diff] [blame] | 1881 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1882 | #ifndef OPENSSL_NO_MD5 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1883 | if (doit[D_MD5]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1884 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1885 | print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1886 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1887 | count = run_benchmark(async_jobs, MD5_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1888 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1889 | print_result(D_MD5, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1890 | } |
| 1891 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1892 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1893 | if (doit[D_HMAC]) { |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 1894 | static const char hmac_key[] = "This is a key..."; |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 1895 | int len = strlen(hmac_key); |
| 1896 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1897 | for (i = 0; i < loopargs_len; i++) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1898 | loopargs[i].hctx = HMAC_CTX_new(); |
| 1899 | if (loopargs[i].hctx == NULL) { |
| 1900 | BIO_printf(bio_err, "HMAC malloc failure, exiting..."); |
| 1901 | exit(1); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1902 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1903 | |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 1904 | HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1905 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1906 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1907 | print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]); |
| 1908 | Time_F(START); |
| 1909 | count = run_benchmark(async_jobs, HMAC_loop, loopargs); |
| 1910 | d = Time_F(STOP); |
| 1911 | print_result(D_HMAC, testnum, count, d); |
| 1912 | } |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 1913 | for (i = 0; i < loopargs_len; i++) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1914 | HMAC_CTX_free(loopargs[i].hctx); |
| 1915 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1916 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1917 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1918 | if (doit[D_SHA1]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1919 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1920 | print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1921 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1922 | count = run_benchmark(async_jobs, SHA1_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1923 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1924 | print_result(D_SHA1, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1925 | } |
| 1926 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1927 | if (doit[D_SHA256]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1928 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1929 | print_message(names[D_SHA256], c[D_SHA256][testnum], |
| 1930 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1931 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1932 | count = run_benchmark(async_jobs, SHA256_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1933 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1934 | print_result(D_SHA256, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1935 | } |
| 1936 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1937 | if (doit[D_SHA512]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1938 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1939 | print_message(names[D_SHA512], c[D_SHA512][testnum], |
| 1940 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1941 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1942 | count = run_benchmark(async_jobs, SHA512_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1943 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1944 | print_result(D_SHA512, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1945 | } |
| 1946 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1947 | #ifndef OPENSSL_NO_WHIRLPOOL |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1948 | if (doit[D_WHIRLPOOL]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1949 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1950 | print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], |
| 1951 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1952 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1953 | count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1954 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1955 | print_result(D_WHIRLPOOL, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1956 | } |
| 1957 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1958 | #endif |
Nils Larsch | ae93dc13 | 2006-12-01 21:42:55 +0000 | [diff] [blame] | 1959 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1960 | #ifndef OPENSSL_NO_RMD160 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1961 | if (doit[D_RMD160]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1962 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1963 | print_message(names[D_RMD160], c[D_RMD160][testnum], |
| 1964 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1965 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1966 | count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1967 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1968 | print_result(D_RMD160, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1969 | } |
| 1970 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1971 | #endif |
| 1972 | #ifndef OPENSSL_NO_RC4 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1973 | if (doit[D_RC4]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1974 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 1975 | print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1976 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1977 | count = run_benchmark(async_jobs, RC4_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1978 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1979 | print_result(D_RC4, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1980 | } |
| 1981 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 1982 | #endif |
| 1983 | #ifndef OPENSSL_NO_DES |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1984 | if (doit[D_CBC_DES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1985 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1986 | print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], |
| 1987 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1988 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1989 | count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1990 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1991 | print_result(D_CBC_DES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1992 | } |
| 1993 | } |
Nils Larsch | ae93dc13 | 2006-12-01 21:42:55 +0000 | [diff] [blame] | 1994 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1995 | if (doit[D_EDE3_DES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 1996 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 1997 | print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], |
| 1998 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1999 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2000 | count = |
| 2001 | run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2002 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2003 | print_result(D_EDE3_DES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2004 | } |
| 2005 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2006 | #endif |
Matt Caswell | 5158c76 | 2016-04-13 11:28:45 +0100 | [diff] [blame] | 2007 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2008 | if (doit[D_CBC_128_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2009 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2010 | print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum], |
| 2011 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2012 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2013 | count = |
| 2014 | run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2015 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2016 | print_result(D_CBC_128_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | if (doit[D_CBC_192_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2020 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2021 | print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum], |
| 2022 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2023 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2024 | count = |
| 2025 | run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2026 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2027 | print_result(D_CBC_192_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | if (doit[D_CBC_256_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2031 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2032 | print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum], |
| 2033 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2034 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2035 | count = |
| 2036 | run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2037 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2038 | print_result(D_CBC_256_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2039 | } |
| 2040 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2041 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2042 | if (doit[D_IGE_128_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2043 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2044 | print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum], |
| 2045 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2046 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2047 | count = |
| 2048 | run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2049 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2050 | print_result(D_IGE_128_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | if (doit[D_IGE_192_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2054 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2055 | print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum], |
| 2056 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2057 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2058 | count = |
| 2059 | run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2060 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2061 | print_result(D_IGE_192_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | if (doit[D_IGE_256_AES]) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2065 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2066 | print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum], |
| 2067 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2068 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2069 | count = |
| 2070 | run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2071 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2072 | print_result(D_IGE_256_AES, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | if (doit[D_GHASH]) { |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2076 | for (i = 0; i < loopargs_len; i++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2077 | loopargs[i].gcm_ctx = |
| 2078 | CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt); |
| 2079 | CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, |
| 2080 | (unsigned char *)"0123456789ab", 12); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2081 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2082 | |
| 2083 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2084 | print_message(names[D_GHASH], c[D_GHASH][testnum], |
| 2085 | lengths[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2086 | Time_F(START); |
| 2087 | count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs); |
| 2088 | d = Time_F(STOP); |
| 2089 | print_result(D_GHASH, testnum, count, d); |
| 2090 | } |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2091 | for (i = 0; i < loopargs_len; i++) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2092 | CRYPTO_gcm128_release(loopargs[i].gcm_ctx); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2093 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2094 | #ifndef OPENSSL_NO_CAMELLIA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2095 | if (doit[D_CBC_128_CML]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2096 | if (async_jobs > 0) { |
| 2097 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2098 | names[D_CBC_128_CML]); |
| 2099 | doit[D_CBC_128_CML] = 0; |
| 2100 | } |
| 2101 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2102 | print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum], |
| 2103 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2104 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2105 | for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++) |
| 2106 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2107 | (size_t)lengths[testnum], &camellia_ks1, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2108 | iv, CAMELLIA_ENCRYPT); |
| 2109 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2110 | print_result(D_CBC_128_CML, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | if (doit[D_CBC_192_CML]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2114 | if (async_jobs > 0) { |
| 2115 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2116 | names[D_CBC_192_CML]); |
| 2117 | doit[D_CBC_192_CML] = 0; |
| 2118 | } |
| 2119 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2120 | print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum], |
| 2121 | lengths[testnum]); |
| 2122 | if (async_jobs > 0) { |
| 2123 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); |
| 2124 | exit(1); |
| 2125 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2126 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2127 | for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++) |
| 2128 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2129 | (size_t)lengths[testnum], &camellia_ks2, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2130 | iv, CAMELLIA_ENCRYPT); |
| 2131 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2132 | print_result(D_CBC_192_CML, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | if (doit[D_CBC_256_CML]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2136 | if (async_jobs > 0) { |
| 2137 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2138 | names[D_CBC_256_CML]); |
| 2139 | doit[D_CBC_256_CML] = 0; |
| 2140 | } |
| 2141 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2142 | print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum], |
| 2143 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2144 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2145 | for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++) |
| 2146 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2147 | (size_t)lengths[testnum], &camellia_ks3, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2148 | iv, CAMELLIA_ENCRYPT); |
| 2149 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2150 | print_result(D_CBC_256_CML, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2151 | } |
| 2152 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2153 | #endif |
| 2154 | #ifndef OPENSSL_NO_IDEA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2155 | if (doit[D_CBC_IDEA]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2156 | if (async_jobs > 0) { |
| 2157 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2158 | names[D_CBC_IDEA]); |
| 2159 | doit[D_CBC_IDEA] = 0; |
| 2160 | } |
| 2161 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2162 | print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], |
| 2163 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2164 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2165 | for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++) |
Rich Salz | 9021a5d | 2016-04-18 07:43:54 -0400 | [diff] [blame] | 2166 | IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2167 | (size_t)lengths[testnum], &idea_ks, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2168 | iv, IDEA_ENCRYPT); |
| 2169 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2170 | print_result(D_CBC_IDEA, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2171 | } |
| 2172 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2173 | #endif |
| 2174 | #ifndef OPENSSL_NO_SEED |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2175 | if (doit[D_CBC_SEED]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2176 | if (async_jobs > 0) { |
| 2177 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2178 | names[D_CBC_SEED]); |
| 2179 | doit[D_CBC_SEED] = 0; |
| 2180 | } |
| 2181 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2182 | print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], |
| 2183 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2184 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2185 | for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++) |
| 2186 | SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2187 | (size_t)lengths[testnum], &seed_ks, iv, 1); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2188 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2189 | print_result(D_CBC_SEED, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2190 | } |
| 2191 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2192 | #endif |
| 2193 | #ifndef OPENSSL_NO_RC2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2194 | if (doit[D_CBC_RC2]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2195 | if (async_jobs > 0) { |
| 2196 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2197 | names[D_CBC_RC2]); |
| 2198 | doit[D_CBC_RC2] = 0; |
| 2199 | } |
| 2200 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2201 | print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], |
| 2202 | lengths[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2203 | if (async_jobs > 0) { |
| 2204 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); |
| 2205 | exit(1); |
| 2206 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2207 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2208 | for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++) |
| 2209 | RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2210 | (size_t)lengths[testnum], &rc2_ks, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2211 | iv, RC2_ENCRYPT); |
| 2212 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2213 | print_result(D_CBC_RC2, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2214 | } |
| 2215 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2216 | #endif |
| 2217 | #ifndef OPENSSL_NO_RC5 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2218 | if (doit[D_CBC_RC5]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2219 | if (async_jobs > 0) { |
| 2220 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2221 | names[D_CBC_RC5]); |
| 2222 | doit[D_CBC_RC5] = 0; |
| 2223 | } |
| 2224 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2225 | print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], |
| 2226 | lengths[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2227 | if (async_jobs > 0) { |
| 2228 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); |
| 2229 | exit(1); |
| 2230 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2231 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2232 | for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++) |
| 2233 | RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2234 | (size_t)lengths[testnum], &rc5_ks, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2235 | iv, RC5_ENCRYPT); |
| 2236 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2237 | print_result(D_CBC_RC5, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2238 | } |
| 2239 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2240 | #endif |
| 2241 | #ifndef OPENSSL_NO_BF |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2242 | if (doit[D_CBC_BF]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2243 | if (async_jobs > 0) { |
| 2244 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2245 | names[D_CBC_BF]); |
| 2246 | doit[D_CBC_BF] = 0; |
| 2247 | } |
| 2248 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2249 | print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], |
| 2250 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2251 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2252 | for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++) |
| 2253 | BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2254 | (size_t)lengths[testnum], &bf_ks, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2255 | iv, BF_ENCRYPT); |
| 2256 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2257 | print_result(D_CBC_BF, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2258 | } |
| 2259 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2260 | #endif |
| 2261 | #ifndef OPENSSL_NO_CAST |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2262 | if (doit[D_CBC_CAST]) { |
FdaSilvaYY | e597260 | 2016-08-18 08:44:43 +0200 | [diff] [blame] | 2263 | if (async_jobs > 0) { |
| 2264 | BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2265 | names[D_CBC_CAST]); |
| 2266 | doit[D_CBC_CAST] = 0; |
| 2267 | } |
| 2268 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2269 | print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], |
| 2270 | lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2271 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2272 | for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++) |
| 2273 | CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
FdaSilvaYY | 8829ce3 | 2016-07-19 23:57:18 +0200 | [diff] [blame] | 2274 | (size_t)lengths[testnum], &cast_ks, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2275 | iv, CAST_ENCRYPT); |
| 2276 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2277 | print_result(D_CBC_CAST, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2278 | } |
| 2279 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2280 | #endif |
Ben Laurie | 5f09d0e | 2007-05-13 12:57:59 +0000 | [diff] [blame] | 2281 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2282 | if (doit[D_EVP]) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2283 | if (multiblock && evp_cipher) { |
| 2284 | if (! |
| 2285 | (EVP_CIPHER_flags(evp_cipher) & |
| 2286 | EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { |
Rich Salz | 7768e11 | 2015-06-04 14:26:55 -0400 | [diff] [blame] | 2287 | BIO_printf(bio_err, "%s is not multi-block capable\n", |
Richard Levitte | 6c2ff56 | 2015-12-18 17:08:49 +0100 | [diff] [blame] | 2288 | OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher))); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2289 | goto end; |
| 2290 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2291 | if (async_jobs > 0) { |
| 2292 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); |
| 2293 | exit(1); |
| 2294 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2295 | multiblock_speed(evp_cipher); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2296 | ret = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2297 | goto end; |
| 2298 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2299 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2300 | if (evp_cipher) { |
Ben Laurie | 5f09d0e | 2007-05-13 12:57:59 +0000 | [diff] [blame] | 2301 | |
Richard Levitte | 6c2ff56 | 2015-12-18 17:08:49 +0100 | [diff] [blame] | 2302 | names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2303 | /* |
| 2304 | * -O3 -fschedule-insns messes up an optimization here! |
| 2305 | * names[D_EVP] somehow becomes NULL |
| 2306 | */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2307 | print_message(names[D_EVP], save_count, lengths[testnum]); |
Bodo Möller | f3dea9a | 2006-06-09 15:44:59 +0000 | [diff] [blame] | 2308 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2309 | for (k = 0; k < loopargs_len; k++) { |
| 2310 | loopargs[k].ctx = EVP_CIPHER_CTX_new(); |
| 2311 | if (decrypt) |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2312 | EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, |
| 2313 | key16, iv); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2314 | else |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2315 | EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, |
| 2316 | key16, iv); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2317 | EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0); |
| 2318 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2319 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2320 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2321 | count = run_benchmark(async_jobs, EVP_Update_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2322 | d = Time_F(STOP); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2323 | for (k = 0; k < loopargs_len; k++) { |
| 2324 | EVP_CIPHER_CTX_free(loopargs[k].ctx); |
| 2325 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2326 | } |
| 2327 | if (evp_md) { |
Richard Levitte | cc9d665 | 2015-11-29 20:12:35 +0100 | [diff] [blame] | 2328 | names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md)); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2329 | print_message(names[D_EVP], save_count, lengths[testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2330 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2331 | count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2332 | d = Time_F(STOP); |
| 2333 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2334 | print_result(D_EVP, testnum, count, d); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2335 | } |
| 2336 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2337 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2338 | for (i = 0; i < loopargs_len; i++) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2339 | RAND_bytes(loopargs[i].buf, 36); |
| 2340 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2341 | #ifndef OPENSSL_NO_RSA |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2342 | for (testnum = 0; testnum < RSA_NUM; testnum++) { |
| 2343 | int st = 0; |
| 2344 | if (!rsa_doit[testnum]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2345 | continue; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2346 | for (i = 0; i < loopargs_len; i++) { |
| 2347 | st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 2348 | &loopargs[i].siglen, loopargs[i].rsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2349 | if (st == 0) |
| 2350 | break; |
| 2351 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2352 | if (st == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2353 | BIO_printf(bio_err, |
| 2354 | "RSA sign failure. No RSA sign will be done.\n"); |
| 2355 | ERR_print_errors(bio_err); |
| 2356 | rsa_count = 1; |
| 2357 | } else { |
| 2358 | pkey_print_message("private", "rsa", |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2359 | rsa_c[testnum][0], rsa_bits[testnum], |
| 2360 | RSA_SECONDS); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2361 | /* RSA_blinding_on(rsa_key[testnum],NULL); */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2362 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2363 | count = run_benchmark(async_jobs, RSA_sign_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2364 | d = Time_F(STOP); |
| 2365 | BIO_printf(bio_err, |
| 2366 | mr ? "+R1:%ld:%d:%.2f\n" |
| 2367 | : "%ld %d bit private RSA's in %.2fs\n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2368 | count, rsa_bits[testnum], d); |
Cristian Stoica | 8ac2d1a | 2016-08-02 11:13:00 +0300 | [diff] [blame] | 2369 | rsa_results[testnum][0] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2370 | rsa_count = count; |
| 2371 | } |
Richard Levitte | 83c40e7 | 2001-11-15 20:19:40 +0000 | [diff] [blame] | 2372 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2373 | for (i = 0; i < loopargs_len; i++) { |
| 2374 | st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 2375 | loopargs[i].siglen, loopargs[i].rsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2376 | if (st <= 0) |
| 2377 | break; |
| 2378 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2379 | if (st <= 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2380 | BIO_printf(bio_err, |
| 2381 | "RSA verify failure. No RSA verify will be done.\n"); |
| 2382 | ERR_print_errors(bio_err); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2383 | rsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2384 | } else { |
| 2385 | pkey_print_message("public", "rsa", |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2386 | rsa_c[testnum][1], rsa_bits[testnum], |
| 2387 | RSA_SECONDS); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2388 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2389 | count = run_benchmark(async_jobs, RSA_verify_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2390 | d = Time_F(STOP); |
| 2391 | BIO_printf(bio_err, |
| 2392 | mr ? "+R2:%ld:%d:%.2f\n" |
| 2393 | : "%ld %d bit public RSA's in %.2fs\n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2394 | count, rsa_bits[testnum], d); |
Cristian Stoica | 8ac2d1a | 2016-08-02 11:13:00 +0300 | [diff] [blame] | 2395 | rsa_results[testnum][1] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2396 | } |
Richard Levitte | 83c40e7 | 2001-11-15 20:19:40 +0000 | [diff] [blame] | 2397 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2398 | if (rsa_count <= 1) { |
| 2399 | /* if longer than 10s, don't do any more */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2400 | for (testnum++; testnum < RSA_NUM; testnum++) |
| 2401 | rsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 2404 | #endif /* OPENSSL_NO_RSA */ |
Richard Levitte | 83c40e7 | 2001-11-15 20:19:40 +0000 | [diff] [blame] | 2405 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2406 | for (i = 0; i < loopargs_len; i++) |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2407 | RAND_bytes(loopargs[i].buf, 36); |
| 2408 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2409 | #ifndef OPENSSL_NO_DSA |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2410 | if (RAND_status() != 1) { |
| 2411 | RAND_seed(rnd_seed, sizeof rnd_seed); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2412 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2413 | for (testnum = 0; testnum < DSA_NUM; testnum++) { |
| 2414 | int st = 0; |
| 2415 | if (!dsa_doit[testnum]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2416 | continue; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2417 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2418 | /* DSA_generate_key(dsa_key[testnum]); */ |
| 2419 | /* DSA_sign_setup(dsa_key[testnum],NULL); */ |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2420 | for (i = 0; i < loopargs_len; i++) { |
| 2421 | st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2, |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 2422 | &loopargs[i].siglen, loopargs[i].dsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2423 | if (st == 0) |
| 2424 | break; |
| 2425 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2426 | if (st == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2427 | BIO_printf(bio_err, |
| 2428 | "DSA sign failure. No DSA sign will be done.\n"); |
| 2429 | ERR_print_errors(bio_err); |
| 2430 | rsa_count = 1; |
| 2431 | } else { |
| 2432 | pkey_print_message("sign", "dsa", |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2433 | dsa_c[testnum][0], dsa_bits[testnum], |
| 2434 | DSA_SECONDS); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2435 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2436 | count = run_benchmark(async_jobs, DSA_sign_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2437 | d = Time_F(STOP); |
| 2438 | BIO_printf(bio_err, |
| 2439 | mr ? "+R3:%ld:%d:%.2f\n" |
| 2440 | : "%ld %d bit DSA signs in %.2fs\n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2441 | count, dsa_bits[testnum], d); |
Cristian Stoica | 0d4de75 | 2016-08-02 11:22:27 +0300 | [diff] [blame] | 2442 | dsa_results[testnum][0] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2443 | rsa_count = count; |
| 2444 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2445 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2446 | for (i = 0; i < loopargs_len; i++) { |
| 2447 | st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2, |
FdaSilvaYY | 0930e07 | 2016-07-28 23:20:19 +0200 | [diff] [blame] | 2448 | loopargs[i].siglen, loopargs[i].dsa_key[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2449 | if (st <= 0) |
| 2450 | break; |
| 2451 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2452 | if (st <= 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2453 | BIO_printf(bio_err, |
| 2454 | "DSA verify failure. No DSA verify will be done.\n"); |
| 2455 | ERR_print_errors(bio_err); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2456 | dsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2457 | } else { |
| 2458 | pkey_print_message("verify", "dsa", |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2459 | dsa_c[testnum][1], dsa_bits[testnum], |
| 2460 | DSA_SECONDS); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2461 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2462 | count = run_benchmark(async_jobs, DSA_verify_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2463 | d = Time_F(STOP); |
| 2464 | BIO_printf(bio_err, |
| 2465 | mr ? "+R4:%ld:%d:%.2f\n" |
| 2466 | : "%ld %d bit DSA verify in %.2fs\n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2467 | count, dsa_bits[testnum], d); |
Cristian Stoica | 0d4de75 | 2016-08-02 11:22:27 +0300 | [diff] [blame] | 2468 | dsa_results[testnum][1] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2469 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 2470 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2471 | if (rsa_count <= 1) { |
| 2472 | /* if longer than 10s, don't do any more */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2473 | for (testnum++; testnum < DSA_NUM; testnum++) |
| 2474 | dsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2475 | } |
| 2476 | } |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 2477 | #endif /* OPENSSL_NO_DSA */ |
Andy Polyakov | e751bba | 2015-01-20 14:15:44 +0100 | [diff] [blame] | 2478 | |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 2479 | #ifndef OPENSSL_NO_EC |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2480 | if (RAND_status() != 1) { |
| 2481 | RAND_seed(rnd_seed, sizeof rnd_seed); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2482 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2483 | for (testnum = 0; testnum < EC_NUM; testnum++) { |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2484 | int st = 1; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2485 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2486 | if (!ecdsa_doit[testnum]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2487 | continue; /* Ignore Curve */ |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2488 | for (i = 0; i < loopargs_len; i++) { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2489 | loopargs[i].ecdsa[testnum] = |
| 2490 | EC_KEY_new_by_curve_name(test_curves[testnum]); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2491 | if (loopargs[i].ecdsa[testnum] == NULL) { |
| 2492 | st = 0; |
| 2493 | break; |
| 2494 | } |
| 2495 | } |
| 2496 | if (st == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2497 | BIO_printf(bio_err, "ECDSA failure.\n"); |
| 2498 | ERR_print_errors(bio_err); |
| 2499 | rsa_count = 1; |
| 2500 | } else { |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2501 | for (i = 0; i < loopargs_len; i++) { |
| 2502 | EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL); |
| 2503 | /* Perform ECDSA signature test */ |
| 2504 | EC_KEY_generate_key(loopargs[i].ecdsa[testnum]); |
| 2505 | st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2506 | &loopargs[i].siglen, |
| 2507 | loopargs[i].ecdsa[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2508 | if (st == 0) |
| 2509 | break; |
| 2510 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2511 | if (st == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2512 | BIO_printf(bio_err, |
| 2513 | "ECDSA sign failure. No ECDSA sign will be done.\n"); |
| 2514 | ERR_print_errors(bio_err); |
| 2515 | rsa_count = 1; |
| 2516 | } else { |
| 2517 | pkey_print_message("sign", "ecdsa", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2518 | ecdsa_c[testnum][0], |
| 2519 | test_curves_bits[testnum], ECDSA_SECONDS); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2520 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2521 | count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2522 | d = Time_F(STOP); |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 2523 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2524 | BIO_printf(bio_err, |
| 2525 | mr ? "+R5:%ld:%d:%.2f\n" : |
| 2526 | "%ld %d bit ECDSA signs in %.2fs \n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2527 | count, test_curves_bits[testnum], d); |
Cristian Stoica | c8bff7a | 2016-08-02 11:38:45 +0300 | [diff] [blame] | 2528 | ecdsa_results[testnum][0] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2529 | rsa_count = count; |
| 2530 | } |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 2531 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2532 | /* Perform ECDSA verification test */ |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2533 | for (i = 0; i < loopargs_len; i++) { |
| 2534 | st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2535 | loopargs[i].siglen, |
| 2536 | loopargs[i].ecdsa[testnum]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2537 | if (st != 1) |
| 2538 | break; |
| 2539 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2540 | if (st != 1) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2541 | BIO_printf(bio_err, |
| 2542 | "ECDSA verify failure. No ECDSA verify will be done.\n"); |
| 2543 | ERR_print_errors(bio_err); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2544 | ecdsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2545 | } else { |
| 2546 | pkey_print_message("verify", "ecdsa", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2547 | ecdsa_c[testnum][1], |
| 2548 | test_curves_bits[testnum], ECDSA_SECONDS); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2549 | Time_F(START); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2550 | count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2551 | d = Time_F(STOP); |
| 2552 | BIO_printf(bio_err, |
| 2553 | mr ? "+R6:%ld:%d:%.2f\n" |
| 2554 | : "%ld %d bit ECDSA verify in %.2fs\n", |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2555 | count, test_curves_bits[testnum], d); |
Cristian Stoica | c8bff7a | 2016-08-02 11:38:45 +0300 | [diff] [blame] | 2556 | ecdsa_results[testnum][1] = (double)count / d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2557 | } |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 2558 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2559 | if (rsa_count <= 1) { |
| 2560 | /* if longer than 10s, don't do any more */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2561 | for (testnum++; testnum < EC_NUM; testnum++) |
| 2562 | ecdsa_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2566 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2567 | if (RAND_status() != 1) { |
| 2568 | RAND_seed(rnd_seed, sizeof rnd_seed); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2569 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2570 | for (testnum = 0; testnum < EC_NUM; testnum++) { |
FdaSilvaYY | 4d82c58 | 2016-07-19 23:54:21 +0200 | [diff] [blame] | 2571 | int ecdh_checks = 1; |
| 2572 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2573 | if (!ecdh_doit[testnum]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2574 | continue; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2575 | |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2576 | for (i = 0; i < loopargs_len; i++) { |
Nicola Tuveri | 2e4c3b5 | 2016-10-04 15:50:11 +0300 | [diff] [blame] | 2577 | EVP_PKEY_CTX *kctx = NULL; |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2578 | EVP_PKEY_CTX *test_ctx = NULL; |
Nicola Tuveri | 2e4c3b5 | 2016-10-04 15:50:11 +0300 | [diff] [blame] | 2579 | EVP_PKEY_CTX *ctx = NULL; |
| 2580 | EVP_PKEY *key_A = NULL; |
| 2581 | EVP_PKEY *key_B = NULL; |
Nicola Tuveri | cc98e63 | 2016-10-04 09:17:11 +0300 | [diff] [blame] | 2582 | size_t outlen; |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2583 | size_t test_outlen; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2584 | |
Nicola Tuveri | 86ff6cc | 2016-10-07 17:23:17 +0300 | [diff] [blame] | 2585 | /* Ensure that the error queue is empty */ |
| 2586 | if (ERR_peek_error()) { |
| 2587 | BIO_printf(bio_err, |
| 2588 | "WARNING: the error queue contains previous unhandled errors.\n"); |
| 2589 | ERR_print_errors(bio_err); |
| 2590 | } |
| 2591 | |
Nicola Tuveri | b756d69 | 2016-10-07 16:24:22 +0300 | [diff] [blame] | 2592 | /* Let's try to create a ctx directly from the NID: this works for |
| 2593 | * curves like Curve25519 that are not implemented through the low |
| 2594 | * level EC interface. |
| 2595 | * If this fails we try creating a EVP_PKEY_EC generic param ctx, |
| 2596 | * then we set the curve by NID before deriving the actual keygen |
| 2597 | * ctx for that specific curve. */ |
| 2598 | kctx = EVP_PKEY_CTX_new_id(test_curves[testnum], NULL); /* keygen ctx from NID */ |
| 2599 | if (!kctx) { |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2600 | EVP_PKEY_CTX *pctx = NULL; |
| 2601 | EVP_PKEY *params = NULL; |
| 2602 | |
Nicola Tuveri | 86ff6cc | 2016-10-07 17:23:17 +0300 | [diff] [blame] | 2603 | /* If we reach this code EVP_PKEY_CTX_new_id() failed and a |
| 2604 | * "int_ctx_new:unsupported algorithm" error was added to the |
| 2605 | * error queue. |
| 2606 | * We remove it from the error queue as we are handling it. */ |
| 2607 | unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */ |
| 2608 | if (error == ERR_peek_last_error() && /* oldest and latest errors match */ |
| 2609 | /* check that the error origin matches */ |
| 2610 | ERR_GET_LIB(error) == ERR_LIB_EVP && |
| 2611 | ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW && |
| 2612 | ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM) |
| 2613 | ERR_get_error(); /* pop error from queue */ |
| 2614 | if (ERR_peek_error()) { |
| 2615 | BIO_printf(bio_err, |
| 2616 | "Unhandled error in the error queue during ECDH init.\n"); |
| 2617 | ERR_print_errors(bio_err); |
| 2618 | rsa_count = 1; |
| 2619 | break; |
| 2620 | } |
| 2621 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2622 | if ( /* Create the context for parameter generation */ |
| 2623 | !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) || |
| 2624 | /* Initialise the parameter generation */ |
| 2625 | !EVP_PKEY_paramgen_init(pctx) || |
| 2626 | /* Set the curve by NID */ |
| 2627 | !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, |
| 2628 | test_curves |
| 2629 | [testnum]) || |
| 2630 | /* Create the parameter object params */ |
Nicola Tuveri | 2e4c3b5 | 2016-10-04 15:50:11 +0300 | [diff] [blame] | 2631 | !EVP_PKEY_paramgen(pctx, ¶ms)) { |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2632 | ecdh_checks = 0; |
Nicola Tuveri | b756d69 | 2016-10-07 16:24:22 +0300 | [diff] [blame] | 2633 | BIO_printf(bio_err, "ECDH EC params init failure.\n"); |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2634 | ERR_print_errors(bio_err); |
| 2635 | rsa_count = 1; |
| 2636 | break; |
| 2637 | } |
| 2638 | /* Create the context for the key generation */ |
| 2639 | kctx = EVP_PKEY_CTX_new(params, NULL); |
| 2640 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2641 | EVP_PKEY_free(params); |
| 2642 | params = NULL; |
| 2643 | EVP_PKEY_CTX_free(pctx); |
| 2644 | pctx = NULL; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2645 | } |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2646 | if (!kctx || /* keygen ctx is not null */ |
Nicola Tuveri | 2e4c3b5 | 2016-10-04 15:50:11 +0300 | [diff] [blame] | 2647 | !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) { |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2648 | ecdh_checks = 0; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2649 | BIO_printf(bio_err, "ECDH keygen failure.\n"); |
| 2650 | ERR_print_errors(bio_err); |
| 2651 | rsa_count = 1; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2652 | break; |
| 2653 | } |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2654 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2655 | if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */ |
| 2656 | !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */ |
| 2657 | !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */ |
| 2658 | !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */ |
| 2659 | !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */ |
| 2660 | !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */ |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2661 | outlen == 0 || /* ensure outlen is a valid size */ |
Nicola Tuveri | 2e4c3b5 | 2016-10-04 15:50:11 +0300 | [diff] [blame] | 2662 | outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) { |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2663 | ecdh_checks = 0; |
| 2664 | BIO_printf(bio_err, "ECDH key generation failure.\n"); |
| 2665 | ERR_print_errors(bio_err); |
| 2666 | rsa_count = 1; |
| 2667 | break; |
| 2668 | } |
| 2669 | |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2670 | /* Here we perform a test run, comparing the output of a*B and b*A; |
| 2671 | * we try this here and assume that further EVP_PKEY_derive calls |
| 2672 | * never fail, so we can skip checks in the actually benchmarked |
| 2673 | * code, for maximum performance. */ |
| 2674 | if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */ |
| 2675 | !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */ |
| 2676 | !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */ |
| 2677 | !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */ |
| 2678 | !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */ |
| 2679 | !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */ |
| 2680 | test_outlen != outlen /* compare output length */ ) { |
| 2681 | ecdh_checks = 0; |
| 2682 | BIO_printf(bio_err, "ECDH computation failure.\n"); |
| 2683 | ERR_print_errors(bio_err); |
| 2684 | rsa_count = 1; |
| 2685 | break; |
| 2686 | } |
Nicola Tuveri | 9bffdeb | 2016-10-06 13:17:00 +0300 | [diff] [blame] | 2687 | |
| 2688 | /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */ |
| 2689 | if (CRYPTO_memcmp(loopargs[i].secret_a, |
| 2690 | loopargs[i].secret_b, outlen)) { |
| 2691 | ecdh_checks = 0; |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2692 | BIO_printf(bio_err, "ECDH computations don't match.\n"); |
| 2693 | ERR_print_errors(bio_err); |
| 2694 | rsa_count = 1; |
| 2695 | break; |
| 2696 | } |
| 2697 | |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2698 | loopargs[i].ecdh_ctx[testnum] = ctx; |
Nicola Tuveri | cc98e63 | 2016-10-04 09:17:11 +0300 | [diff] [blame] | 2699 | loopargs[i].outlen[testnum] = outlen; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2700 | |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2701 | EVP_PKEY_CTX_free(kctx); |
| 2702 | kctx = NULL; |
Nicola Tuveri | f7d984d | 2016-10-04 16:40:47 +0300 | [diff] [blame] | 2703 | EVP_PKEY_CTX_free(test_ctx); |
| 2704 | test_ctx = NULL; |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2705 | } |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2706 | if (ecdh_checks != 0) { |
| 2707 | pkey_print_message("", "ecdh", |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2708 | ecdh_c[testnum][0], |
| 2709 | test_curves_bits[testnum], ECDH_SECONDS); |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2710 | Time_F(START); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2711 | count = |
| 2712 | run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs); |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2713 | d = Time_F(STOP); |
| 2714 | BIO_printf(bio_err, |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 2715 | mr ? "+R7:%ld:%d:%.2f\n" : |
| 2716 | "%ld %d-bit ECDH ops in %.2fs\n", count, |
| 2717 | test_curves_bits[testnum], d); |
Cristian Stoica | 222c3da | 2016-08-02 11:41:30 +0300 | [diff] [blame] | 2718 | ecdh_results[testnum][0] = (double)count / d; |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2719 | rsa_count = count; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2720 | } |
Nils Larsch | 9dd8405 | 2005-05-16 10:11:04 +0000 | [diff] [blame] | 2721 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2722 | if (rsa_count <= 1) { |
| 2723 | /* if longer than 10s, don't do any more */ |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2724 | for (testnum++; testnum < EC_NUM; testnum++) |
| 2725 | ecdh_doit[testnum] = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2726 | } |
| 2727 | } |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 2728 | #endif /* OPENSSL_NO_EC */ |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2729 | #ifndef NO_FORK |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2730 | show_res: |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2731 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2732 | if (!mr) { |
Rich Salz | b0700d2 | 2015-10-27 15:11:48 -0400 | [diff] [blame] | 2733 | printf("%s\n", OpenSSL_version(OPENSSL_VERSION)); |
| 2734 | printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2735 | printf("options:"); |
| 2736 | printf("%s ", BN_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2737 | #ifndef OPENSSL_NO_MD2 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2738 | printf("%s ", MD2_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2739 | #endif |
| 2740 | #ifndef OPENSSL_NO_RC4 |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2741 | printf("%s ", RC4_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2742 | #endif |
| 2743 | #ifndef OPENSSL_NO_DES |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2744 | printf("%s ", DES_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2745 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2746 | printf("%s ", AES_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2747 | #ifndef OPENSSL_NO_IDEA |
Rich Salz | 9021a5d | 2016-04-18 07:43:54 -0400 | [diff] [blame] | 2748 | printf("%s ", IDEA_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2749 | #endif |
| 2750 | #ifndef OPENSSL_NO_BF |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2751 | printf("%s ", BF_options()); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2752 | #endif |
Rich Salz | b0700d2 | 2015-10-27 15:11:48 -0400 | [diff] [blame] | 2753 | printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2754 | } |
Nils Larsch | 9dd8405 | 2005-05-16 10:11:04 +0000 | [diff] [blame] | 2755 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2756 | if (pr_header) { |
| 2757 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2758 | printf("+H"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2759 | else { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2760 | printf |
| 2761 | ("The 'numbers' are in 1000s of bytes per second processed.\n"); |
| 2762 | printf("type "); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2763 | } |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2764 | for (testnum = 0; testnum < SIZE_NUM; testnum++) |
| 2765 | printf(mr ? ":%d" : "%7d bytes", lengths[testnum]); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2766 | printf("\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2767 | } |
Nils Larsch | 9dd8405 | 2005-05-16 10:11:04 +0000 | [diff] [blame] | 2768 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2769 | for (k = 0; k < ALGOR_NUM; k++) { |
| 2770 | if (!doit[k]) |
| 2771 | continue; |
| 2772 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2773 | printf("+F:%d:%s", k, names[k]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2774 | else |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2775 | printf("%-13s", names[k]); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2776 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
| 2777 | if (results[k][testnum] > 10000 && !mr) |
| 2778 | printf(" %11.2fk", results[k][testnum] / 1e3); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2779 | else |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2780 | printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2781 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2782 | printf("\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2783 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2784 | #ifndef OPENSSL_NO_RSA |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2785 | testnum = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2786 | for (k = 0; k < RSA_NUM; k++) { |
| 2787 | if (!rsa_doit[k]) |
| 2788 | continue; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2789 | if (testnum && !mr) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2790 | printf("%18ssign verify sign/s verify/s\n", " "); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2791 | testnum = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2792 | } |
| 2793 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2794 | printf("+F2:%u:%u:%f:%f\n", |
| 2795 | k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2796 | else |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2797 | printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
Cristian Stoica | 8ac2d1a | 2016-08-02 11:13:00 +0300 | [diff] [blame] | 2798 | rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1], |
| 2799 | rsa_results[k][0], rsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2800 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2801 | #endif |
| 2802 | #ifndef OPENSSL_NO_DSA |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2803 | testnum = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2804 | for (k = 0; k < DSA_NUM; k++) { |
| 2805 | if (!dsa_doit[k]) |
| 2806 | continue; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2807 | if (testnum && !mr) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2808 | printf("%18ssign verify sign/s verify/s\n", " "); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2809 | testnum = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2810 | } |
| 2811 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2812 | printf("+F3:%u:%u:%f:%f\n", |
| 2813 | k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2814 | else |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2815 | printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
Cristian Stoica | 0d4de75 | 2016-08-02 11:22:27 +0300 | [diff] [blame] | 2816 | dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1], |
| 2817 | dsa_results[k][0], dsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2818 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2819 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 2820 | #ifndef OPENSSL_NO_EC |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2821 | testnum = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2822 | for (k = 0; k < EC_NUM; k++) { |
| 2823 | if (!ecdsa_doit[k]) |
| 2824 | continue; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2825 | if (testnum && !mr) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2826 | printf("%30ssign verify sign/s verify/s\n", " "); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2827 | testnum = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2828 | } |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 2829 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2830 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2831 | printf("+F4:%u:%u:%f:%f\n", |
| 2832 | k, test_curves_bits[k], |
| 2833 | ecdsa_results[k][0], ecdsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2834 | else |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2835 | printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", |
| 2836 | test_curves_bits[k], |
| 2837 | test_curves_names[k], |
Cristian Stoica | c8bff7a | 2016-08-02 11:38:45 +0300 | [diff] [blame] | 2838 | 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1], |
| 2839 | ecdsa_results[k][0], ecdsa_results[k][1]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2840 | } |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2841 | |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2842 | testnum = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2843 | for (k = 0; k < EC_NUM; k++) { |
| 2844 | if (!ecdh_doit[k]) |
| 2845 | continue; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2846 | if (testnum && !mr) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2847 | printf("%30sop op/s\n", " "); |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2848 | testnum = 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2849 | } |
| 2850 | if (mr) |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2851 | printf("+F5:%u:%u:%f:%f\n", |
| 2852 | k, test_curves_bits[k], |
| 2853 | ecdh_results[k][0], 1.0 / ecdh_results[k][0]); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2854 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2855 | else |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2856 | printf("%4u bit ecdh (%s) %8.4fs %8.1f\n", |
| 2857 | test_curves_bits[k], |
| 2858 | test_curves_names[k], |
Cristian Stoica | 222c3da | 2016-08-02 11:41:30 +0300 | [diff] [blame] | 2859 | 1.0 / ecdh_results[k][0], ecdh_results[k][0]); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2860 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2861 | #endif |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2862 | |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2863 | ret = 0; |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 2864 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2865 | end: |
| 2866 | ERR_print_errors(bio_err); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2867 | for (i = 0; i < loopargs_len; i++) { |
Andrea Grandi | b283968 | 2016-02-27 06:14:49 +0000 | [diff] [blame] | 2868 | OPENSSL_free(loopargs[i].buf_malloc); |
| 2869 | OPENSSL_free(loopargs[i].buf2_malloc); |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 2870 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2871 | #ifndef OPENSSL_NO_RSA |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2872 | for (k = 0; k < RSA_NUM; k++) |
| 2873 | RSA_free(loopargs[i].rsa_key[k]); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2874 | #endif |
| 2875 | #ifndef OPENSSL_NO_DSA |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2876 | for (k = 0; k < DSA_NUM; k++) |
| 2877 | DSA_free(loopargs[i].dsa_key[k]); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2878 | #endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 2879 | #ifndef OPENSSL_NO_EC |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2880 | for (k = 0; k < EC_NUM; k++) { |
| 2881 | EC_KEY_free(loopargs[i].ecdsa[k]); |
Nicola Tuveri | ed7377d | 2016-10-03 20:28:32 +0300 | [diff] [blame] | 2882 | EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]); |
Andrea Grandi | 0ff4343 | 2016-02-18 10:56:53 +0000 | [diff] [blame] | 2883 | } |
Andrea Grandi | b283968 | 2016-02-27 06:14:49 +0000 | [diff] [blame] | 2884 | OPENSSL_free(loopargs[i].secret_a); |
| 2885 | OPENSSL_free(loopargs[i].secret_b); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2886 | #endif |
FdaSilvaYY | 5f986ed | 2016-07-29 13:22:42 +0200 | [diff] [blame] | 2887 | } |
| 2888 | |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 2889 | if (async_jobs > 0) { |
| 2890 | for (i = 0; i < loopargs_len; i++) |
| 2891 | ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx); |
Cristian Stoica | dab1f5f | 2016-05-17 18:40:14 +0300 | [diff] [blame] | 2892 | } |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 2893 | |
Cristian Stoica | dab1f5f | 2016-05-17 18:40:14 +0300 | [diff] [blame] | 2894 | if (async_init) { |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 2895 | ASYNC_cleanup_thread(); |
Andrea Grandi | 1e61392 | 2016-02-29 11:28:55 +0000 | [diff] [blame] | 2896 | } |
| 2897 | OPENSSL_free(loopargs); |
Richard Levitte | dd1abd4 | 2016-09-28 23:39:18 +0200 | [diff] [blame] | 2898 | release_engine(e); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 2899 | return (ret); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2900 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2901 | |
Ben Laurie | 646d569 | 2000-11-20 04:14:19 +0000 | [diff] [blame] | 2902 | static void print_message(const char *s, long num, int length) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2903 | { |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2904 | #ifdef SIGALRM |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2905 | BIO_printf(bio_err, |
| 2906 | mr ? "+DT:%s:%d:%d\n" |
| 2907 | : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length); |
| 2908 | (void)BIO_flush(bio_err); |
| 2909 | alarm(SECONDS); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2910 | #else |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2911 | BIO_printf(bio_err, |
| 2912 | mr ? "+DN:%s:%ld:%d\n" |
| 2913 | : "Doing %s %ld times on %d size blocks: ", s, num, length); |
| 2914 | (void)BIO_flush(bio_err); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2915 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2916 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 2917 | |
Nils Larsch | 689c6f2 | 2005-03-20 23:12:13 +0000 | [diff] [blame] | 2918 | static void pkey_print_message(const char *str, const char *str2, long num, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2919 | int bits, int tm) |
| 2920 | { |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2921 | #ifdef SIGALRM |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2922 | BIO_printf(bio_err, |
| 2923 | mr ? "+DTP:%d:%s:%s:%d\n" |
| 2924 | : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm); |
| 2925 | (void)BIO_flush(bio_err); |
| 2926 | alarm(tm); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2927 | #else |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2928 | BIO_printf(bio_err, |
| 2929 | mr ? "+DNP:%ld:%d:%s:%s\n" |
| 2930 | : "Doing %ld %d bit %s %s's: ", num, bits, str, str2); |
| 2931 | (void)BIO_flush(bio_err); |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2932 | #endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2933 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 2934 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2935 | static void print_result(int alg, int run_no, int count, double time_used) |
| 2936 | { |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 2937 | if (count == -1) { |
| 2938 | BIO_puts(bio_err, "EVP error!\n"); |
| 2939 | exit(1); |
| 2940 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2941 | BIO_printf(bio_err, |
| 2942 | mr ? "+R:%d:%s:%f\n" |
| 2943 | : "%d %s's in %.2fs\n", count, names[alg], time_used); |
| 2944 | results[alg][run_no] = ((double)count) / time_used * lengths[run_no]; |
| 2945 | } |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2946 | |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 2947 | #ifndef NO_FORK |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2948 | static char *sstrsep(char **string, const char *delim) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2949 | { |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2950 | char isdelim[256]; |
| 2951 | char *token = *string; |
| 2952 | |
| 2953 | if (**string == 0) |
| 2954 | return NULL; |
| 2955 | |
Ben Laurie | 54a656e | 2002-11-13 15:43:43 +0000 | [diff] [blame] | 2956 | memset(isdelim, 0, sizeof isdelim); |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2957 | isdelim[0] = 1; |
| 2958 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2959 | while (*delim) { |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2960 | isdelim[(unsigned char)(*delim)] = 1; |
| 2961 | delim++; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2964 | while (!isdelim[(unsigned char)(**string)]) { |
| 2965 | (*string)++; |
| 2966 | } |
| 2967 | |
| 2968 | if (**string) { |
| 2969 | **string = 0; |
| 2970 | (*string)++; |
| 2971 | } |
| 2972 | |
| 2973 | return token; |
| 2974 | } |
| 2975 | |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2976 | static int do_multi(int multi) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2977 | { |
| 2978 | int n; |
| 2979 | int fd[2]; |
| 2980 | int *fds; |
| 2981 | static char sep[] = ":"; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 2982 | |
Rich Salz | b4faea5 | 2015-05-01 23:10:31 -0400 | [diff] [blame] | 2983 | fds = malloc(sizeof(*fds) * multi); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2984 | for (n = 0; n < multi; ++n) { |
| 2985 | if (pipe(fd) == -1) { |
Rich Salz | 7768e11 | 2015-06-04 14:26:55 -0400 | [diff] [blame] | 2986 | BIO_printf(bio_err, "pipe failure\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2987 | exit(1); |
| 2988 | } |
| 2989 | fflush(stdout); |
Rich Salz | 7768e11 | 2015-06-04 14:26:55 -0400 | [diff] [blame] | 2990 | (void)BIO_flush(bio_err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2991 | if (fork()) { |
| 2992 | close(fd[1]); |
| 2993 | fds[n] = fd[0]; |
| 2994 | } else { |
| 2995 | close(fd[0]); |
| 2996 | close(1); |
| 2997 | if (dup(fd[1]) == -1) { |
Rich Salz | 7768e11 | 2015-06-04 14:26:55 -0400 | [diff] [blame] | 2998 | BIO_printf(bio_err, "dup failed\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 2999 | exit(1); |
| 3000 | } |
| 3001 | close(fd[1]); |
| 3002 | mr = 1; |
| 3003 | usertime = 0; |
| 3004 | free(fds); |
| 3005 | return 0; |
| 3006 | } |
| 3007 | printf("Forked child %d\n", n); |
| 3008 | } |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3009 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3010 | /* for now, assume the pipe is long enough to take all the output */ |
| 3011 | for (n = 0; n < multi; ++n) { |
| 3012 | FILE *f; |
| 3013 | char buf[1024]; |
| 3014 | char *p; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3015 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3016 | f = fdopen(fds[n], "r"); |
| 3017 | while (fgets(buf, sizeof buf, f)) { |
| 3018 | p = strchr(buf, '\n'); |
| 3019 | if (p) |
| 3020 | *p = '\0'; |
| 3021 | if (buf[0] != '+') { |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 3022 | BIO_printf(bio_err, |
| 3023 | "Don't understand line '%s' from child %d\n", buf, |
| 3024 | n); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3025 | continue; |
| 3026 | } |
| 3027 | printf("Got: %s from %d\n", buf, n); |
Rich Salz | 86885c2 | 2015-05-06 14:56:14 -0400 | [diff] [blame] | 3028 | if (strncmp(buf, "+F:", 3) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3029 | int alg; |
| 3030 | int j; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3031 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3032 | p = buf + 3; |
| 3033 | alg = atoi(sstrsep(&p, sep)); |
| 3034 | sstrsep(&p, sep); |
| 3035 | for (j = 0; j < SIZE_NUM; ++j) |
| 3036 | results[alg][j] += atof(sstrsep(&p, sep)); |
Rich Salz | 86885c2 | 2015-05-06 14:56:14 -0400 | [diff] [blame] | 3037 | } else if (strncmp(buf, "+F2:", 4) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3038 | int k; |
| 3039 | double d; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3040 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3041 | p = buf + 4; |
| 3042 | k = atoi(sstrsep(&p, sep)); |
| 3043 | sstrsep(&p, sep); |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3044 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3045 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | 8ac2d1a | 2016-08-02 11:13:00 +0300 | [diff] [blame] | 3046 | rsa_results[k][0] += d; |
Ben Laurie | 0e21156 | 2001-10-25 14:27:17 +0000 | [diff] [blame] | 3047 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3048 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | 8ac2d1a | 2016-08-02 11:13:00 +0300 | [diff] [blame] | 3049 | rsa_results[k][1] += d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3050 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 3051 | # ifndef OPENSSL_NO_DSA |
Rich Salz | 86885c2 | 2015-05-06 14:56:14 -0400 | [diff] [blame] | 3052 | else if (strncmp(buf, "+F3:", 4) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3053 | int k; |
| 3054 | double d; |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3055 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3056 | p = buf + 4; |
| 3057 | k = atoi(sstrsep(&p, sep)); |
| 3058 | sstrsep(&p, sep); |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3059 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3060 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | 0d4de75 | 2016-08-02 11:22:27 +0300 | [diff] [blame] | 3061 | dsa_results[k][0] += d; |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3062 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3063 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | 0d4de75 | 2016-08-02 11:22:27 +0300 | [diff] [blame] | 3064 | dsa_results[k][1] += d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3065 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 3066 | # endif |
Rich Salz | 10bf4fc | 2015-03-10 19:09:27 -0400 | [diff] [blame] | 3067 | # ifndef OPENSSL_NO_EC |
Rich Salz | 86885c2 | 2015-05-06 14:56:14 -0400 | [diff] [blame] | 3068 | else if (strncmp(buf, "+F4:", 4) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3069 | int k; |
| 3070 | double d; |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3071 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3072 | p = buf + 4; |
| 3073 | k = atoi(sstrsep(&p, sep)); |
| 3074 | sstrsep(&p, sep); |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3075 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3076 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | c8bff7a | 2016-08-02 11:38:45 +0300 | [diff] [blame] | 3077 | ecdsa_results[k][0] += d; |
Bodo Möller | e172d60 | 2002-08-09 08:43:04 +0000 | [diff] [blame] | 3078 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3079 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | c8bff7a | 2016-08-02 11:38:45 +0300 | [diff] [blame] | 3080 | ecdsa_results[k][1] += d; |
FdaSilvaYY | d6073e2 | 2016-08-07 12:04:26 +0200 | [diff] [blame] | 3081 | } else if (strncmp(buf, "+F5:", 4) == 0) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3082 | int k; |
| 3083 | double d; |
| 3084 | |
| 3085 | p = buf + 4; |
| 3086 | k = atoi(sstrsep(&p, sep)); |
| 3087 | sstrsep(&p, sep); |
| 3088 | |
| 3089 | d = atof(sstrsep(&p, sep)); |
Cristian Stoica | 222c3da | 2016-08-02 11:41:30 +0300 | [diff] [blame] | 3090 | ecdh_results[k][0] += d; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3091 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 3092 | # endif |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3093 | |
Rich Salz | 86885c2 | 2015-05-06 14:56:14 -0400 | [diff] [blame] | 3094 | else if (strncmp(buf, "+H:", 3) == 0) { |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 3095 | ; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3096 | } else |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 3097 | BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, |
| 3098 | n); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | fclose(f); |
| 3102 | } |
| 3103 | free(fds); |
| 3104 | return 1; |
| 3105 | } |
Rich Salz | a00ae6c | 2015-01-27 10:06:22 -0500 | [diff] [blame] | 3106 | #endif |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3107 | |
| 3108 | static void multiblock_speed(const EVP_CIPHER *evp_cipher) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3109 | { |
| 3110 | static int mblengths[] = |
| 3111 | { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 }; |
Andrea Grandi | 8b0b80d | 2015-12-09 07:26:38 +0000 | [diff] [blame] | 3112 | int j, count, num = OSSL_NELEM(mblengths); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3113 | const char *alg_name; |
| 3114 | unsigned char *inp, *out, no_key[32], no_iv[16]; |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3115 | EVP_CIPHER_CTX *ctx; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3116 | double d = 0.0; |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3117 | |
Rich Salz | 68dc682 | 2015-04-30 17:48:31 -0400 | [diff] [blame] | 3118 | inp = app_malloc(mblengths[num - 1], "multiblock input buffer"); |
| 3119 | out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer"); |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3120 | ctx = EVP_CIPHER_CTX_new(); |
| 3121 | EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv); |
Nicola Tuveri | 29dd15b | 2016-10-04 09:20:49 +0300 | [diff] [blame] | 3122 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key); |
Richard Levitte | 6c2ff56 | 2015-12-18 17:08:49 +0100 | [diff] [blame] | 3123 | alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3124 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3125 | for (j = 0; j < num; j++) { |
| 3126 | print_message(alg_name, 0, mblengths[j]); |
| 3127 | Time_F(START); |
| 3128 | for (count = 0, run = 1; run && count < 0x7fffffff; count++) { |
Matt Caswell | c826988 | 2015-04-27 11:07:06 +0100 | [diff] [blame] | 3129 | unsigned char aad[EVP_AEAD_TLS1_AAD_LEN]; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3130 | EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param; |
| 3131 | size_t len = mblengths[j]; |
| 3132 | int packlen; |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3133 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3134 | memset(aad, 0, 8); /* avoid uninitialized values */ |
| 3135 | aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */ |
| 3136 | aad[9] = 3; /* version */ |
| 3137 | aad[10] = 2; |
| 3138 | aad[11] = 0; /* length */ |
| 3139 | aad[12] = 0; |
| 3140 | mb_param.out = NULL; |
| 3141 | mb_param.inp = aad; |
| 3142 | mb_param.len = len; |
| 3143 | mb_param.interleave = 8; |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3144 | |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3145 | packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3146 | sizeof(mb_param), &mb_param); |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3147 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3148 | if (packlen > 0) { |
| 3149 | mb_param.out = out; |
| 3150 | mb_param.inp = inp; |
| 3151 | mb_param.len = len; |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3152 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3153 | sizeof(mb_param), &mb_param); |
| 3154 | } else { |
| 3155 | int pad; |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3156 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3157 | RAND_bytes(out, 16); |
| 3158 | len += 16; |
| 3159 | aad[11] = len >> 8; |
| 3160 | aad[12] = len; |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3161 | pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD, |
Matt Caswell | c826988 | 2015-04-27 11:07:06 +0100 | [diff] [blame] | 3162 | EVP_AEAD_TLS1_AAD_LEN, aad); |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3163 | EVP_Cipher(ctx, out, inp, len + pad); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | d = Time_F(STOP); |
Rich Salz | 7e1b748 | 2015-04-24 15:26:15 -0400 | [diff] [blame] | 3167 | BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n" |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3168 | : "%d %s's in %.2fs\n", count, "evp", d); |
| 3169 | results[D_EVP][j] = ((double)count) / d * mblengths[j]; |
| 3170 | } |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3171 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3172 | if (mr) { |
| 3173 | fprintf(stdout, "+H"); |
| 3174 | for (j = 0; j < num; j++) |
| 3175 | fprintf(stdout, ":%d", mblengths[j]); |
| 3176 | fprintf(stdout, "\n"); |
| 3177 | fprintf(stdout, "+F:%d:%s", D_EVP, alg_name); |
| 3178 | for (j = 0; j < num; j++) |
| 3179 | fprintf(stdout, ":%.2f", results[D_EVP][j]); |
| 3180 | fprintf(stdout, "\n"); |
| 3181 | } else { |
| 3182 | fprintf(stdout, |
| 3183 | "The 'numbers' are in 1000s of bytes per second processed.\n"); |
| 3184 | fprintf(stdout, "type "); |
| 3185 | for (j = 0; j < num; j++) |
| 3186 | fprintf(stdout, "%7d bytes", mblengths[j]); |
| 3187 | fprintf(stdout, "\n"); |
| 3188 | fprintf(stdout, "%-24s", alg_name); |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3189 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3190 | for (j = 0; j < num; j++) { |
| 3191 | if (results[D_EVP][j] > 10000) |
| 3192 | fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3); |
| 3193 | else |
| 3194 | fprintf(stdout, " %11.2f ", results[D_EVP][j]); |
| 3195 | } |
| 3196 | fprintf(stdout, "\n"); |
| 3197 | } |
Andy Polyakov | 375a64e | 2014-07-05 23:53:55 +0200 | [diff] [blame] | 3198 | |
Rich Salz | b548a1f | 2015-05-01 10:02:07 -0400 | [diff] [blame] | 3199 | OPENSSL_free(inp); |
| 3200 | OPENSSL_free(out); |
Richard Levitte | 846ec07 | 2015-12-13 22:08:41 +0100 | [diff] [blame] | 3201 | EVP_CIPHER_CTX_free(ctx); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 3202 | } |