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