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