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