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