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