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