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