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