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