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