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