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