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