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