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