]>
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; | |
358558eb | 170 | size_t outlen; |
3331e43b | 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 | |
d6073e27 | 350 | static int found(const char *name, const OPT_PAIR *pairs, int *result) |
7e1b7485 RS |
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 | ||
44c83ebd | 366 | const OPTIONS speed_options[] = { |
7e1b7485 RS |
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, '-', |
d6073e27 | 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 |
d6073e27 F |
383 | {"async_jobs", OPT_ASYNCJOBS, 'p', |
384 | "Enable async mode and start pnum jobs"}, | |
8b0b80d9 | 385 | #endif |
7e1b7485 RS |
386 | #ifndef OPENSSL_NO_ENGINE |
387 | {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, | |
388 | #endif | |
7786005d | 389 | {NULL}, |
7e1b7485 RS |
390 | }; |
391 | ||
392 | #define D_MD2 0 | |
393 | #define D_MDC2 1 | |
394 | #define D_MD4 2 | |
395 | #define D_MD5 3 | |
396 | #define D_HMAC 4 | |
397 | #define D_SHA1 5 | |
398 | #define D_RMD160 6 | |
399 | #define D_RC4 7 | |
400 | #define D_CBC_DES 8 | |
401 | #define D_EDE3_DES 9 | |
402 | #define D_CBC_IDEA 10 | |
403 | #define D_CBC_SEED 11 | |
404 | #define D_CBC_RC2 12 | |
405 | #define D_CBC_RC5 13 | |
406 | #define D_CBC_BF 14 | |
407 | #define D_CBC_CAST 15 | |
408 | #define D_CBC_128_AES 16 | |
409 | #define D_CBC_192_AES 17 | |
410 | #define D_CBC_256_AES 18 | |
411 | #define D_CBC_128_CML 19 | |
412 | #define D_CBC_192_CML 20 | |
413 | #define D_CBC_256_CML 21 | |
414 | #define D_EVP 22 | |
415 | #define D_SHA256 23 | |
416 | #define D_SHA512 24 | |
417 | #define D_WHIRLPOOL 25 | |
418 | #define D_IGE_128_AES 26 | |
419 | #define D_IGE_192_AES 27 | |
420 | #define D_IGE_256_AES 28 | |
421 | #define D_GHASH 29 | |
df2ee0e2 | 422 | static OPT_PAIR doit_choices[] = { |
7e1b7485 RS |
423 | #ifndef OPENSSL_NO_MD2 |
424 | {"md2", D_MD2}, | |
425 | #endif | |
426 | #ifndef OPENSSL_NO_MDC2 | |
427 | {"mdc2", D_MDC2}, | |
428 | #endif | |
429 | #ifndef OPENSSL_NO_MD4 | |
430 | {"md4", D_MD4}, | |
431 | #endif | |
432 | #ifndef OPENSSL_NO_MD5 | |
433 | {"md5", D_MD5}, | |
7e1b7485 RS |
434 | {"hmac", D_HMAC}, |
435 | #endif | |
436 | {"sha1", D_SHA1}, | |
437 | {"sha256", D_SHA256}, | |
438 | {"sha512", D_SHA512}, | |
439 | #ifndef OPENSSL_NO_WHIRLPOOL | |
440 | {"whirlpool", D_WHIRLPOOL}, | |
441 | #endif | |
fd682e4c | 442 | #ifndef OPENSSL_NO_RMD160 |
7e1b7485 RS |
443 | {"ripemd", D_RMD160}, |
444 | {"rmd160", D_RMD160}, | |
445 | {"ripemd160", D_RMD160}, | |
446 | #endif | |
447 | #ifndef OPENSSL_NO_RC4 | |
448 | {"rc4", D_RC4}, | |
449 | #endif | |
450 | #ifndef OPENSSL_NO_DES | |
451 | {"des-cbc", D_CBC_DES}, | |
452 | {"des-ede3", D_EDE3_DES}, | |
453 | #endif | |
7e1b7485 RS |
454 | {"aes-128-cbc", D_CBC_128_AES}, |
455 | {"aes-192-cbc", D_CBC_192_AES}, | |
456 | {"aes-256-cbc", D_CBC_256_AES}, | |
457 | {"aes-128-ige", D_IGE_128_AES}, | |
458 | {"aes-192-ige", D_IGE_192_AES}, | |
459 | {"aes-256-ige", D_IGE_256_AES}, | |
7e1b7485 RS |
460 | #ifndef OPENSSL_NO_RC2 |
461 | {"rc2-cbc", D_CBC_RC2}, | |
462 | {"rc2", D_CBC_RC2}, | |
463 | #endif | |
464 | #ifndef OPENSSL_NO_RC5 | |
465 | {"rc5-cbc", D_CBC_RC5}, | |
466 | {"rc5", D_CBC_RC5}, | |
467 | #endif | |
468 | #ifndef OPENSSL_NO_IDEA | |
469 | {"idea-cbc", D_CBC_IDEA}, | |
470 | {"idea", D_CBC_IDEA}, | |
471 | #endif | |
472 | #ifndef OPENSSL_NO_SEED | |
473 | {"seed-cbc", D_CBC_SEED}, | |
474 | {"seed", D_CBC_SEED}, | |
475 | #endif | |
476 | #ifndef OPENSSL_NO_BF | |
477 | {"bf-cbc", D_CBC_BF}, | |
478 | {"blowfish", D_CBC_BF}, | |
479 | {"bf", D_CBC_BF}, | |
480 | #endif | |
481 | #ifndef OPENSSL_NO_CAST | |
482 | {"cast-cbc", D_CBC_CAST}, | |
483 | {"cast", D_CBC_CAST}, | |
484 | {"cast5", D_CBC_CAST}, | |
485 | #endif | |
486 | {"ghash", D_GHASH}, | |
487 | {NULL} | |
488 | }; | |
489 | ||
83ae8124 MC |
490 | #ifndef OPENSSL_NO_DSA |
491 | # define R_DSA_512 0 | |
492 | # define R_DSA_1024 1 | |
493 | # define R_DSA_2048 2 | |
7e1b7485 RS |
494 | static OPT_PAIR dsa_choices[] = { |
495 | {"dsa512", R_DSA_512}, | |
496 | {"dsa1024", R_DSA_1024}, | |
497 | {"dsa2048", R_DSA_2048}, | |
498 | {NULL}, | |
499 | }; | |
83ae8124 | 500 | #endif |
667ac4ec | 501 | |
7e1b7485 RS |
502 | #define R_RSA_512 0 |
503 | #define R_RSA_1024 1 | |
504 | #define R_RSA_2048 2 | |
505 | #define R_RSA_3072 3 | |
506 | #define R_RSA_4096 4 | |
507 | #define R_RSA_7680 5 | |
508 | #define R_RSA_15360 6 | |
509 | static OPT_PAIR rsa_choices[] = { | |
510 | {"rsa512", R_RSA_512}, | |
511 | {"rsa1024", R_RSA_1024}, | |
512 | {"rsa2048", R_RSA_2048}, | |
513 | {"rsa3072", R_RSA_3072}, | |
514 | {"rsa4096", R_RSA_4096}, | |
515 | {"rsa7680", R_RSA_7680}, | |
516 | {"rsa15360", R_RSA_15360}, | |
517 | {NULL} | |
518 | }; | |
519 | ||
520 | #define R_EC_P160 0 | |
521 | #define R_EC_P192 1 | |
522 | #define R_EC_P224 2 | |
523 | #define R_EC_P256 3 | |
524 | #define R_EC_P384 4 | |
525 | #define R_EC_P521 5 | |
526 | #define R_EC_K163 6 | |
527 | #define R_EC_K233 7 | |
528 | #define R_EC_K283 8 | |
529 | #define R_EC_K409 9 | |
530 | #define R_EC_K571 10 | |
531 | #define R_EC_B163 11 | |
532 | #define R_EC_B233 12 | |
533 | #define R_EC_B283 13 | |
534 | #define R_EC_B409 14 | |
535 | #define R_EC_B571 15 | |
db50c1da | 536 | #define R_EC_X25519 16 |
f5349f8c | 537 | #ifndef OPENSSL_NO_EC |
7e1b7485 RS |
538 | static OPT_PAIR ecdsa_choices[] = { |
539 | {"ecdsap160", R_EC_P160}, | |
540 | {"ecdsap192", R_EC_P192}, | |
541 | {"ecdsap224", R_EC_P224}, | |
542 | {"ecdsap256", R_EC_P256}, | |
543 | {"ecdsap384", R_EC_P384}, | |
544 | {"ecdsap521", R_EC_P521}, | |
545 | {"ecdsak163", R_EC_K163}, | |
546 | {"ecdsak233", R_EC_K233}, | |
547 | {"ecdsak283", R_EC_K283}, | |
548 | {"ecdsak409", R_EC_K409}, | |
549 | {"ecdsak571", R_EC_K571}, | |
550 | {"ecdsab163", R_EC_B163}, | |
551 | {"ecdsab233", R_EC_B233}, | |
552 | {"ecdsab283", R_EC_B283}, | |
553 | {"ecdsab409", R_EC_B409}, | |
554 | {"ecdsab571", R_EC_B571}, | |
555 | {NULL} | |
556 | }; | |
d6073e27 | 557 | |
7e1b7485 RS |
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 | { | |
fb2141c7 | 596 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 613 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 630 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 647 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 658 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 675 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 686 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 697 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 709 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 722 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 739 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 755 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 766 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 783 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 795 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 807 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 819 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 832 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 845 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 858 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 871 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 894 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 914 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 934 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 957 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 977 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 AG |
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 | { | |
fb2141c7 | 1000 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 1021 | loopargs_t *tempargs = *(loopargs_t **)args; |
8b0b80d9 | 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 | { | |
fb2141c7 | 1045 | loopargs_t *tempargs = *(loopargs_t **)args; |
0ff43435 AG |
1046 | EC_KEY **ecdh_a = tempargs->ecdh_a; |
1047 | EC_KEY **ecdh_b = tempargs->ecdh_b; | |
1048 | unsigned char *secret_a = tempargs->secret_a; | |
358558eb CS |
1049 | int count; |
1050 | size_t outlen = tempargs->outlen; | |
3331e43b F |
1051 | kdf_fn kdf = tempargs->kdf; |
1052 | ||
8b0b80d9 AG |
1053 | for (count = 0; COND(ecdh_c[testnum][0]); count++) { |
1054 | ECDH_compute_key(secret_a, outlen, | |
1055 | EC_KEY_get0_public_key(ecdh_b[testnum]), | |
1056 | ecdh_a[testnum], kdf); | |
1057 | } | |
1058 | return count; | |
1059 | } | |
5f986ed3 | 1060 | |
358558eb | 1061 | static const size_t KDF1_SHA1_len = 20; |
5f986ed3 F |
1062 | static void *KDF1_SHA1(const void *in, size_t inlen, void *out, |
1063 | size_t *outlen) | |
1064 | { | |
1065 | if (*outlen < SHA_DIGEST_LENGTH) | |
1066 | return NULL; | |
1067 | *outlen = SHA_DIGEST_LENGTH; | |
1068 | return SHA1(in, inlen, out); | |
1069 | } | |
d6073e27 | 1070 | #endif /* OPENSSL_NO_EC */ |
8b0b80d9 | 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) { |
fb2141c7 | 1085 | return loop_function((void *)&loopargs); |
8b0b80d9 AG |
1086 | } |
1087 | ||
1088 | for (i = 0; i < async_jobs && !error; i++) { | |
fb2141c7 F |
1089 | loopargs_t *looparg_item = loopargs + i; |
1090 | ||
1091 | /* Copy pointer content (looparg_t item address) into async context */ | |
700b8145 F |
1092 | ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx, |
1093 | &job_op_count, loop_function, | |
fb2141c7 | 1094 | (void *)&looparg_item, sizeof(looparg_item)); |
700b8145 | 1095 | switch (ret) { |
fd4b0c08 F |
1096 | case ASYNC_PAUSE: |
1097 | ++num_inprogress; | |
1098 | break; | |
1099 | case ASYNC_FINISH: | |
1100 | if (job_op_count == -1) { | |
8b0b80d9 | 1101 | error = 1; |
fd4b0c08 F |
1102 | } else { |
1103 | total_op_count += job_op_count; | |
1104 | } | |
1105 | break; | |
1106 | case ASYNC_NO_JOBS: | |
1107 | case ASYNC_ERR: | |
1108 | BIO_printf(bio_err, "Failure in the job\n"); | |
1109 | ERR_print_errors(bio_err); | |
1110 | error = 1; | |
1111 | break; | |
8b0b80d9 AG |
1112 | } |
1113 | } | |
1114 | ||
1115 | while (num_inprogress > 0) { | |
2ea92604 | 1116 | #if defined(OPENSSL_SYS_WINDOWS) |
564e1029 | 1117 | DWORD avail = 0; |
2ea92604 | 1118 | #elif defined(OPENSSL_SYS_UNIX) |
8b0b80d9 | 1119 | int select_result = 0; |
564e1029 AG |
1120 | OSSL_ASYNC_FD max_fd = 0; |
1121 | fd_set waitfdset; | |
363a1fc6 | 1122 | |
564e1029 | 1123 | FD_ZERO(&waitfdset); |
1e613922 | 1124 | |
564e1029 AG |
1125 | for (i = 0; i < async_jobs && num_inprogress > 0; i++) { |
1126 | if (loopargs[i].inprogress_job == NULL) | |
1127 | continue; | |
1e613922 | 1128 | |
564e1029 AG |
1129 | if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds) |
1130 | || num_job_fds > 1) { | |
1131 | BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); | |
1132 | ERR_print_errors(bio_err); | |
1133 | error = 1; | |
1134 | break; | |
8b0b80d9 | 1135 | } |
564e1029 AG |
1136 | ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds); |
1137 | FD_SET(job_fd, &waitfdset); | |
1138 | if (job_fd > max_fd) | |
1139 | max_fd = job_fd; | |
8b0b80d9 | 1140 | } |
8b0b80d9 | 1141 | |
402ec2f5 | 1142 | if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) { |
570c0716 AG |
1143 | BIO_printf(bio_err, |
1144 | "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). " | |
1145 | "Decrease the value of async_jobs\n", | |
1146 | max_fd, FD_SETSIZE); | |
1147 | ERR_print_errors(bio_err); | |
1148 | error = 1; | |
1149 | break; | |
1150 | } | |
1151 | ||
564e1029 | 1152 | select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL); |
8b0b80d9 AG |
1153 | if (select_result == -1 && errno == EINTR) |
1154 | continue; | |
1155 | ||
1156 | if (select_result == -1) { | |
564e1029 AG |
1157 | BIO_printf(bio_err, "Failure in the select\n"); |
1158 | ERR_print_errors(bio_err); | |
1159 | error = 1; | |
1160 | break; | |
8b0b80d9 AG |
1161 | } |
1162 | ||
1163 | if (select_result == 0) | |
1164 | continue; | |
8b0b80d9 AG |
1165 | #endif |
1166 | ||
1167 | for (i = 0; i < async_jobs; i++) { | |
1168 | if (loopargs[i].inprogress_job == NULL) | |
1169 | continue; | |
1170 | ||
1e613922 AG |
1171 | if (!ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, NULL, &num_job_fds) |
1172 | || num_job_fds > 1) { | |
1173 | BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n"); | |
1174 | ERR_print_errors(bio_err); | |
1175 | error = 1; | |
1176 | break; | |
1177 | } | |
1178 | ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds); | |
8b0b80d9 | 1179 | |
667867cc | 1180 | #if defined(OPENSSL_SYS_UNIX) |
1e613922 | 1181 | if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset)) |
8b0b80d9 | 1182 | continue; |
667867cc | 1183 | #elif defined(OPENSSL_SYS_WINDOWS) |
fd4b0c08 | 1184 | if (num_job_fds == 1 |
700b8145 | 1185 | && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) |
fd4b0c08 | 1186 | && avail > 0) |
8b0b80d9 AG |
1187 | continue; |
1188 | #endif | |
1189 | ||
609b0852 DB |
1190 | ret = ASYNC_start_job(&loopargs[i].inprogress_job, |
1191 | loopargs[i].wait_ctx, &job_op_count, loop_function, | |
700b8145 F |
1192 | (void *)(loopargs + i), sizeof(loopargs_t)); |
1193 | switch (ret) { | |
fd4b0c08 F |
1194 | case ASYNC_PAUSE: |
1195 | break; | |
1196 | case ASYNC_FINISH: | |
1197 | if (job_op_count == -1) { | |
8b0b80d9 | 1198 | error = 1; |
fd4b0c08 F |
1199 | } else { |
1200 | total_op_count += job_op_count; | |
1201 | } | |
1202 | --num_inprogress; | |
1203 | loopargs[i].inprogress_job = NULL; | |
1204 | break; | |
1205 | case ASYNC_NO_JOBS: | |
1206 | case ASYNC_ERR: | |
1207 | --num_inprogress; | |
1208 | loopargs[i].inprogress_job = NULL; | |
1209 | BIO_printf(bio_err, "Failure in the job\n"); | |
1210 | ERR_print_errors(bio_err); | |
1211 | error = 1; | |
1212 | break; | |
8b0b80d9 AG |
1213 | } |
1214 | } | |
1215 | } | |
1216 | ||
1217 | return error ? -1 : total_op_count; | |
1218 | } | |
1219 | ||
1220 | int speed_main(int argc, char **argv) | |
1221 | { | |
1222 | loopargs_t *loopargs = NULL; | |
dab1f5fe | 1223 | int async_init = 0; |
8b0b80d9 AG |
1224 | int loopargs_len = 0; |
1225 | char *prog; | |
19075d58 F |
1226 | #ifndef OPENSSL_NO_ENGINE |
1227 | const char *engine_id = NULL; | |
1228 | #endif | |
8b0b80d9 AG |
1229 | const EVP_CIPHER *evp_cipher = NULL; |
1230 | double d = 0.0; | |
1231 | OPTION_CHOICE o; | |
4d82c58b F |
1232 | int multiblock = 0, pr_header = 0; |
1233 | int doit[ALGOR_NUM] = { 0 }; | |
8b0b80d9 | 1234 | int ret = 1, i, k, misalign = 0; |
19075d58 | 1235 | long count = 0; |
8b0b80d9 AG |
1236 | #ifndef NO_FORK |
1237 | int multi = 0; | |
1238 | #endif | |
1239 | int async_jobs = 0; | |
5f986ed3 F |
1240 | #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \ |
1241 | || !defined(OPENSSL_NO_EC) | |
0ff43435 | 1242 | long rsa_count = 1; |
a00ae6c4 | 1243 | #endif |
5f986ed3 F |
1244 | |
1245 | /* What follows are the buffers and key material. */ | |
a00ae6c4 | 1246 | #ifndef OPENSSL_NO_RC5 |
0f113f3e | 1247 | RC5_32_KEY rc5_ks; |
a00ae6c4 RS |
1248 | #endif |
1249 | #ifndef OPENSSL_NO_RC2 | |
0f113f3e | 1250 | RC2_KEY rc2_ks; |
a00ae6c4 RS |
1251 | #endif |
1252 | #ifndef OPENSSL_NO_IDEA | |
0f113f3e | 1253 | IDEA_KEY_SCHEDULE idea_ks; |
a00ae6c4 RS |
1254 | #endif |
1255 | #ifndef OPENSSL_NO_SEED | |
0f113f3e | 1256 | SEED_KEY_SCHEDULE seed_ks; |
a00ae6c4 RS |
1257 | #endif |
1258 | #ifndef OPENSSL_NO_BF | |
0f113f3e | 1259 | BF_KEY bf_ks; |
a00ae6c4 RS |
1260 | #endif |
1261 | #ifndef OPENSSL_NO_CAST | |
0f113f3e | 1262 | CAST_KEY cast_ks; |
a00ae6c4 | 1263 | #endif |
0f113f3e MC |
1264 | static const unsigned char key16[16] = { |
1265 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | |
1266 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 | |
1267 | }; | |
0f113f3e MC |
1268 | static const unsigned char key24[24] = { |
1269 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | |
1270 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, | |
1271 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 | |
1272 | }; | |
1273 | static const unsigned char key32[32] = { | |
1274 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | |
1275 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, | |
1276 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, | |
1277 | 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 | |
1278 | }; | |
a00ae6c4 | 1279 | #ifndef OPENSSL_NO_CAMELLIA |
0f113f3e MC |
1280 | static const unsigned char ckey24[24] = { |
1281 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | |
1282 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, | |
1283 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 | |
1284 | }; | |
1285 | static const unsigned char ckey32[32] = { | |
1286 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | |
1287 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, | |
1288 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, | |
1289 | 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 | |
1290 | }; | |
7e1b7485 | 1291 | CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3; |
a00ae6c4 | 1292 | #endif |
a00ae6c4 | 1293 | #ifndef OPENSSL_NO_DES |
7e1b7485 RS |
1294 | static DES_cblock key = { |
1295 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 | |
1296 | }; | |
1297 | static DES_cblock key2 = { | |
1298 | 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 | |
1299 | }; | |
1300 | static DES_cblock key3 = { | |
1301 | 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 | |
1302 | }; | |
a00ae6c4 | 1303 | #endif |
a00ae6c4 | 1304 | #ifndef OPENSSL_NO_RSA |
4d82c58b | 1305 | static const unsigned int rsa_bits[RSA_NUM] = { |
0f113f3e MC |
1306 | 512, 1024, 2048, 3072, 4096, 7680, 15360 |
1307 | }; | |
4d82c58b | 1308 | static const unsigned char *rsa_data[RSA_NUM] = { |
0f113f3e MC |
1309 | test512, test1024, test2048, test3072, test4096, test7680, test15360 |
1310 | }; | |
4d82c58b | 1311 | static const int rsa_data_length[RSA_NUM] = { |
0f113f3e MC |
1312 | sizeof(test512), sizeof(test1024), |
1313 | sizeof(test2048), sizeof(test3072), | |
1314 | sizeof(test4096), sizeof(test7680), | |
1315 | sizeof(test15360) | |
1316 | }; | |
5f986ed3 | 1317 | int rsa_doit[RSA_NUM] = { 0 }; |
a00ae6c4 RS |
1318 | #endif |
1319 | #ifndef OPENSSL_NO_DSA | |
4d82c58b | 1320 | static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 }; |
5f986ed3 | 1321 | int dsa_doit[DSA_NUM] = { 0 }; |
a00ae6c4 RS |
1322 | #endif |
1323 | #ifndef OPENSSL_NO_EC | |
0f113f3e MC |
1324 | /* |
1325 | * We only test over the following curves as they are representative, To | |
1326 | * add tests over more curves, simply add the curve NID and curve name to | |
1327 | * the following arrays and increase the EC_NUM value accordingly. | |
1328 | */ | |
4d82c58b | 1329 | static const unsigned int test_curves[EC_NUM] = { |
0f113f3e | 1330 | /* Prime Curves */ |
7e1b7485 RS |
1331 | NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1, |
1332 | NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1, | |
0f113f3e | 1333 | /* Binary Curves */ |
7e1b7485 RS |
1334 | NID_sect163k1, NID_sect233k1, NID_sect283k1, |
1335 | NID_sect409k1, NID_sect571k1, NID_sect163r2, | |
1336 | NID_sect233r1, NID_sect283r1, NID_sect409r1, | |
db50c1da DSH |
1337 | NID_sect571r1, |
1338 | /* Other */ | |
1339 | NID_X25519 | |
0f113f3e MC |
1340 | }; |
1341 | static const char *test_curves_names[EC_NUM] = { | |
1342 | /* Prime Curves */ | |
7e1b7485 RS |
1343 | "secp160r1", "nistp192", "nistp224", |
1344 | "nistp256", "nistp384", "nistp521", | |
0f113f3e | 1345 | /* Binary Curves */ |
7e1b7485 RS |
1346 | "nistk163", "nistk233", "nistk283", |
1347 | "nistk409", "nistk571", "nistb163", | |
1348 | "nistb233", "nistb283", "nistb409", | |
db50c1da DSH |
1349 | "nistb571", |
1350 | /* Other */ | |
1351 | "X25519" | |
0f113f3e | 1352 | }; |
4d82c58b | 1353 | static const int test_curves_bits[EC_NUM] = { |
7e1b7485 RS |
1354 | 160, 192, 224, |
1355 | 256, 384, 521, | |
1356 | 163, 233, 283, | |
1357 | 409, 571, 163, | |
1358 | 233, 283, 409, | |
db50c1da | 1359 | 571, 253 /* X25519 */ |
0f113f3e | 1360 | }; |
d02b48c6 | 1361 | |
4d82c58b F |
1362 | int ecdsa_doit[EC_NUM] = { 0 }; |
1363 | int ecdh_doit[EC_NUM] = { 0 }; | |
d6073e27 | 1364 | #endif /* ndef OPENSSL_NO_EC */ |
7e1b7485 RS |
1365 | |
1366 | prog = opt_init(argc, argv, speed_options); | |
1367 | while ((o = opt_next()) != OPT_EOF) { | |
1368 | switch (o) { | |
1369 | case OPT_EOF: | |
1370 | case OPT_ERR: | |
1371 | opterr: | |
1372 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
1373 | goto end; | |
1374 | case OPT_HELP: | |
1375 | opt_help(speed_options); | |
1376 | ret = 0; | |
1377 | goto end; | |
1378 | case OPT_ELAPSED: | |
0f113f3e | 1379 | usertime = 0; |
7e1b7485 RS |
1380 | break; |
1381 | case OPT_EVP: | |
1382 | evp_cipher = EVP_get_cipherbyname(opt_arg()); | |
1383 | if (evp_cipher == NULL) | |
1384 | evp_md = EVP_get_digestbyname(opt_arg()); | |
1385 | if (evp_cipher == NULL && evp_md == NULL) { | |
1386 | BIO_printf(bio_err, | |
55b09fe6 | 1387 | "%s: %s is an unknown cipher or digest\n", |
7e1b7485 | 1388 | prog, opt_arg()); |
0f113f3e MC |
1389 | goto end; |
1390 | } | |
1391 | doit[D_EVP] = 1; | |
7e1b7485 RS |
1392 | break; |
1393 | case OPT_DECRYPT: | |
0f113f3e | 1394 | decrypt = 1; |
7e1b7485 | 1395 | break; |
7e1b7485 | 1396 | case OPT_ENGINE: |
8b0b80d9 AG |
1397 | /* |
1398 | * In a forked execution, an engine might need to be | |
1399 | * initialised by each child process, not by the parent. | |
1400 | * So store the name here and run setup_engine() later on. | |
1401 | */ | |
19075d58 | 1402 | #ifndef OPENSSL_NO_ENGINE |
8b0b80d9 | 1403 | engine_id = opt_arg(); |
19075d58 | 1404 | #endif |
7e1b7485 | 1405 | break; |
7e1b7485 | 1406 | case OPT_MULTI: |
9c3bcfa0 | 1407 | #ifndef NO_FORK |
7e1b7485 | 1408 | multi = atoi(opt_arg()); |
8b0b80d9 AG |
1409 | #endif |
1410 | break; | |
1411 | case OPT_ASYNCJOBS: | |
667867cc | 1412 | #ifndef OPENSSL_NO_ASYNC |
8b0b80d9 | 1413 | async_jobs = atoi(opt_arg()); |
667867cc MC |
1414 | if (!ASYNC_is_capable()) { |
1415 | BIO_printf(bio_err, | |
1416 | "%s: async_jobs specified but async not supported\n", | |
1417 | prog); | |
1418 | goto opterr; | |
1419 | } | |
a00ae6c4 | 1420 | #endif |
9c3bcfa0 | 1421 | break; |
7e1b7485 RS |
1422 | case OPT_MISALIGN: |
1423 | if (!opt_int(opt_arg(), &misalign)) | |
0f113f3e | 1424 | goto end; |
7e1b7485 | 1425 | if (misalign > MISALIGN) { |
0f113f3e | 1426 | BIO_printf(bio_err, |
7e1b7485 RS |
1427 | "%s: Maximum offset is %d\n", prog, MISALIGN); |
1428 | goto opterr; | |
0f113f3e | 1429 | } |
7e1b7485 RS |
1430 | break; |
1431 | case OPT_MR: | |
1432 | mr = 1; | |
1433 | break; | |
1434 | case OPT_MB: | |
1435 | multiblock = 1; | |
cfd451d4 F |
1436 | #ifdef OPENSSL_NO_MULTIBLOCK |
1437 | BIO_printf(bio_err, | |
1438 | "%s: -mb specified but multi-block support is disabled\n", | |
1439 | prog); | |
1440 | goto end; | |
1441 | #endif | |
7e1b7485 RS |
1442 | break; |
1443 | } | |
1444 | } | |
1445 | argc = opt_num_rest(); | |
1446 | argv = opt_rest(); | |
1447 | ||
1448 | /* Remaining arguments are algorithms. */ | |
1449 | for ( ; *argv; argv++) { | |
1450 | if (found(*argv, doit_choices, &i)) { | |
1451 | doit[i] = 1; | |
1452 | continue; | |
1453 | } | |
a00ae6c4 | 1454 | #ifndef OPENSSL_NO_DES |
7e1b7485 RS |
1455 | if (strcmp(*argv, "des") == 0) { |
1456 | doit[D_CBC_DES] = doit[D_EDE3_DES] = 1; | |
1457 | continue; | |
1458 | } | |
a00ae6c4 | 1459 | #endif |
7e1b7485 RS |
1460 | if (strcmp(*argv, "sha") == 0) { |
1461 | doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1; | |
1462 | continue; | |
1463 | } | |
a00ae6c4 | 1464 | #ifndef OPENSSL_NO_RSA |
a00ae6c4 | 1465 | # ifndef RSA_NULL |
0f113f3e | 1466 | if (strcmp(*argv, "openssl") == 0) { |
b0700d2c | 1467 | RSA_set_default_method(RSA_PKCS1_OpenSSL()); |
7e1b7485 RS |
1468 | continue; |
1469 | } | |
a00ae6c4 | 1470 | # endif |
7e1b7485 RS |
1471 | if (strcmp(*argv, "rsa") == 0) { |
1472 | rsa_doit[R_RSA_512] = rsa_doit[R_RSA_1024] = | |
1473 | rsa_doit[R_RSA_2048] = rsa_doit[R_RSA_3072] = | |
1474 | rsa_doit[R_RSA_4096] = rsa_doit[R_RSA_7680] = | |
1475 | rsa_doit[R_RSA_15360] = 1; | |
1476 | continue; | |
1477 | } | |
1478 | if (found(*argv, rsa_choices, &i)) { | |
1479 | rsa_doit[i] = 1; | |
1480 | continue; | |
1481 | } | |
a00ae6c4 | 1482 | #endif |
7e1b7485 RS |
1483 | #ifndef OPENSSL_NO_DSA |
1484 | if (strcmp(*argv, "dsa") == 0) { | |
1485 | dsa_doit[R_DSA_512] = dsa_doit[R_DSA_1024] = | |
1486 | dsa_doit[R_DSA_2048] = 1; | |
1487 | continue; | |
1488 | } | |
1489 | if (found(*argv, dsa_choices, &i)) { | |
1490 | dsa_doit[i] = 2; | |
1491 | continue; | |
1492 | } | |
a00ae6c4 | 1493 | #endif |
0f113f3e | 1494 | if (strcmp(*argv, "aes") == 0) { |
7e1b7485 RS |
1495 | doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = |
1496 | doit[D_CBC_256_AES] = 1; | |
1497 | continue; | |
1498 | } | |
a00ae6c4 | 1499 | #ifndef OPENSSL_NO_CAMELLIA |
0f113f3e | 1500 | if (strcmp(*argv, "camellia") == 0) { |
7e1b7485 RS |
1501 | doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = |
1502 | doit[D_CBC_256_CML] = 1; | |
1503 | continue; | |
1504 | } | |
a00ae6c4 | 1505 | #endif |
10bf4fc2 | 1506 | #ifndef OPENSSL_NO_EC |
7e1b7485 | 1507 | if (strcmp(*argv, "ecdsa") == 0) { |
0f113f3e MC |
1508 | for (i = 0; i < EC_NUM; i++) |
1509 | ecdsa_doit[i] = 1; | |
7e1b7485 RS |
1510 | continue; |
1511 | } | |
1512 | if (found(*argv, ecdsa_choices, &i)) { | |
1513 | ecdsa_doit[i] = 2; | |
1514 | continue; | |
1515 | } | |
1516 | if (strcmp(*argv, "ecdh") == 0) { | |
0f113f3e MC |
1517 | for (i = 0; i < EC_NUM; i++) |
1518 | ecdh_doit[i] = 1; | |
7e1b7485 RS |
1519 | continue; |
1520 | } | |
1521 | if (found(*argv, ecdh_choices, &i)) { | |
1522 | ecdh_doit[i] = 2; | |
1523 | continue; | |
0f113f3e | 1524 | } |
7e1b7485 RS |
1525 | #endif |
1526 | BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv); | |
1527 | goto end; | |
0f113f3e | 1528 | } |
d02b48c6 | 1529 | |
8b0b80d9 AG |
1530 | /* Initialize the job pool if async mode is enabled */ |
1531 | if (async_jobs > 0) { | |
dab1f5fe CS |
1532 | async_init = ASYNC_init_thread(async_jobs, async_jobs); |
1533 | if (!async_init) { | |
8b0b80d9 AG |
1534 | BIO_printf(bio_err, "Error creating the ASYNC job pool\n"); |
1535 | goto end; | |
1536 | } | |
1537 | } | |
1538 | ||
1539 | loopargs_len = (async_jobs == 0 ? 1 : async_jobs); | |
1540 | loopargs = app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs"); | |
1541 | memset(loopargs, 0, loopargs_len * sizeof(loopargs_t)); | |
1542 | ||
0ff43435 | 1543 | for (i = 0; i < loopargs_len; i++) { |
1e613922 AG |
1544 | if (async_jobs > 0) { |
1545 | loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new(); | |
1546 | if (loopargs[i].wait_ctx == NULL) { | |
1547 | BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n"); | |
1548 | goto end; | |
1549 | } | |
1550 | } | |
1551 | ||
8b0b80d9 AG |
1552 | loopargs[i].buf_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer"); |
1553 | loopargs[i].buf2_malloc = app_malloc((int)BUFSIZE + MAX_MISALIGNMENT + 1, "input buffer"); | |
1554 | /* Align the start of buffers on a 64 byte boundary */ | |
1555 | loopargs[i].buf = loopargs[i].buf_malloc + misalign; | |
1556 | loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign; | |
0ff43435 | 1557 | #ifndef OPENSSL_NO_EC |
0ff43435 AG |
1558 | loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a"); |
1559 | loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b"); | |
1560 | #endif | |
8b0b80d9 AG |
1561 | } |
1562 | ||
a00ae6c4 | 1563 | #ifndef NO_FORK |
0f113f3e MC |
1564 | if (multi && do_multi(multi)) |
1565 | goto show_res; | |
a00ae6c4 | 1566 | #endif |
d02b48c6 | 1567 | |
8b0b80d9 AG |
1568 | /* Initialize the engine after the fork */ |
1569 | (void)setup_engine(engine_id, 0); | |
1570 | ||
7e1b7485 | 1571 | /* No parameters; turn on everything. */ |
dfba17b4 | 1572 | if ((argc == 0) && !doit[D_EVP]) { |
7e1b7485 | 1573 | for (i = 0; i < ALGOR_NUM; i++) |
0f113f3e MC |
1574 | if (i != D_EVP) |
1575 | doit[i] = 1; | |
d6073e27 | 1576 | #ifndef OPENSSL_NO_RSA |
0f113f3e MC |
1577 | for (i = 0; i < RSA_NUM; i++) |
1578 | rsa_doit[i] = 1; | |
d6073e27 | 1579 | #endif |
83ae8124 | 1580 | #ifndef OPENSSL_NO_DSA |
0f113f3e MC |
1581 | for (i = 0; i < DSA_NUM; i++) |
1582 | dsa_doit[i] = 1; | |
83ae8124 | 1583 | #endif |
10bf4fc2 | 1584 | #ifndef OPENSSL_NO_EC |
0f113f3e MC |
1585 | for (i = 0; i < EC_NUM; i++) |
1586 | ecdsa_doit[i] = 1; | |
0f113f3e MC |
1587 | for (i = 0; i < EC_NUM; i++) |
1588 | ecdh_doit[i] = 1; | |
a00ae6c4 | 1589 | #endif |
0f113f3e MC |
1590 | } |
1591 | for (i = 0; i < ALGOR_NUM; i++) | |
1592 | if (doit[i]) | |
1593 | pr_header++; | |
1594 | ||
1595 | if (usertime == 0 && !mr) | |
1596 | BIO_printf(bio_err, | |
1597 | "You have chosen to measure elapsed time " | |
1598 | "instead of user CPU time.\n"); | |
1599 | ||
a00ae6c4 | 1600 | #ifndef OPENSSL_NO_RSA |
0ff43435 AG |
1601 | for (i = 0; i < loopargs_len; i++) { |
1602 | for (k = 0; k < RSA_NUM; k++) { | |
1603 | const unsigned char *p; | |
1604 | ||
1605 | p = rsa_data[k]; | |
1606 | loopargs[i].rsa_key[k] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]); | |
1607 | if (loopargs[i].rsa_key[k] == NULL) { | |
1608 | BIO_printf(bio_err, "internal error loading RSA key number %d\n", | |
1609 | k); | |
1610 | goto end; | |
1611 | } | |
0f113f3e | 1612 | } |
a00ae6c4 RS |
1613 | } |
1614 | #endif | |
a00ae6c4 | 1615 | #ifndef OPENSSL_NO_DSA |
0ff43435 AG |
1616 | for (i = 0; i < loopargs_len; i++) { |
1617 | loopargs[i].dsa_key[0] = get_dsa512(); | |
1618 | loopargs[i].dsa_key[1] = get_dsa1024(); | |
1619 | loopargs[i].dsa_key[2] = get_dsa2048(); | |
1620 | } | |
a00ae6c4 | 1621 | #endif |
a00ae6c4 | 1622 | #ifndef OPENSSL_NO_DES |
0f113f3e MC |
1623 | DES_set_key_unchecked(&key, &sch); |
1624 | DES_set_key_unchecked(&key2, &sch2); | |
1625 | DES_set_key_unchecked(&key3, &sch3); | |
a00ae6c4 | 1626 | #endif |
0f113f3e MC |
1627 | AES_set_encrypt_key(key16, 128, &aes_ks1); |
1628 | AES_set_encrypt_key(key24, 192, &aes_ks2); | |
1629 | AES_set_encrypt_key(key32, 256, &aes_ks3); | |
a00ae6c4 | 1630 | #ifndef OPENSSL_NO_CAMELLIA |
0f113f3e MC |
1631 | Camellia_set_key(key16, 128, &camellia_ks1); |
1632 | Camellia_set_key(ckey24, 192, &camellia_ks2); | |
1633 | Camellia_set_key(ckey32, 256, &camellia_ks3); | |
a00ae6c4 RS |
1634 | #endif |
1635 | #ifndef OPENSSL_NO_IDEA | |
9021a5df | 1636 | IDEA_set_encrypt_key(key16, &idea_ks); |
a00ae6c4 RS |
1637 | #endif |
1638 | #ifndef OPENSSL_NO_SEED | |
0f113f3e | 1639 | SEED_set_key(key16, &seed_ks); |
a00ae6c4 RS |
1640 | #endif |
1641 | #ifndef OPENSSL_NO_RC4 | |
0f113f3e | 1642 | RC4_set_key(&rc4_ks, 16, key16); |
a00ae6c4 RS |
1643 | #endif |
1644 | #ifndef OPENSSL_NO_RC2 | |
0f113f3e | 1645 | RC2_set_key(&rc2_ks, 16, key16, 128); |
a00ae6c4 RS |
1646 | #endif |
1647 | #ifndef OPENSSL_NO_RC5 | |
0f113f3e | 1648 | RC5_32_set_key(&rc5_ks, 16, key16, 12); |
a00ae6c4 RS |
1649 | #endif |
1650 | #ifndef OPENSSL_NO_BF | |
0f113f3e | 1651 | BF_set_key(&bf_ks, 16, key16); |
a00ae6c4 RS |
1652 | #endif |
1653 | #ifndef OPENSSL_NO_CAST | |
0f113f3e | 1654 | CAST_set_key(&cast_ks, 16, key16); |
a00ae6c4 | 1655 | #endif |
a00ae6c4 RS |
1656 | #ifndef SIGALRM |
1657 | # ifndef OPENSSL_NO_DES | |
0f113f3e MC |
1658 | BIO_printf(bio_err, "First we calculate the approximate speed ...\n"); |
1659 | count = 10; | |
1660 | do { | |
1661 | long it; | |
1662 | count *= 2; | |
1663 | Time_F(START); | |
1664 | for (it = count; it; it--) | |
8b0b80d9 AG |
1665 | DES_ecb_encrypt((DES_cblock *)loopargs[0].buf, |
1666 | (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT); | |
0f113f3e MC |
1667 | d = Time_F(STOP); |
1668 | } while (d < 3); | |
1669 | save_count = count; | |
1670 | c[D_MD2][0] = count / 10; | |
1671 | c[D_MDC2][0] = count / 10; | |
1672 | c[D_MD4][0] = count; | |
1673 | c[D_MD5][0] = count; | |
1674 | c[D_HMAC][0] = count; | |
1675 | c[D_SHA1][0] = count; | |
1676 | c[D_RMD160][0] = count; | |
1677 | c[D_RC4][0] = count * 5; | |
1678 | c[D_CBC_DES][0] = count; | |
1679 | c[D_EDE3_DES][0] = count / 3; | |
1680 | c[D_CBC_IDEA][0] = count; | |
1681 | c[D_CBC_SEED][0] = count; | |
1682 | c[D_CBC_RC2][0] = count; | |
1683 | c[D_CBC_RC5][0] = count; | |
1684 | c[D_CBC_BF][0] = count; | |
1685 | c[D_CBC_CAST][0] = count; | |
1686 | c[D_CBC_128_AES][0] = count; | |
1687 | c[D_CBC_192_AES][0] = count; | |
1688 | c[D_CBC_256_AES][0] = count; | |
1689 | c[D_CBC_128_CML][0] = count; | |
1690 | c[D_CBC_192_CML][0] = count; | |
1691 | c[D_CBC_256_CML][0] = count; | |
1692 | c[D_SHA256][0] = count; | |
1693 | c[D_SHA512][0] = count; | |
1694 | c[D_WHIRLPOOL][0] = count; | |
1695 | c[D_IGE_128_AES][0] = count; | |
1696 | c[D_IGE_192_AES][0] = count; | |
1697 | c[D_IGE_256_AES][0] = count; | |
1698 | c[D_GHASH][0] = count; | |
1699 | ||
1700 | for (i = 1; i < SIZE_NUM; i++) { | |
1701 | long l0, l1; | |
1702 | ||
1703 | l0 = (long)lengths[0]; | |
1704 | l1 = (long)lengths[i]; | |
1705 | ||
1706 | c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1; | |
1707 | c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1; | |
1708 | c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1; | |
1709 | c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1; | |
1710 | c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1; | |
1711 | c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1; | |
1712 | c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1; | |
1713 | c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1; | |
1714 | c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1; | |
1715 | c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1; | |
6d9843e7 | 1716 | c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1; |
0f113f3e MC |
1717 | |
1718 | l0 = (long)lengths[i - 1]; | |
1719 | ||
1720 | c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1; | |
1721 | c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1; | |
1722 | c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1; | |
1723 | c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1; | |
1724 | c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1; | |
1725 | c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1; | |
1726 | c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1; | |
1727 | c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1; | |
1728 | c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1; | |
1729 | c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1; | |
1730 | c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1; | |
1731 | c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1; | |
1732 | c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1; | |
1733 | c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1; | |
1734 | c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1; | |
1735 | c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1; | |
1736 | c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1; | |
1737 | c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1; | |
1738 | } | |
e172d60d | 1739 | |
a00ae6c4 | 1740 | # ifndef OPENSSL_NO_RSA |
0f113f3e MC |
1741 | rsa_c[R_RSA_512][0] = count / 2000; |
1742 | rsa_c[R_RSA_512][1] = count / 400; | |
1743 | for (i = 1; i < RSA_NUM; i++) { | |
1744 | rsa_c[i][0] = rsa_c[i - 1][0] / 8; | |
1745 | rsa_c[i][1] = rsa_c[i - 1][1] / 4; | |
70c4e156 | 1746 | if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0) |
0f113f3e MC |
1747 | rsa_doit[i] = 0; |
1748 | else { | |
1749 | if (rsa_c[i][0] == 0) { | |
70c4e156 | 1750 | rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */ |
0f113f3e MC |
1751 | rsa_c[i][1] = 20; |
1752 | } | |
1753 | } | |
1754 | } | |
a00ae6c4 | 1755 | # endif |
0f113f3e | 1756 | |
a00ae6c4 | 1757 | # ifndef OPENSSL_NO_DSA |
0f113f3e MC |
1758 | dsa_c[R_DSA_512][0] = count / 1000; |
1759 | dsa_c[R_DSA_512][1] = count / 1000 / 2; | |
1760 | for (i = 1; i < DSA_NUM; i++) { | |
1761 | dsa_c[i][0] = dsa_c[i - 1][0] / 4; | |
1762 | dsa_c[i][1] = dsa_c[i - 1][1] / 4; | |
70c4e156 | 1763 | if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0) |
0f113f3e MC |
1764 | dsa_doit[i] = 0; |
1765 | else { | |
70c4e156 F |
1766 | if (dsa_c[i][0] == 0) { |
1767 | dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */ | |
0f113f3e MC |
1768 | dsa_c[i][1] = 1; |
1769 | } | |
1770 | } | |
1771 | } | |
a00ae6c4 | 1772 | # endif |
0f113f3e | 1773 | |
10bf4fc2 | 1774 | # ifndef OPENSSL_NO_EC |
0f113f3e MC |
1775 | ecdsa_c[R_EC_P160][0] = count / 1000; |
1776 | ecdsa_c[R_EC_P160][1] = count / 1000 / 2; | |
1777 | for (i = R_EC_P192; i <= R_EC_P521; i++) { | |
1778 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; | |
1779 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; | |
70c4e156 | 1780 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
0f113f3e MC |
1781 | ecdsa_doit[i] = 0; |
1782 | else { | |
70c4e156 | 1783 | if (ecdsa_c[i][0] == 0) { |
0f113f3e MC |
1784 | ecdsa_c[i][0] = 1; |
1785 | ecdsa_c[i][1] = 1; | |
1786 | } | |
1787 | } | |
1788 | } | |
1789 | ecdsa_c[R_EC_K163][0] = count / 1000; | |
1790 | ecdsa_c[R_EC_K163][1] = count / 1000 / 2; | |
1791 | for (i = R_EC_K233; i <= R_EC_K571; i++) { | |
1792 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; | |
1793 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; | |
70c4e156 | 1794 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
0f113f3e MC |
1795 | ecdsa_doit[i] = 0; |
1796 | else { | |
70c4e156 | 1797 | if (ecdsa_c[i][0] == 0) { |
0f113f3e MC |
1798 | ecdsa_c[i][0] = 1; |
1799 | ecdsa_c[i][1] = 1; | |
1800 | } | |
1801 | } | |
1802 | } | |
1803 | ecdsa_c[R_EC_B163][0] = count / 1000; | |
1804 | ecdsa_c[R_EC_B163][1] = count / 1000 / 2; | |
1805 | for (i = R_EC_B233; i <= R_EC_B571; i++) { | |
1806 | ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; | |
1807 | ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; | |
70c4e156 | 1808 | if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0) |
0f113f3e MC |
1809 | ecdsa_doit[i] = 0; |
1810 | else { | |
70c4e156 | 1811 | if (ecdsa_c[i][0] == 0) { |
0f113f3e MC |
1812 | ecdsa_c[i][0] = 1; |
1813 | ecdsa_c[i][1] = 1; | |
1814 | } | |
1815 | } | |
1816 | } | |
7e1b7485 | 1817 | |
0f113f3e | 1818 | ecdh_c[R_EC_P160][0] = count / 1000; |
0f113f3e MC |
1819 | for (i = R_EC_P192; i <= R_EC_P521; 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_K163][0] = count / 1000; | |
0f113f3e MC |
1830 | for (i = R_EC_K233; i <= R_EC_K571; 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 | } | |
1840 | ecdh_c[R_EC_B163][0] = count / 1000; | |
0f113f3e MC |
1841 | for (i = R_EC_B233; i <= R_EC_B571; i++) { |
1842 | ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; | |
70c4e156 | 1843 | if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0) |
0f113f3e MC |
1844 | ecdh_doit[i] = 0; |
1845 | else { | |
70c4e156 | 1846 | if (ecdh_c[i][0] == 0) { |
0f113f3e | 1847 | ecdh_c[i][0] = 1; |
0f113f3e MC |
1848 | } |
1849 | } | |
1850 | } | |
a00ae6c4 | 1851 | # endif |
e172d60d | 1852 | |
0f113f3e | 1853 | # else |
a00ae6c4 RS |
1854 | /* not worth fixing */ |
1855 | # error "You cannot disable DES on systems without SIGALRM." | |
1856 | # endif /* OPENSSL_NO_DES */ | |
1857 | #else | |
a00ae6c4 | 1858 | # ifndef _WIN32 |
0f113f3e | 1859 | signal(SIGALRM, sig_done); |
a00ae6c4 RS |
1860 | # endif |
1861 | #endif /* SIGALRM */ | |
0f113f3e | 1862 | |
a00ae6c4 | 1863 | #ifndef OPENSSL_NO_MD2 |
0f113f3e | 1864 | if (doit[D_MD2]) { |
8b0b80d9 AG |
1865 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1866 | print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum]); | |
0f113f3e | 1867 | Time_F(START); |
8b0b80d9 | 1868 | count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs); |
0f113f3e | 1869 | d = Time_F(STOP); |
8b0b80d9 | 1870 | print_result(D_MD2, testnum, count, d); |
0f113f3e MC |
1871 | } |
1872 | } | |
a00ae6c4 RS |
1873 | #endif |
1874 | #ifndef OPENSSL_NO_MDC2 | |
0f113f3e | 1875 | if (doit[D_MDC2]) { |
8b0b80d9 AG |
1876 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1877 | print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum]); | |
0f113f3e | 1878 | Time_F(START); |
8b0b80d9 | 1879 | count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs); |
0f113f3e | 1880 | d = Time_F(STOP); |
8b0b80d9 | 1881 | print_result(D_MDC2, testnum, count, d); |
0f113f3e MC |
1882 | } |
1883 | } | |
a00ae6c4 | 1884 | #endif |
d02b48c6 | 1885 | |
a00ae6c4 | 1886 | #ifndef OPENSSL_NO_MD4 |
0f113f3e | 1887 | if (doit[D_MD4]) { |
8b0b80d9 AG |
1888 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1889 | print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum]); | |
0f113f3e | 1890 | Time_F(START); |
8b0b80d9 | 1891 | count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs); |
0f113f3e | 1892 | d = Time_F(STOP); |
8b0b80d9 | 1893 | print_result(D_MD4, testnum, count, d); |
0f113f3e MC |
1894 | } |
1895 | } | |
a00ae6c4 | 1896 | #endif |
3009458e | 1897 | |
a00ae6c4 | 1898 | #ifndef OPENSSL_NO_MD5 |
0f113f3e | 1899 | if (doit[D_MD5]) { |
8b0b80d9 AG |
1900 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1901 | print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum]); | |
0f113f3e | 1902 | Time_F(START); |
8b0b80d9 | 1903 | count = run_benchmark(async_jobs, MD5_loop, loopargs); |
0f113f3e | 1904 | d = Time_F(STOP); |
8b0b80d9 | 1905 | print_result(D_MD5, testnum, count, d); |
0f113f3e MC |
1906 | } |
1907 | } | |
d02b48c6 | 1908 | |
0f113f3e | 1909 | if (doit[D_HMAC]) { |
d6073e27 | 1910 | static const char hmac_key[] = "This is a key..."; |
8829ce30 F |
1911 | int len = strlen(hmac_key); |
1912 | ||
0ff43435 | 1913 | for (i = 0; i < loopargs_len; i++) { |
8b0b80d9 AG |
1914 | loopargs[i].hctx = HMAC_CTX_new(); |
1915 | if (loopargs[i].hctx == NULL) { | |
1916 | BIO_printf(bio_err, "HMAC malloc failure, exiting..."); | |
1917 | exit(1); | |
1918 | } | |
0f113f3e | 1919 | |
8829ce30 | 1920 | HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL); |
bf7c6817 | 1921 | } |
8b0b80d9 AG |
1922 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1923 | print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum]); | |
0f113f3e | 1924 | Time_F(START); |
8b0b80d9 | 1925 | count = run_benchmark(async_jobs, HMAC_loop, loopargs); |
0f113f3e | 1926 | d = Time_F(STOP); |
8b0b80d9 AG |
1927 | print_result(D_HMAC, testnum, count, d); |
1928 | } | |
0ff43435 | 1929 | for (i = 0; i < loopargs_len; i++) { |
8b0b80d9 | 1930 | HMAC_CTX_free(loopargs[i].hctx); |
0f113f3e | 1931 | } |
0f113f3e | 1932 | } |
a00ae6c4 | 1933 | #endif |
0f113f3e | 1934 | if (doit[D_SHA1]) { |
8b0b80d9 AG |
1935 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1936 | print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum]); | |
0f113f3e | 1937 | Time_F(START); |
8b0b80d9 | 1938 | count = run_benchmark(async_jobs, SHA1_loop, loopargs); |
0f113f3e | 1939 | d = Time_F(STOP); |
8b0b80d9 | 1940 | print_result(D_SHA1, testnum, count, d); |
0f113f3e MC |
1941 | } |
1942 | } | |
0f113f3e | 1943 | if (doit[D_SHA256]) { |
8b0b80d9 AG |
1944 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1945 | print_message(names[D_SHA256], c[D_SHA256][testnum], lengths[testnum]); | |
0f113f3e | 1946 | Time_F(START); |
8b0b80d9 | 1947 | count = run_benchmark(async_jobs, SHA256_loop, loopargs); |
0f113f3e | 1948 | d = Time_F(STOP); |
8b0b80d9 | 1949 | print_result(D_SHA256, testnum, count, d); |
0f113f3e MC |
1950 | } |
1951 | } | |
0f113f3e | 1952 | if (doit[D_SHA512]) { |
8b0b80d9 AG |
1953 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1954 | print_message(names[D_SHA512], c[D_SHA512][testnum], lengths[testnum]); | |
0f113f3e | 1955 | Time_F(START); |
8b0b80d9 | 1956 | count = run_benchmark(async_jobs, SHA512_loop, loopargs); |
0f113f3e | 1957 | d = Time_F(STOP); |
8b0b80d9 | 1958 | print_result(D_SHA512, testnum, count, d); |
0f113f3e MC |
1959 | } |
1960 | } | |
46ceb15c | 1961 | |
a00ae6c4 | 1962 | #ifndef OPENSSL_NO_WHIRLPOOL |
0f113f3e | 1963 | if (doit[D_WHIRLPOOL]) { |
8b0b80d9 AG |
1964 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1965 | print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum], lengths[testnum]); | |
0f113f3e | 1966 | Time_F(START); |
8b0b80d9 | 1967 | count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs); |
0f113f3e | 1968 | d = Time_F(STOP); |
8b0b80d9 | 1969 | print_result(D_WHIRLPOOL, testnum, count, d); |
0f113f3e MC |
1970 | } |
1971 | } | |
a00ae6c4 | 1972 | #endif |
c88f8f76 | 1973 | |
a00ae6c4 | 1974 | #ifndef OPENSSL_NO_RMD160 |
0f113f3e | 1975 | if (doit[D_RMD160]) { |
8b0b80d9 AG |
1976 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1977 | print_message(names[D_RMD160], c[D_RMD160][testnum], lengths[testnum]); | |
0f113f3e | 1978 | Time_F(START); |
8b0b80d9 | 1979 | count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs); |
0f113f3e | 1980 | d = Time_F(STOP); |
8b0b80d9 | 1981 | print_result(D_RMD160, testnum, count, d); |
0f113f3e MC |
1982 | } |
1983 | } | |
a00ae6c4 RS |
1984 | #endif |
1985 | #ifndef OPENSSL_NO_RC4 | |
0f113f3e | 1986 | if (doit[D_RC4]) { |
8b0b80d9 AG |
1987 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1988 | print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum]); | |
0f113f3e | 1989 | Time_F(START); |
8b0b80d9 | 1990 | count = run_benchmark(async_jobs, RC4_loop, loopargs); |
0f113f3e | 1991 | d = Time_F(STOP); |
8b0b80d9 | 1992 | print_result(D_RC4, testnum, count, d); |
0f113f3e MC |
1993 | } |
1994 | } | |
a00ae6c4 RS |
1995 | #endif |
1996 | #ifndef OPENSSL_NO_DES | |
0f113f3e | 1997 | if (doit[D_CBC_DES]) { |
8b0b80d9 AG |
1998 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
1999 | print_message(names[D_CBC_DES], c[D_CBC_DES][testnum], lengths[testnum]); | |
0f113f3e | 2000 | Time_F(START); |
8b0b80d9 | 2001 | count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs); |
0f113f3e | 2002 | d = Time_F(STOP); |
8b0b80d9 | 2003 | print_result(D_CBC_DES, testnum, count, d); |
0f113f3e MC |
2004 | } |
2005 | } | |
ae93dc13 | 2006 | |
0f113f3e | 2007 | if (doit[D_EDE3_DES]) { |
8b0b80d9 AG |
2008 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2009 | print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum], lengths[testnum]); | |
0f113f3e | 2010 | Time_F(START); |
8b0b80d9 | 2011 | count = run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs); |
0f113f3e | 2012 | d = Time_F(STOP); |
8b0b80d9 | 2013 | print_result(D_EDE3_DES, testnum, count, d); |
0f113f3e MC |
2014 | } |
2015 | } | |
a00ae6c4 | 2016 | #endif |
5158c763 | 2017 | |
0f113f3e | 2018 | if (doit[D_CBC_128_AES]) { |
8b0b80d9 AG |
2019 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2020 | print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum], | |
2021 | lengths[testnum]); | |
0f113f3e | 2022 | Time_F(START); |
8b0b80d9 | 2023 | count = run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs); |
0f113f3e | 2024 | d = Time_F(STOP); |
8b0b80d9 | 2025 | print_result(D_CBC_128_AES, testnum, count, d); |
0f113f3e MC |
2026 | } |
2027 | } | |
2028 | if (doit[D_CBC_192_AES]) { | |
8b0b80d9 AG |
2029 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2030 | print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum], | |
2031 | lengths[testnum]); | |
0f113f3e | 2032 | Time_F(START); |
8b0b80d9 | 2033 | count = run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs); |
0f113f3e | 2034 | d = Time_F(STOP); |
8b0b80d9 | 2035 | print_result(D_CBC_192_AES, testnum, count, d); |
0f113f3e MC |
2036 | } |
2037 | } | |
2038 | if (doit[D_CBC_256_AES]) { | |
8b0b80d9 AG |
2039 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2040 | print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum], | |
2041 | lengths[testnum]); | |
0f113f3e | 2042 | Time_F(START); |
8b0b80d9 | 2043 | count = run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs); |
0f113f3e | 2044 | d = Time_F(STOP); |
8b0b80d9 | 2045 | print_result(D_CBC_256_AES, testnum, count, d); |
0f113f3e MC |
2046 | } |
2047 | } | |
5f09d0ec | 2048 | |
0f113f3e | 2049 | if (doit[D_IGE_128_AES]) { |
8b0b80d9 AG |
2050 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2051 | print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum], | |
2052 | lengths[testnum]); | |
0f113f3e | 2053 | Time_F(START); |
8b0b80d9 | 2054 | count = run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs); |
0f113f3e | 2055 | d = Time_F(STOP); |
8b0b80d9 | 2056 | print_result(D_IGE_128_AES, testnum, count, d); |
0f113f3e MC |
2057 | } |
2058 | } | |
2059 | if (doit[D_IGE_192_AES]) { | |
8b0b80d9 AG |
2060 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2061 | print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum], | |
2062 | lengths[testnum]); | |
0f113f3e | 2063 | Time_F(START); |
8b0b80d9 | 2064 | count = run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs); |
0f113f3e | 2065 | d = Time_F(STOP); |
8b0b80d9 | 2066 | print_result(D_IGE_192_AES, testnum, count, d); |
0f113f3e MC |
2067 | } |
2068 | } | |
2069 | if (doit[D_IGE_256_AES]) { | |
8b0b80d9 AG |
2070 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2071 | print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum], | |
2072 | lengths[testnum]); | |
0f113f3e | 2073 | Time_F(START); |
8b0b80d9 | 2074 | count = run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs); |
0f113f3e | 2075 | d = Time_F(STOP); |
8b0b80d9 | 2076 | print_result(D_IGE_256_AES, testnum, count, d); |
0f113f3e MC |
2077 | } |
2078 | } | |
2079 | if (doit[D_GHASH]) { | |
0ff43435 | 2080 | for (i = 0; i < loopargs_len; i++) { |
8b0b80d9 AG |
2081 | loopargs[i].gcm_ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt); |
2082 | CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx, (unsigned char *)"0123456789ab", 12); | |
2083 | } | |
0f113f3e | 2084 | |
8b0b80d9 AG |
2085 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2086 | print_message(names[D_GHASH], c[D_GHASH][testnum], lengths[testnum]); | |
0f113f3e | 2087 | Time_F(START); |
8b0b80d9 | 2088 | count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs); |
0f113f3e | 2089 | d = Time_F(STOP); |
8b0b80d9 | 2090 | print_result(D_GHASH, testnum, count, d); |
0f113f3e | 2091 | } |
0ff43435 | 2092 | for (i = 0; i < loopargs_len; i++) |
8b0b80d9 | 2093 | CRYPTO_gcm128_release(loopargs[i].gcm_ctx); |
0f113f3e | 2094 | } |
5158c763 | 2095 | |
a00ae6c4 | 2096 | #ifndef OPENSSL_NO_CAMELLIA |
0f113f3e | 2097 | if (doit[D_CBC_128_CML]) { |
e5972607 F |
2098 | if (async_jobs > 0) { |
2099 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2100 | names[D_CBC_128_CML]); | |
2101 | doit[D_CBC_128_CML] = 0; | |
2102 | } | |
2103 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 AG |
2104 | print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum], |
2105 | lengths[testnum]); | |
0f113f3e | 2106 | Time_F(START); |
8b0b80d9 AG |
2107 | for (count = 0, run = 1; COND(c[D_CBC_128_CML][testnum]); count++) |
2108 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2109 | (size_t)lengths[testnum], &camellia_ks1, |
0f113f3e MC |
2110 | iv, CAMELLIA_ENCRYPT); |
2111 | d = Time_F(STOP); | |
8b0b80d9 | 2112 | print_result(D_CBC_128_CML, testnum, count, d); |
0f113f3e MC |
2113 | } |
2114 | } | |
2115 | if (doit[D_CBC_192_CML]) { | |
e5972607 F |
2116 | if (async_jobs > 0) { |
2117 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2118 | names[D_CBC_192_CML]); | |
2119 | doit[D_CBC_192_CML] = 0; | |
2120 | } | |
2121 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 AG |
2122 | print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum], |
2123 | lengths[testnum]); | |
2124 | if (async_jobs > 0) { | |
2125 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); | |
2126 | exit(1); | |
2127 | } | |
0f113f3e | 2128 | Time_F(START); |
8b0b80d9 AG |
2129 | for (count = 0, run = 1; COND(c[D_CBC_192_CML][testnum]); count++) |
2130 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2131 | (size_t)lengths[testnum], &camellia_ks2, |
0f113f3e MC |
2132 | iv, CAMELLIA_ENCRYPT); |
2133 | d = Time_F(STOP); | |
8b0b80d9 | 2134 | print_result(D_CBC_192_CML, testnum, count, d); |
0f113f3e MC |
2135 | } |
2136 | } | |
2137 | if (doit[D_CBC_256_CML]) { | |
e5972607 F |
2138 | if (async_jobs > 0) { |
2139 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2140 | names[D_CBC_256_CML]); | |
2141 | doit[D_CBC_256_CML] = 0; | |
2142 | } | |
2143 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 AG |
2144 | print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum], |
2145 | lengths[testnum]); | |
0f113f3e | 2146 | Time_F(START); |
8b0b80d9 AG |
2147 | for (count = 0, run = 1; COND(c[D_CBC_256_CML][testnum]); count++) |
2148 | Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2149 | (size_t)lengths[testnum], &camellia_ks3, |
0f113f3e MC |
2150 | iv, CAMELLIA_ENCRYPT); |
2151 | d = Time_F(STOP); | |
8b0b80d9 | 2152 | print_result(D_CBC_256_CML, testnum, count, d); |
0f113f3e MC |
2153 | } |
2154 | } | |
a00ae6c4 RS |
2155 | #endif |
2156 | #ifndef OPENSSL_NO_IDEA | |
0f113f3e | 2157 | if (doit[D_CBC_IDEA]) { |
e5972607 F |
2158 | if (async_jobs > 0) { |
2159 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2160 | names[D_CBC_IDEA]); | |
2161 | doit[D_CBC_IDEA] = 0; | |
2162 | } | |
2163 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 | 2164 | print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum], lengths[testnum]); |
0f113f3e | 2165 | Time_F(START); |
8b0b80d9 | 2166 | for (count = 0, run = 1; COND(c[D_CBC_IDEA][testnum]); count++) |
9021a5df | 2167 | IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, |
8829ce30 | 2168 | (size_t)lengths[testnum], &idea_ks, |
0f113f3e MC |
2169 | iv, IDEA_ENCRYPT); |
2170 | d = Time_F(STOP); | |
8b0b80d9 | 2171 | print_result(D_CBC_IDEA, testnum, count, d); |
0f113f3e MC |
2172 | } |
2173 | } | |
a00ae6c4 RS |
2174 | #endif |
2175 | #ifndef OPENSSL_NO_SEED | |
0f113f3e | 2176 | if (doit[D_CBC_SEED]) { |
e5972607 F |
2177 | if (async_jobs > 0) { |
2178 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2179 | names[D_CBC_SEED]); | |
2180 | doit[D_CBC_SEED] = 0; | |
2181 | } | |
2182 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 | 2183 | print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum], lengths[testnum]); |
0f113f3e | 2184 | Time_F(START); |
8b0b80d9 AG |
2185 | for (count = 0, run = 1; COND(c[D_CBC_SEED][testnum]); count++) |
2186 | SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2187 | (size_t)lengths[testnum], &seed_ks, iv, 1); |
0f113f3e | 2188 | d = Time_F(STOP); |
8b0b80d9 | 2189 | print_result(D_CBC_SEED, testnum, count, d); |
0f113f3e MC |
2190 | } |
2191 | } | |
a00ae6c4 RS |
2192 | #endif |
2193 | #ifndef OPENSSL_NO_RC2 | |
0f113f3e | 2194 | if (doit[D_CBC_RC2]) { |
e5972607 F |
2195 | if (async_jobs > 0) { |
2196 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2197 | names[D_CBC_RC2]); | |
2198 | doit[D_CBC_RC2] = 0; | |
2199 | } | |
2200 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 AG |
2201 | print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum], lengths[testnum]); |
2202 | if (async_jobs > 0) { | |
2203 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); | |
2204 | exit(1); | |
2205 | } | |
0f113f3e | 2206 | Time_F(START); |
8b0b80d9 AG |
2207 | for (count = 0, run = 1; COND(c[D_CBC_RC2][testnum]); count++) |
2208 | RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2209 | (size_t)lengths[testnum], &rc2_ks, |
0f113f3e MC |
2210 | iv, RC2_ENCRYPT); |
2211 | d = Time_F(STOP); | |
8b0b80d9 | 2212 | print_result(D_CBC_RC2, testnum, count, d); |
0f113f3e MC |
2213 | } |
2214 | } | |
a00ae6c4 RS |
2215 | #endif |
2216 | #ifndef OPENSSL_NO_RC5 | |
0f113f3e | 2217 | if (doit[D_CBC_RC5]) { |
e5972607 F |
2218 | if (async_jobs > 0) { |
2219 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2220 | names[D_CBC_RC5]); | |
2221 | doit[D_CBC_RC5] = 0; | |
2222 | } | |
2223 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 AG |
2224 | print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum], lengths[testnum]); |
2225 | if (async_jobs > 0) { | |
2226 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); | |
2227 | exit(1); | |
2228 | } | |
0f113f3e | 2229 | Time_F(START); |
8b0b80d9 AG |
2230 | for (count = 0, run = 1; COND(c[D_CBC_RC5][testnum]); count++) |
2231 | RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2232 | (size_t)lengths[testnum], &rc5_ks, |
0f113f3e MC |
2233 | iv, RC5_ENCRYPT); |
2234 | d = Time_F(STOP); | |
8b0b80d9 | 2235 | print_result(D_CBC_RC5, testnum, count, d); |
0f113f3e MC |
2236 | } |
2237 | } | |
a00ae6c4 RS |
2238 | #endif |
2239 | #ifndef OPENSSL_NO_BF | |
0f113f3e | 2240 | if (doit[D_CBC_BF]) { |
e5972607 F |
2241 | if (async_jobs > 0) { |
2242 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2243 | names[D_CBC_BF]); | |
2244 | doit[D_CBC_BF] = 0; | |
2245 | } | |
2246 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 | 2247 | print_message(names[D_CBC_BF], c[D_CBC_BF][testnum], lengths[testnum]); |
0f113f3e | 2248 | Time_F(START); |
8b0b80d9 AG |
2249 | for (count = 0, run = 1; COND(c[D_CBC_BF][testnum]); count++) |
2250 | BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2251 | (size_t)lengths[testnum], &bf_ks, |
0f113f3e MC |
2252 | iv, BF_ENCRYPT); |
2253 | d = Time_F(STOP); | |
8b0b80d9 | 2254 | print_result(D_CBC_BF, testnum, count, d); |
0f113f3e MC |
2255 | } |
2256 | } | |
a00ae6c4 RS |
2257 | #endif |
2258 | #ifndef OPENSSL_NO_CAST | |
0f113f3e | 2259 | if (doit[D_CBC_CAST]) { |
e5972607 F |
2260 | if (async_jobs > 0) { |
2261 | BIO_printf(bio_err, "Async mode is not supported with %s\n", | |
2262 | names[D_CBC_CAST]); | |
2263 | doit[D_CBC_CAST] = 0; | |
2264 | } | |
2265 | for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { | |
8b0b80d9 | 2266 | print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum], lengths[testnum]); |
0f113f3e | 2267 | Time_F(START); |
8b0b80d9 AG |
2268 | for (count = 0, run = 1; COND(c[D_CBC_CAST][testnum]); count++) |
2269 | CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf, | |
8829ce30 | 2270 | (size_t)lengths[testnum], &cast_ks, |
0f113f3e MC |
2271 | iv, CAST_ENCRYPT); |
2272 | d = Time_F(STOP); | |
8b0b80d9 | 2273 | print_result(D_CBC_CAST, testnum, count, d); |
0f113f3e MC |
2274 | } |
2275 | } | |
a00ae6c4 | 2276 | #endif |
f3dea9a5 | 2277 | |
0f113f3e | 2278 | if (doit[D_EVP]) { |
a00ae6c4 | 2279 | #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK |
0f113f3e MC |
2280 | if (multiblock && evp_cipher) { |
2281 | if (! | |
2282 | (EVP_CIPHER_flags(evp_cipher) & | |
2283 | EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { | |
7768e116 | 2284 | BIO_printf(bio_err, "%s is not multi-block capable\n", |
6c2ff56e | 2285 | OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher))); |
0f113f3e MC |
2286 | goto end; |
2287 | } | |
8b0b80d9 AG |
2288 | if (async_jobs > 0) { |
2289 | BIO_printf(bio_err, "Async mode is not supported, exiting..."); | |
2290 | exit(1); | |
2291 | } | |
0f113f3e | 2292 | multiblock_speed(evp_cipher); |
7e1b7485 | 2293 | ret = 0; |
0f113f3e MC |
2294 | goto end; |
2295 | } | |
a00ae6c4 | 2296 | #endif |
8b0b80d9 | 2297 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
0f113f3e | 2298 | if (evp_cipher) { |
0f113f3e | 2299 | |
6c2ff56e | 2300 | names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); |
0f113f3e MC |
2301 | /* |
2302 | * -O3 -fschedule-insns messes up an optimization here! | |
2303 | * names[D_EVP] somehow becomes NULL | |
2304 | */ | |
8b0b80d9 AG |
2305 | print_message(names[D_EVP], save_count, lengths[testnum]); |
2306 | ||
2307 | for (k = 0; k < loopargs_len; k++) { | |
2308 | loopargs[k].ctx = EVP_CIPHER_CTX_new(); | |
2309 | if (decrypt) | |
2310 | EVP_DecryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv); | |
2311 | else | |
2312 | EVP_EncryptInit_ex(loopargs[k].ctx, evp_cipher, NULL, key16, iv); | |
2313 | EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0); | |
2314 | } | |
0f113f3e MC |
2315 | |
2316 | Time_F(START); | |
8b0b80d9 | 2317 | count = run_benchmark(async_jobs, EVP_Update_loop, loopargs); |
0f113f3e | 2318 | d = Time_F(STOP); |
8b0b80d9 AG |
2319 | for (k = 0; k < loopargs_len; k++) { |
2320 | EVP_CIPHER_CTX_free(loopargs[k].ctx); | |
2321 | } | |
0f113f3e MC |
2322 | } |
2323 | if (evp_md) { | |
cc9d6655 | 2324 | names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md)); |
8b0b80d9 | 2325 | print_message(names[D_EVP], save_count, lengths[testnum]); |
0f113f3e | 2326 | Time_F(START); |
8b0b80d9 | 2327 | count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs); |
0f113f3e MC |
2328 | d = Time_F(STOP); |
2329 | } | |
8b0b80d9 | 2330 | print_result(D_EVP, testnum, count, d); |
0f113f3e MC |
2331 | } |
2332 | } | |
7e1b7485 | 2333 | |
0ff43435 | 2334 | for (i = 0; i < loopargs_len; i++) |
8b0b80d9 AG |
2335 | RAND_bytes(loopargs[i].buf, 36); |
2336 | ||
a00ae6c4 | 2337 | #ifndef OPENSSL_NO_RSA |
8b0b80d9 AG |
2338 | for (testnum = 0; testnum < RSA_NUM; testnum++) { |
2339 | int st = 0; | |
2340 | if (!rsa_doit[testnum]) | |
0f113f3e | 2341 | continue; |
0ff43435 AG |
2342 | for (i = 0; i < loopargs_len; i++) { |
2343 | st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, | |
0930e07d | 2344 | &loopargs[i].siglen, loopargs[i].rsa_key[testnum]); |
8b0b80d9 AG |
2345 | if (st == 0) |
2346 | break; | |
2347 | } | |
7e1b7485 | 2348 | if (st == 0) { |
0f113f3e MC |
2349 | BIO_printf(bio_err, |
2350 | "RSA sign failure. No RSA sign will be done.\n"); | |
2351 | ERR_print_errors(bio_err); | |
2352 | rsa_count = 1; | |
2353 | } else { | |
2354 | pkey_print_message("private", "rsa", | |
8b0b80d9 AG |
2355 | rsa_c[testnum][0], rsa_bits[testnum], RSA_SECONDS); |
2356 | /* RSA_blinding_on(rsa_key[testnum],NULL); */ | |
0f113f3e | 2357 | Time_F(START); |
8b0b80d9 | 2358 | count = run_benchmark(async_jobs, RSA_sign_loop, loopargs); |
0f113f3e MC |
2359 | d = Time_F(STOP); |
2360 | BIO_printf(bio_err, | |
2361 | mr ? "+R1:%ld:%d:%.2f\n" | |
2362 | : "%ld %d bit private RSA's in %.2fs\n", | |
8b0b80d9 AG |
2363 | count, rsa_bits[testnum], d); |
2364 | rsa_results[testnum][0] = d / (double)count; | |
0f113f3e MC |
2365 | rsa_count = count; |
2366 | } | |
d02b48c6 | 2367 | |
0ff43435 AG |
2368 | for (i = 0; i < loopargs_len; i++) { |
2369 | st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2, | |
0930e07d | 2370 | loopargs[i].siglen, loopargs[i].rsa_key[testnum]); |
8b0b80d9 AG |
2371 | if (st <= 0) |
2372 | break; | |
2373 | } | |
7e1b7485 | 2374 | if (st <= 0) { |
0f113f3e MC |
2375 | BIO_printf(bio_err, |
2376 | "RSA verify failure. No RSA verify will be done.\n"); | |
2377 | ERR_print_errors(bio_err); | |
8b0b80d9 | 2378 | rsa_doit[testnum] = 0; |
0f113f3e MC |
2379 | } else { |
2380 | pkey_print_message("public", "rsa", | |
8b0b80d9 | 2381 | rsa_c[testnum][1], rsa_bits[testnum], RSA_SECONDS); |
0f113f3e | 2382 | Time_F(START); |
8b0b80d9 | 2383 | count = run_benchmark(async_jobs, RSA_verify_loop, loopargs); |
0f113f3e MC |
2384 | d = Time_F(STOP); |
2385 | BIO_printf(bio_err, | |
2386 | mr ? "+R2:%ld:%d:%.2f\n" | |
2387 | : "%ld %d bit public RSA's in %.2fs\n", | |
8b0b80d9 AG |
2388 | count, rsa_bits[testnum], d); |
2389 | rsa_results[testnum][1] = d / (double)count; | |
0f113f3e | 2390 | } |
d02b48c6 | 2391 | |
0f113f3e MC |
2392 | if (rsa_count <= 1) { |
2393 | /* if longer than 10s, don't do any more */ | |
8b0b80d9 AG |
2394 | for (testnum++; testnum < RSA_NUM; testnum++) |
2395 | rsa_doit[testnum] = 0; | |
0f113f3e MC |
2396 | } |
2397 | } | |
d6073e27 | 2398 | #endif /* OPENSSL_NO_RSA */ |
d02b48c6 | 2399 | |
0ff43435 | 2400 | for (i = 0; i < loopargs_len; i++) |
8b0b80d9 AG |
2401 | RAND_bytes(loopargs[i].buf, 36); |
2402 | ||
a00ae6c4 | 2403 | #ifndef OPENSSL_NO_DSA |
0f113f3e MC |
2404 | if (RAND_status() != 1) { |
2405 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
0f113f3e | 2406 | } |
8b0b80d9 AG |
2407 | for (testnum = 0; testnum < DSA_NUM; testnum++) { |
2408 | int st = 0; | |
2409 | if (!dsa_doit[testnum]) | |
0f113f3e MC |
2410 | continue; |
2411 | ||
8b0b80d9 AG |
2412 | /* DSA_generate_key(dsa_key[testnum]); */ |
2413 | /* DSA_sign_setup(dsa_key[testnum],NULL); */ | |
0ff43435 AG |
2414 | for (i = 0; i < loopargs_len; i++) { |
2415 | st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2, | |
0930e07d | 2416 | &loopargs[i].siglen, loopargs[i].dsa_key[testnum]); |
8b0b80d9 AG |
2417 | if (st == 0) |
2418 | break; | |
2419 | } | |
7e1b7485 | 2420 | if (st == 0) { |
0f113f3e MC |
2421 | BIO_printf(bio_err, |
2422 | "DSA sign failure. No DSA sign will be done.\n"); | |
2423 | ERR_print_errors(bio_err); | |
2424 | rsa_count = 1; | |
2425 | } else { | |
2426 | pkey_print_message("sign", "dsa", | |
8b0b80d9 | 2427 | dsa_c[testnum][0], dsa_bits[testnum], DSA_SECONDS); |
0f113f3e | 2428 | Time_F(START); |
8b0b80d9 | 2429 | count = run_benchmark(async_jobs, DSA_sign_loop, loopargs); |
0f113f3e MC |
2430 | d = Time_F(STOP); |
2431 | BIO_printf(bio_err, | |
2432 | mr ? "+R3:%ld:%d:%.2f\n" | |
2433 | : "%ld %d bit DSA signs in %.2fs\n", | |
8b0b80d9 AG |
2434 | count, dsa_bits[testnum], d); |
2435 | dsa_results[testnum][0] = d / (double)count; | |
0f113f3e MC |
2436 | rsa_count = count; |
2437 | } | |
e172d60d | 2438 | |
0ff43435 AG |
2439 | for (i = 0; i < loopargs_len; i++) { |
2440 | st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2, | |
0930e07d | 2441 | loopargs[i].siglen, loopargs[i].dsa_key[testnum]); |
8b0b80d9 AG |
2442 | if (st <= 0) |
2443 | break; | |
2444 | } | |
7e1b7485 | 2445 | if (st <= 0) { |
0f113f3e MC |
2446 | BIO_printf(bio_err, |
2447 | "DSA verify failure. No DSA verify will be done.\n"); | |
2448 | ERR_print_errors(bio_err); | |
8b0b80d9 | 2449 | dsa_doit[testnum] = 0; |
0f113f3e MC |
2450 | } else { |
2451 | pkey_print_message("verify", "dsa", | |
8b0b80d9 | 2452 | dsa_c[testnum][1], dsa_bits[testnum], DSA_SECONDS); |
0f113f3e | 2453 | Time_F(START); |
8b0b80d9 | 2454 | count = run_benchmark(async_jobs, DSA_verify_loop, loopargs); |
0f113f3e MC |
2455 | d = Time_F(STOP); |
2456 | BIO_printf(bio_err, | |
2457 | mr ? "+R4:%ld:%d:%.2f\n" | |
2458 | : "%ld %d bit DSA verify in %.2fs\n", | |
8b0b80d9 AG |
2459 | count, dsa_bits[testnum], d); |
2460 | dsa_results[testnum][1] = d / (double)count; | |
0f113f3e | 2461 | } |
e172d60d | 2462 | |
0f113f3e MC |
2463 | if (rsa_count <= 1) { |
2464 | /* if longer than 10s, don't do any more */ | |
8b0b80d9 AG |
2465 | for (testnum++; testnum < DSA_NUM; testnum++) |
2466 | dsa_doit[testnum] = 0; | |
0f113f3e MC |
2467 | } |
2468 | } | |
d6073e27 | 2469 | #endif /* OPENSSL_NO_DSA */ |
e172d60d | 2470 | |
10bf4fc2 | 2471 | #ifndef OPENSSL_NO_EC |
0f113f3e MC |
2472 | if (RAND_status() != 1) { |
2473 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
0f113f3e | 2474 | } |
8b0b80d9 | 2475 | for (testnum = 0; testnum < EC_NUM; testnum++) { |
0ff43435 | 2476 | int st = 1; |
0f113f3e | 2477 | |
8b0b80d9 | 2478 | if (!ecdsa_doit[testnum]) |
0f113f3e | 2479 | continue; /* Ignore Curve */ |
0ff43435 AG |
2480 | for (i = 0; i < loopargs_len; i++) { |
2481 | loopargs[i].ecdsa[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]); | |
2482 | if (loopargs[i].ecdsa[testnum] == NULL) { | |
2483 | st = 0; | |
2484 | break; | |
2485 | } | |
2486 | } | |
2487 | if (st == 0) { | |
0f113f3e MC |
2488 | BIO_printf(bio_err, "ECDSA failure.\n"); |
2489 | ERR_print_errors(bio_err); | |
2490 | rsa_count = 1; | |
2491 | } else { | |
0ff43435 AG |
2492 | for (i = 0; i < loopargs_len; i++) { |
2493 | EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL); | |
2494 | /* Perform ECDSA signature test */ | |
2495 | EC_KEY_generate_key(loopargs[i].ecdsa[testnum]); | |
2496 | st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2, | |
0930e07d | 2497 | &loopargs[i].siglen, loopargs[i].ecdsa[testnum]); |
8b0b80d9 AG |
2498 | if (st == 0) |
2499 | break; | |
2500 | } | |
7e1b7485 | 2501 | if (st == 0) { |
0f113f3e MC |
2502 | BIO_printf(bio_err, |
2503 | "ECDSA sign failure. No ECDSA sign will be done.\n"); | |
2504 | ERR_print_errors(bio_err); | |
2505 | rsa_count = 1; | |
2506 | } else { | |
2507 | pkey_print_message("sign", "ecdsa", | |
8b0b80d9 AG |
2508 | ecdsa_c[testnum][0], |
2509 | test_curves_bits[testnum], ECDSA_SECONDS); | |
0f113f3e | 2510 | Time_F(START); |
8b0b80d9 | 2511 | count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs); |
0f113f3e MC |
2512 | d = Time_F(STOP); |
2513 | ||
2514 | BIO_printf(bio_err, | |
2515 | mr ? "+R5:%ld:%d:%.2f\n" : | |
2516 | "%ld %d bit ECDSA signs in %.2fs \n", | |
8b0b80d9 AG |
2517 | count, test_curves_bits[testnum], d); |
2518 | ecdsa_results[testnum][0] = d / (double)count; | |
0f113f3e MC |
2519 | rsa_count = count; |
2520 | } | |
2521 | ||
2522 | /* Perform ECDSA verification test */ | |
0ff43435 AG |
2523 | for (i = 0; i < loopargs_len; i++) { |
2524 | st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2, | |
0930e07d | 2525 | loopargs[i].siglen, loopargs[i].ecdsa[testnum]); |
8b0b80d9 AG |
2526 | if (st != 1) |
2527 | break; | |
2528 | } | |
7e1b7485 | 2529 | if (st != 1) { |
0f113f3e MC |
2530 | BIO_printf(bio_err, |
2531 | "ECDSA verify failure. No ECDSA verify will be done.\n"); | |
2532 | ERR_print_errors(bio_err); | |
8b0b80d9 | 2533 | ecdsa_doit[testnum] = 0; |
0f113f3e MC |
2534 | } else { |
2535 | pkey_print_message("verify", "ecdsa", | |
8b0b80d9 AG |
2536 | ecdsa_c[testnum][1], |
2537 | test_curves_bits[testnum], ECDSA_SECONDS); | |
0f113f3e | 2538 | Time_F(START); |
8b0b80d9 | 2539 | count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs); |
0f113f3e MC |
2540 | d = Time_F(STOP); |
2541 | BIO_printf(bio_err, | |
2542 | mr ? "+R6:%ld:%d:%.2f\n" | |
2543 | : "%ld %d bit ECDSA verify in %.2fs\n", | |
8b0b80d9 AG |
2544 | count, test_curves_bits[testnum], d); |
2545 | ecdsa_results[testnum][1] = d / (double)count; | |
0f113f3e MC |
2546 | } |
2547 | ||
2548 | if (rsa_count <= 1) { | |
2549 | /* if longer than 10s, don't do any more */ | |
8b0b80d9 AG |
2550 | for (testnum++; testnum < EC_NUM; testnum++) |
2551 | ecdsa_doit[testnum] = 0; | |
0f113f3e MC |
2552 | } |
2553 | } | |
2554 | } | |
7e1b7485 | 2555 | |
0f113f3e MC |
2556 | if (RAND_status() != 1) { |
2557 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
0f113f3e | 2558 | } |
8b0b80d9 | 2559 | for (testnum = 0; testnum < EC_NUM; testnum++) { |
4d82c58b F |
2560 | int ecdh_checks = 1; |
2561 | ||
8b0b80d9 | 2562 | if (!ecdh_doit[testnum]) |
0f113f3e | 2563 | continue; |
0ff43435 AG |
2564 | for (i = 0; i < loopargs_len; i++) { |
2565 | loopargs[i].ecdh_a[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]); | |
2566 | loopargs[i].ecdh_b[testnum] = EC_KEY_new_by_curve_name(test_curves[testnum]); | |
2567 | if (loopargs[i].ecdh_a[testnum] == NULL || | |
2568 | loopargs[i].ecdh_b[testnum] == NULL) { | |
2569 | ecdh_checks = 0; | |
2570 | break; | |
2571 | } | |
2572 | } | |
2573 | if (ecdh_checks == 0) { | |
0f113f3e MC |
2574 | BIO_printf(bio_err, "ECDH failure.\n"); |
2575 | ERR_print_errors(bio_err); | |
2576 | rsa_count = 1; | |
2577 | } else { | |
0ff43435 AG |
2578 | for (i = 0; i < loopargs_len; i++) { |
2579 | /* generate two ECDH key pairs */ | |
2580 | if (!EC_KEY_generate_key(loopargs[i].ecdh_a[testnum]) || | |
2581 | !EC_KEY_generate_key(loopargs[i].ecdh_b[testnum])) { | |
2582 | BIO_printf(bio_err, "ECDH key generation failure.\n"); | |
2583 | ERR_print_errors(bio_err); | |
0f113f3e | 2584 | ecdh_checks = 0; |
0ff43435 AG |
2585 | rsa_count = 1; |
2586 | } else { | |
4d82c58b | 2587 | int secret_size_a, secret_size_b; |
0ff43435 AG |
2588 | /* |
2589 | * If field size is not more than 24 octets, then use SHA-1 | |
2590 | * hash of result; otherwise, use result (see section 4.8 of | |
2591 | * draft-ietf-tls-ecc-03.txt). | |
2592 | */ | |
3331e43b F |
2593 | int field_size = EC_GROUP_get_degree( |
2594 | EC_KEY_get0_group(loopargs[i].ecdh_a[testnum])); | |
2595 | ||
2596 | if (field_size <= 24 * 8) { /* 192 bits */ | |
2597 | loopargs[i].outlen = KDF1_SHA1_len; | |
2598 | loopargs[i].kdf = KDF1_SHA1; | |
0ff43435 | 2599 | } else { |
3331e43b F |
2600 | loopargs[i].outlen = (field_size + 7) / 8; |
2601 | loopargs[i].kdf = NULL; | |
0ff43435 AG |
2602 | } |
2603 | secret_size_a = | |
3331e43b | 2604 | ECDH_compute_key(loopargs[i].secret_a, loopargs[i].outlen, |
0ff43435 | 2605 | EC_KEY_get0_public_key(loopargs[i].ecdh_b[testnum]), |
3331e43b | 2606 | loopargs[i].ecdh_a[testnum], loopargs[i].kdf); |
0ff43435 | 2607 | secret_size_b = |
3331e43b | 2608 | ECDH_compute_key(loopargs[i].secret_b, loopargs[i].outlen, |
0ff43435 | 2609 | EC_KEY_get0_public_key(loopargs[i].ecdh_a[testnum]), |
3331e43b | 2610 | loopargs[i].ecdh_b[testnum], loopargs[i].kdf); |
0ff43435 | 2611 | if (secret_size_a != secret_size_b) |
0f113f3e | 2612 | ecdh_checks = 0; |
0ff43435 AG |
2613 | else |
2614 | ecdh_checks = 1; | |
0f113f3e | 2615 | |
4d82c58b F |
2616 | for (k = 0; k < secret_size_a && ecdh_checks == 1; k++) { |
2617 | if (loopargs[i].secret_a[k] != loopargs[i].secret_b[k]) | |
0ff43435 AG |
2618 | ecdh_checks = 0; |
2619 | } | |
0f113f3e | 2620 | |
0ff43435 AG |
2621 | if (ecdh_checks == 0) { |
2622 | BIO_printf(bio_err, "ECDH computations don't match.\n"); | |
2623 | ERR_print_errors(bio_err); | |
2624 | rsa_count = 1; | |
2625 | break; | |
2626 | } | |
2627 | } | |
447402e6 AG |
2628 | } |
2629 | if (ecdh_checks != 0) { | |
2630 | pkey_print_message("", "ecdh", | |
2631 | ecdh_c[testnum][0], | |
2632 | test_curves_bits[testnum], ECDH_SECONDS); | |
2633 | Time_F(START); | |
2634 | count = run_benchmark(async_jobs, ECDH_compute_key_loop, loopargs); | |
2635 | d = Time_F(STOP); | |
2636 | BIO_printf(bio_err, | |
2637 | mr ? "+R7:%ld:%d:%.2f\n" : | |
2638 | "%ld %d-bit ECDH ops in %.2fs\n", count, | |
2639 | test_curves_bits[testnum], d); | |
2640 | ecdh_results[testnum][0] = d / (double)count; | |
2641 | rsa_count = count; | |
0f113f3e MC |
2642 | } |
2643 | } | |
e172d60d | 2644 | |
0f113f3e MC |
2645 | if (rsa_count <= 1) { |
2646 | /* if longer than 10s, don't do any more */ | |
8b0b80d9 AG |
2647 | for (testnum++; testnum < EC_NUM; testnum++) |
2648 | ecdh_doit[testnum] = 0; | |
0f113f3e MC |
2649 | } |
2650 | } | |
d6073e27 | 2651 | #endif /* OPENSSL_NO_EC */ |
a00ae6c4 | 2652 | #ifndef NO_FORK |
0f113f3e | 2653 | show_res: |
a00ae6c4 | 2654 | #endif |
0f113f3e | 2655 | if (!mr) { |
b0700d2c RS |
2656 | printf("%s\n", OpenSSL_version(OPENSSL_VERSION)); |
2657 | printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON)); | |
0f113f3e MC |
2658 | printf("options:"); |
2659 | printf("%s ", BN_options()); | |
a00ae6c4 | 2660 | #ifndef OPENSSL_NO_MD2 |
0f113f3e | 2661 | printf("%s ", MD2_options()); |
a00ae6c4 RS |
2662 | #endif |
2663 | #ifndef OPENSSL_NO_RC4 | |
0f113f3e | 2664 | printf("%s ", RC4_options()); |
a00ae6c4 RS |
2665 | #endif |
2666 | #ifndef OPENSSL_NO_DES | |
0f113f3e | 2667 | printf("%s ", DES_options()); |
a00ae6c4 | 2668 | #endif |
0f113f3e | 2669 | printf("%s ", AES_options()); |
a00ae6c4 | 2670 | #ifndef OPENSSL_NO_IDEA |
9021a5df | 2671 | printf("%s ", IDEA_options()); |
a00ae6c4 RS |
2672 | #endif |
2673 | #ifndef OPENSSL_NO_BF | |
0f113f3e | 2674 | printf("%s ", BF_options()); |
a00ae6c4 | 2675 | #endif |
b0700d2c | 2676 | printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS)); |
0f113f3e | 2677 | } |
e172d60d | 2678 | |
0f113f3e MC |
2679 | if (pr_header) { |
2680 | if (mr) | |
7e1b7485 | 2681 | printf("+H"); |
0f113f3e | 2682 | else { |
7e1b7485 RS |
2683 | printf |
2684 | ("The 'numbers' are in 1000s of bytes per second processed.\n"); | |
2685 | printf("type "); | |
0f113f3e | 2686 | } |
8b0b80d9 AG |
2687 | for (testnum = 0; testnum < SIZE_NUM; testnum++) |
2688 | printf(mr ? ":%d" : "%7d bytes", lengths[testnum]); | |
7e1b7485 | 2689 | printf("\n"); |
0f113f3e | 2690 | } |
e172d60d | 2691 | |
0f113f3e MC |
2692 | for (k = 0; k < ALGOR_NUM; k++) { |
2693 | if (!doit[k]) | |
2694 | continue; | |
2695 | if (mr) | |
7e1b7485 | 2696 | printf("+F:%d:%s", k, names[k]); |
0f113f3e | 2697 | else |
7e1b7485 | 2698 | printf("%-13s", names[k]); |
8b0b80d9 AG |
2699 | for (testnum = 0; testnum < SIZE_NUM; testnum++) { |
2700 | if (results[k][testnum] > 10000 && !mr) | |
2701 | printf(" %11.2fk", results[k][testnum] / 1e3); | |
0f113f3e | 2702 | else |
8b0b80d9 | 2703 | printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]); |
0f113f3e | 2704 | } |
7e1b7485 | 2705 | printf("\n"); |
0f113f3e | 2706 | } |
a00ae6c4 | 2707 | #ifndef OPENSSL_NO_RSA |
8b0b80d9 | 2708 | testnum = 1; |
0f113f3e MC |
2709 | for (k = 0; k < RSA_NUM; k++) { |
2710 | if (!rsa_doit[k]) | |
2711 | continue; | |
8b0b80d9 | 2712 | if (testnum && !mr) { |
0f113f3e | 2713 | printf("%18ssign verify sign/s verify/s\n", " "); |
8b0b80d9 | 2714 | testnum = 0; |
0f113f3e MC |
2715 | } |
2716 | if (mr) | |
7e1b7485 RS |
2717 | printf("+F2:%u:%u:%f:%f\n", |
2718 | k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]); | |
0f113f3e | 2719 | else |
7e1b7485 RS |
2720 | printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
2721 | rsa_bits[k], rsa_results[k][0], rsa_results[k][1], | |
2722 | 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]); | |
0f113f3e | 2723 | } |
a00ae6c4 RS |
2724 | #endif |
2725 | #ifndef OPENSSL_NO_DSA | |
8b0b80d9 | 2726 | testnum = 1; |
0f113f3e MC |
2727 | for (k = 0; k < DSA_NUM; k++) { |
2728 | if (!dsa_doit[k]) | |
2729 | continue; | |
8b0b80d9 | 2730 | if (testnum && !mr) { |
0f113f3e | 2731 | printf("%18ssign verify sign/s verify/s\n", " "); |
8b0b80d9 | 2732 | testnum = 0; |
0f113f3e MC |
2733 | } |
2734 | if (mr) | |
7e1b7485 RS |
2735 | printf("+F3:%u:%u:%f:%f\n", |
2736 | k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]); | |
0f113f3e | 2737 | else |
7e1b7485 RS |
2738 | printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
2739 | dsa_bits[k], dsa_results[k][0], dsa_results[k][1], | |
2740 | 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]); | |
0f113f3e | 2741 | } |
a00ae6c4 | 2742 | #endif |
10bf4fc2 | 2743 | #ifndef OPENSSL_NO_EC |
8b0b80d9 | 2744 | testnum = 1; |
0f113f3e MC |
2745 | for (k = 0; k < EC_NUM; k++) { |
2746 | if (!ecdsa_doit[k]) | |
2747 | continue; | |
8b0b80d9 | 2748 | if (testnum && !mr) { |
0f113f3e | 2749 | printf("%30ssign verify sign/s verify/s\n", " "); |
8b0b80d9 | 2750 | testnum = 0; |
0f113f3e MC |
2751 | } |
2752 | ||
2753 | if (mr) | |
7e1b7485 RS |
2754 | printf("+F4:%u:%u:%f:%f\n", |
2755 | k, test_curves_bits[k], | |
2756 | ecdsa_results[k][0], ecdsa_results[k][1]); | |
0f113f3e | 2757 | else |
7e1b7485 RS |
2758 | printf("%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", |
2759 | test_curves_bits[k], | |
2760 | test_curves_names[k], | |
2761 | ecdsa_results[k][0], ecdsa_results[k][1], | |
2762 | 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]); | |
0f113f3e | 2763 | } |
7e1b7485 | 2764 | |
8b0b80d9 | 2765 | testnum = 1; |
0f113f3e MC |
2766 | for (k = 0; k < EC_NUM; k++) { |
2767 | if (!ecdh_doit[k]) | |
2768 | continue; | |
8b0b80d9 | 2769 | if (testnum && !mr) { |
0f113f3e | 2770 | printf("%30sop op/s\n", " "); |
8b0b80d9 | 2771 | testnum = 0; |
0f113f3e MC |
2772 | } |
2773 | if (mr) | |
7e1b7485 RS |
2774 | printf("+F5:%u:%u:%f:%f\n", |
2775 | k, test_curves_bits[k], | |
2776 | ecdh_results[k][0], 1.0 / ecdh_results[k][0]); | |
0f113f3e MC |
2777 | |
2778 | else | |
7e1b7485 RS |
2779 | printf("%4u bit ecdh (%s) %8.4fs %8.1f\n", |
2780 | test_curves_bits[k], | |
2781 | test_curves_names[k], | |
2782 | ecdh_results[k][0], 1.0 / ecdh_results[k][0]); | |
0f113f3e | 2783 | } |
a00ae6c4 | 2784 | #endif |
0f113f3e | 2785 | |
7e1b7485 | 2786 | ret = 0; |
0f113f3e MC |
2787 | |
2788 | end: | |
2789 | ERR_print_errors(bio_err); | |
0ff43435 | 2790 | for (i = 0; i < loopargs_len; i++) { |
b2839683 AG |
2791 | OPENSSL_free(loopargs[i].buf_malloc); |
2792 | OPENSSL_free(loopargs[i].buf2_malloc); | |
5f986ed3 | 2793 | |
a00ae6c4 | 2794 | #ifndef OPENSSL_NO_RSA |
0ff43435 AG |
2795 | for (k = 0; k < RSA_NUM; k++) |
2796 | RSA_free(loopargs[i].rsa_key[k]); | |
a00ae6c4 RS |
2797 | #endif |
2798 | #ifndef OPENSSL_NO_DSA | |
0ff43435 AG |
2799 | for (k = 0; k < DSA_NUM; k++) |
2800 | DSA_free(loopargs[i].dsa_key[k]); | |
a00ae6c4 | 2801 | #endif |
10bf4fc2 | 2802 | #ifndef OPENSSL_NO_EC |
0ff43435 AG |
2803 | for (k = 0; k < EC_NUM; k++) { |
2804 | EC_KEY_free(loopargs[i].ecdsa[k]); | |
2805 | EC_KEY_free(loopargs[i].ecdh_a[k]); | |
2806 | EC_KEY_free(loopargs[i].ecdh_b[k]); | |
2807 | } | |
b2839683 AG |
2808 | OPENSSL_free(loopargs[i].secret_a); |
2809 | OPENSSL_free(loopargs[i].secret_b); | |
a00ae6c4 | 2810 | #endif |
5f986ed3 F |
2811 | } |
2812 | ||
1e613922 AG |
2813 | if (async_jobs > 0) { |
2814 | for (i = 0; i < loopargs_len; i++) | |
2815 | ASYNC_WAIT_CTX_free(loopargs[i].wait_ctx); | |
dab1f5fe | 2816 | } |
1e613922 | 2817 | |
dab1f5fe | 2818 | if (async_init) { |
8b0b80d9 | 2819 | ASYNC_cleanup_thread(); |
1e613922 AG |
2820 | } |
2821 | OPENSSL_free(loopargs); | |
7e1b7485 | 2822 | return (ret); |
0f113f3e | 2823 | } |
d02b48c6 | 2824 | |
646d5695 | 2825 | static void print_message(const char *s, long num, int length) |
0f113f3e | 2826 | { |
a00ae6c4 | 2827 | #ifdef SIGALRM |
0f113f3e MC |
2828 | BIO_printf(bio_err, |
2829 | mr ? "+DT:%s:%d:%d\n" | |
2830 | : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length); | |
2831 | (void)BIO_flush(bio_err); | |
2832 | alarm(SECONDS); | |
a00ae6c4 | 2833 | #else |
0f113f3e MC |
2834 | BIO_printf(bio_err, |
2835 | mr ? "+DN:%s:%ld:%d\n" | |
2836 | : "Doing %s %ld times on %d size blocks: ", s, num, length); | |
2837 | (void)BIO_flush(bio_err); | |
a00ae6c4 | 2838 | #endif |
0f113f3e | 2839 | } |
d02b48c6 | 2840 | |
689c6f25 | 2841 | static void pkey_print_message(const char *str, const char *str2, long num, |
0f113f3e MC |
2842 | int bits, int tm) |
2843 | { | |
a00ae6c4 | 2844 | #ifdef SIGALRM |
0f113f3e MC |
2845 | BIO_printf(bio_err, |
2846 | mr ? "+DTP:%d:%s:%s:%d\n" | |
2847 | : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm); | |
2848 | (void)BIO_flush(bio_err); | |
2849 | alarm(tm); | |
a00ae6c4 | 2850 | #else |
0f113f3e MC |
2851 | BIO_printf(bio_err, |
2852 | mr ? "+DNP:%ld:%d:%s:%s\n" | |
2853 | : "Doing %ld %d bit %s %s's: ", num, bits, str, str2); | |
2854 | (void)BIO_flush(bio_err); | |
a00ae6c4 | 2855 | #endif |
0f113f3e | 2856 | } |
58964a49 | 2857 | |
0f113f3e MC |
2858 | static void print_result(int alg, int run_no, int count, double time_used) |
2859 | { | |
d166ed8c DSH |
2860 | if (count == -1) { |
2861 | BIO_puts(bio_err, "EVP error!\n"); | |
2862 | exit(1); | |
2863 | } | |
0f113f3e MC |
2864 | BIO_printf(bio_err, |
2865 | mr ? "+R:%d:%s:%f\n" | |
2866 | : "%d %s's in %.2fs\n", count, names[alg], time_used); | |
2867 | results[alg][run_no] = ((double)count) / time_used * lengths[run_no]; | |
2868 | } | |
0e211563 | 2869 | |
a00ae6c4 | 2870 | #ifndef NO_FORK |
0e211563 | 2871 | static char *sstrsep(char **string, const char *delim) |
0f113f3e | 2872 | { |
0e211563 BL |
2873 | char isdelim[256]; |
2874 | char *token = *string; | |
2875 | ||
2876 | if (**string == 0) | |
2877 | return NULL; | |
2878 | ||
54a656ef | 2879 | memset(isdelim, 0, sizeof isdelim); |
0e211563 BL |
2880 | isdelim[0] = 1; |
2881 | ||
0f113f3e | 2882 | while (*delim) { |
0e211563 BL |
2883 | isdelim[(unsigned char)(*delim)] = 1; |
2884 | delim++; | |
0f113f3e | 2885 | } |
0e211563 | 2886 | |
0f113f3e | 2887 | while (!isdelim[(unsigned char)(**string)]) { |
0e211563 | 2888 | (*string)++; |
0f113f3e | 2889 | } |
0e211563 | 2890 | |
0f113f3e | 2891 | if (**string) { |
0e211563 BL |
2892 | **string = 0; |
2893 | (*string)++; | |
0f113f3e | 2894 | } |
0e211563 BL |
2895 | |
2896 | return token; | |
0f113f3e | 2897 | } |
0e211563 BL |
2898 | |
2899 | static int do_multi(int multi) | |
0f113f3e MC |
2900 | { |
2901 | int n; | |
2902 | int fd[2]; | |
2903 | int *fds; | |
2904 | static char sep[] = ":"; | |
2905 | ||
b4faea50 | 2906 | fds = malloc(sizeof(*fds) * multi); |
0f113f3e MC |
2907 | for (n = 0; n < multi; ++n) { |
2908 | if (pipe(fd) == -1) { | |
7768e116 | 2909 | BIO_printf(bio_err, "pipe failure\n"); |
0f113f3e MC |
2910 | exit(1); |
2911 | } | |
2912 | fflush(stdout); | |
7768e116 | 2913 | (void)BIO_flush(bio_err); |
0f113f3e MC |
2914 | if (fork()) { |
2915 | close(fd[1]); | |
2916 | fds[n] = fd[0]; | |
2917 | } else { | |
2918 | close(fd[0]); | |
2919 | close(1); | |
2920 | if (dup(fd[1]) == -1) { | |
7768e116 | 2921 | BIO_printf(bio_err, "dup failed\n"); |
0f113f3e MC |
2922 | exit(1); |
2923 | } | |
2924 | close(fd[1]); | |
2925 | mr = 1; | |
2926 | usertime = 0; | |
2927 | free(fds); | |
2928 | return 0; | |
2929 | } | |
2930 | printf("Forked child %d\n", n); | |
2931 | } | |
e172d60d | 2932 | |
0f113f3e MC |
2933 | /* for now, assume the pipe is long enough to take all the output */ |
2934 | for (n = 0; n < multi; ++n) { | |
2935 | FILE *f; | |
2936 | char buf[1024]; | |
2937 | char *p; | |
2938 | ||
2939 | f = fdopen(fds[n], "r"); | |
2940 | while (fgets(buf, sizeof buf, f)) { | |
2941 | p = strchr(buf, '\n'); | |
2942 | if (p) | |
2943 | *p = '\0'; | |
2944 | if (buf[0] != '+') { | |
7768e116 | 2945 | BIO_printf(bio_err, "Don't understand line '%s' from child %d\n", |
0f113f3e MC |
2946 | buf, n); |
2947 | continue; | |
2948 | } | |
2949 | printf("Got: %s from %d\n", buf, n); | |
86885c28 | 2950 | if (strncmp(buf, "+F:", 3) == 0) { |
0f113f3e MC |
2951 | int alg; |
2952 | int j; | |
2953 | ||
2954 | p = buf + 3; | |
2955 | alg = atoi(sstrsep(&p, sep)); | |
2956 | sstrsep(&p, sep); | |
2957 | for (j = 0; j < SIZE_NUM; ++j) | |
2958 | results[alg][j] += atof(sstrsep(&p, sep)); | |
86885c28 | 2959 | } else if (strncmp(buf, "+F2:", 4) == 0) { |
0f113f3e MC |
2960 | int k; |
2961 | double d; | |
2962 | ||
2963 | p = buf + 4; | |
2964 | k = atoi(sstrsep(&p, sep)); | |
2965 | sstrsep(&p, sep); | |
2966 | ||
0f113f3e MC |
2967 | d = atof(sstrsep(&p, sep)); |
2968 | if (n) | |
2969 | rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d); | |
2970 | else | |
2971 | rsa_results[k][0] = d; | |
2972 | ||
2973 | d = atof(sstrsep(&p, sep)); | |
2974 | if (n) | |
2975 | rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d); | |
2976 | else | |
2977 | rsa_results[k][1] = d; | |
2978 | } | |
a00ae6c4 | 2979 | # ifndef OPENSSL_NO_DSA |
86885c28 | 2980 | else if (strncmp(buf, "+F3:", 4) == 0) { |
0f113f3e MC |
2981 | int k; |
2982 | double d; | |
2983 | ||
2984 | p = buf + 4; | |
2985 | k = atoi(sstrsep(&p, sep)); | |
2986 | sstrsep(&p, sep); | |
2987 | ||
2988 | d = atof(sstrsep(&p, sep)); | |
2989 | if (n) | |
2990 | dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d); | |
2991 | else | |
2992 | dsa_results[k][0] = d; | |
2993 | ||
2994 | d = atof(sstrsep(&p, sep)); | |
2995 | if (n) | |
2996 | dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d); | |
2997 | else | |
2998 | dsa_results[k][1] = d; | |
2999 | } | |
a00ae6c4 | 3000 | # endif |
10bf4fc2 | 3001 | # ifndef OPENSSL_NO_EC |
86885c28 | 3002 | else if (strncmp(buf, "+F4:", 4) == 0) { |
0f113f3e MC |
3003 | int k; |
3004 | double d; | |
3005 | ||
3006 | p = buf + 4; | |
3007 | k = atoi(sstrsep(&p, sep)); | |
3008 | sstrsep(&p, sep); | |
3009 | ||
3010 | d = atof(sstrsep(&p, sep)); | |
3011 | if (n) | |
3012 | ecdsa_results[k][0] = | |
3013 | 1 / (1 / ecdsa_results[k][0] + 1 / d); | |
3014 | else | |
3015 | ecdsa_results[k][0] = d; | |
3016 | ||
3017 | d = atof(sstrsep(&p, sep)); | |
3018 | if (n) | |
3019 | ecdsa_results[k][1] = | |
3020 | 1 / (1 / ecdsa_results[k][1] + 1 / d); | |
3021 | else | |
3022 | ecdsa_results[k][1] = d; | |
d6073e27 | 3023 | } else if (strncmp(buf, "+F5:", 4) == 0) { |
0f113f3e MC |
3024 | int k; |
3025 | double d; | |
3026 | ||
3027 | p = buf + 4; | |
3028 | k = atoi(sstrsep(&p, sep)); | |
3029 | sstrsep(&p, sep); | |
3030 | ||
3031 | d = atof(sstrsep(&p, sep)); | |
3032 | if (n) | |
3033 | ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d); | |
3034 | else | |
3035 | ecdh_results[k][0] = d; | |
3036 | ||
3037 | } | |
a00ae6c4 | 3038 | # endif |
0f113f3e | 3039 | |
86885c28 | 3040 | else if (strncmp(buf, "+H:", 3) == 0) { |
7e1b7485 | 3041 | ; |
0f113f3e | 3042 | } else |
7768e116 | 3043 | BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n); |
0f113f3e MC |
3044 | } |
3045 | ||
3046 | fclose(f); | |
3047 | } | |
3048 | free(fds); | |
3049 | return 1; | |
3050 | } | |
a00ae6c4 | 3051 | #endif |
375a64e3 AP |
3052 | |
3053 | static void multiblock_speed(const EVP_CIPHER *evp_cipher) | |
0f113f3e MC |
3054 | { |
3055 | static int mblengths[] = | |
3056 | { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 }; | |
8b0b80d9 | 3057 | int j, count, num = OSSL_NELEM(mblengths); |
0f113f3e MC |
3058 | const char *alg_name; |
3059 | unsigned char *inp, *out, no_key[32], no_iv[16]; | |
846ec07d | 3060 | EVP_CIPHER_CTX *ctx; |
0f113f3e MC |
3061 | double d = 0.0; |
3062 | ||
68dc6824 RS |
3063 | inp = app_malloc(mblengths[num - 1], "multiblock input buffer"); |
3064 | out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer"); | |
846ec07d RL |
3065 | ctx = EVP_CIPHER_CTX_new(); |
3066 | EVP_EncryptInit_ex(ctx, evp_cipher, NULL, no_key, no_iv); | |
3067 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), | |
0f113f3e | 3068 | no_key); |
6c2ff56e | 3069 | alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); |
0f113f3e MC |
3070 | |
3071 | for (j = 0; j < num; j++) { | |
3072 | print_message(alg_name, 0, mblengths[j]); | |
3073 | Time_F(START); | |
3074 | for (count = 0, run = 1; run && count < 0x7fffffff; count++) { | |
c8269881 | 3075 | unsigned char aad[EVP_AEAD_TLS1_AAD_LEN]; |
0f113f3e MC |
3076 | EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param; |
3077 | size_t len = mblengths[j]; | |
3078 | int packlen; | |
3079 | ||
3080 | memset(aad, 0, 8); /* avoid uninitialized values */ | |
3081 | aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */ | |
3082 | aad[9] = 3; /* version */ | |
3083 | aad[10] = 2; | |
3084 | aad[11] = 0; /* length */ | |
3085 | aad[12] = 0; | |
3086 | mb_param.out = NULL; | |
3087 | mb_param.inp = aad; | |
3088 | mb_param.len = len; | |
3089 | mb_param.interleave = 8; | |
3090 | ||
846ec07d | 3091 | packlen = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_AAD, |
0f113f3e MC |
3092 | sizeof(mb_param), &mb_param); |
3093 | ||
3094 | if (packlen > 0) { | |
3095 | mb_param.out = out; | |
3096 | mb_param.inp = inp; | |
3097 | mb_param.len = len; | |
846ec07d | 3098 | EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT, |
0f113f3e MC |
3099 | sizeof(mb_param), &mb_param); |
3100 | } else { | |
3101 | int pad; | |
3102 | ||
3103 | RAND_bytes(out, 16); | |
3104 | len += 16; | |
3105 | aad[11] = len >> 8; | |
3106 | aad[12] = len; | |
846ec07d | 3107 | pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD, |
c8269881 | 3108 | EVP_AEAD_TLS1_AAD_LEN, aad); |
846ec07d | 3109 | EVP_Cipher(ctx, out, inp, len + pad); |
0f113f3e MC |
3110 | } |
3111 | } | |
3112 | d = Time_F(STOP); | |
7e1b7485 | 3113 | BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n" |
0f113f3e MC |
3114 | : "%d %s's in %.2fs\n", count, "evp", d); |
3115 | results[D_EVP][j] = ((double)count) / d * mblengths[j]; | |
3116 | } | |
3117 | ||
3118 | if (mr) { | |
3119 | fprintf(stdout, "+H"); | |
3120 | for (j = 0; j < num; j++) | |
3121 | fprintf(stdout, ":%d", mblengths[j]); | |
3122 | fprintf(stdout, "\n"); | |
3123 | fprintf(stdout, "+F:%d:%s", D_EVP, alg_name); | |
3124 | for (j = 0; j < num; j++) | |
3125 | fprintf(stdout, ":%.2f", results[D_EVP][j]); | |
3126 | fprintf(stdout, "\n"); | |
3127 | } else { | |
3128 | fprintf(stdout, | |
3129 | "The 'numbers' are in 1000s of bytes per second processed.\n"); | |
3130 | fprintf(stdout, "type "); | |
3131 | for (j = 0; j < num; j++) | |
3132 | fprintf(stdout, "%7d bytes", mblengths[j]); | |
3133 | fprintf(stdout, "\n"); | |
3134 | fprintf(stdout, "%-24s", alg_name); | |
3135 | ||
3136 | for (j = 0; j < num; j++) { | |
3137 | if (results[D_EVP][j] > 10000) | |
3138 | fprintf(stdout, " %11.2fk", results[D_EVP][j] / 1e3); | |
3139 | else | |
3140 | fprintf(stdout, " %11.2f ", results[D_EVP][j]); | |
3141 | } | |
3142 | fprintf(stdout, "\n"); | |
3143 | } | |
3144 | ||
b548a1f1 RS |
3145 | OPENSSL_free(inp); |
3146 | OPENSSL_free(out); | |
846ec07d | 3147 | EVP_CIPHER_CTX_free(ctx); |
0f113f3e | 3148 | } |