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