]>
Commit | Line | Data |
---|---|---|
7876e448 | 1 | /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */ |
58964a49 | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
d02b48c6 RE |
3 | * All rights reserved. |
4 | * | |
5 | * This package is an SSL implementation written | |
6 | * by Eric Young (eay@cryptsoft.com). | |
7 | * The implementation was written so as to conform with Netscapes SSL. | |
8 | * | |
9 | * This library is free for commercial and non-commercial use as long as | |
10 | * the following conditions are aheared to. The following conditions | |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | |
13 | * included with this distribution is covered by the same copyright terms | |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | |
15 | * | |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | |
17 | * the code are not to be removed. | |
18 | * If this package is used in a product, Eric Young should be given attribution | |
19 | * as the author of the parts of the library used. | |
20 | * This can be in the form of a textual message at program startup or | |
21 | * in documentation (online or textual) provided with the package. | |
22 | * | |
23 | * Redistribution and use in source and binary forms, with or without | |
24 | * modification, are permitted provided that the following conditions | |
25 | * are met: | |
26 | * 1. Redistributions of source code must retain the copyright | |
27 | * notice, this list of conditions and the following disclaimer. | |
28 | * 2. Redistributions in binary form must reproduce the above copyright | |
29 | * notice, this list of conditions and the following disclaimer in the | |
30 | * documentation and/or other materials provided with the distribution. | |
31 | * 3. All advertising materials mentioning features or use of this software | |
32 | * must display the following acknowledgement: | |
33 | * "This product includes cryptographic software written by | |
34 | * Eric Young (eay@cryptsoft.com)" | |
35 | * The word 'cryptographic' can be left out if the rouines from the library | |
36 | * being used are not cryptographic related :-). | |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | |
38 | * the apps directory (application code) you must include an acknowledgement: | |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | |
40 | * | |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
51 | * SUCH DAMAGE. | |
52 | * | |
53 | * The licence and distribution terms for any publically available version or | |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | |
55 | * copied and put under another distribution licence | |
56 | * [including the GNU Public Licence.] | |
57 | */ | |
e172d60d BM |
58 | /* ==================================================================== |
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | |
60 | * | |
61 | * Portions of the attached software ("Contribution") are developed by | |
62 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | |
63 | * | |
64 | * The Contribution is licensed pursuant to the OpenSSL open source | |
65 | * license provided above. | |
66 | * | |
e172d60d BM |
67 | * The ECDH and ECDSA speed test software is originally written by |
68 | * Sumit Gupta of Sun Microsystems Laboratories. | |
69 | * | |
70 | */ | |
d02b48c6 RE |
71 | |
72 | /* most of this code has been pilfered from my libdes speed.c program */ | |
73 | ||
85d686e7 RL |
74 | #ifndef OPENSSL_NO_SPEED |
75 | ||
d02b48c6 RE |
76 | #undef SECONDS |
77 | #define SECONDS 3 | |
dfeab068 RE |
78 | #define RSA_SECONDS 10 |
79 | #define DSA_SECONDS 10 | |
e172d60d BM |
80 | #define ECDSA_SECONDS 10 |
81 | #define ECDH_SECONDS 10 | |
d02b48c6 RE |
82 | |
83 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | |
84 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | |
85 | ||
86 | #undef PROG | |
87 | #define PROG speed_main | |
88 | ||
89 | #include <stdio.h> | |
90 | #include <stdlib.h> | |
4d8743f4 | 91 | |
d02b48c6 | 92 | #include <string.h> |
58964a49 | 93 | #include <math.h> |
d02b48c6 | 94 | #include "apps.h" |
cf1b7d96 | 95 | #ifdef OPENSSL_NO_STDIO |
d02b48c6 RE |
96 | #define APPS_WIN16 |
97 | #endif | |
ec577822 BM |
98 | #include <openssl/crypto.h> |
99 | #include <openssl/rand.h> | |
100 | #include <openssl/err.h> | |
646d5695 BL |
101 | #include <openssl/evp.h> |
102 | #include <openssl/objects.h> | |
f559f31b | 103 | #if !defined(OPENSSL_SYS_MSDOS) |
a4a8f7b3 | 104 | #include OPENSSL_UNISTD |
f559f31b | 105 | #endif |
d02b48c6 | 106 | |
4d8743f4 RL |
107 | #ifndef OPENSSL_SYS_NETWARE |
108 | #include <signal.h> | |
109 | #endif | |
110 | ||
c3bdbcf6 | 111 | #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX) |
2bfb4dbc | 112 | # define USE_TOD |
3e83e686 | 113 | #elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) |
2bfb4dbc | 114 | # define TIMES |
d02b48c6 | 115 | #endif |
3e83e686 | 116 | #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS) /* FIXME */ |
3132e196 RL |
117 | # define TIMEB |
118 | #endif | |
d02b48c6 | 119 | |
4d8743f4 RL |
120 | #if defined(OPENSSL_SYS_NETWARE) |
121 | #undef TIMES | |
122 | #undef TIMEB | |
123 | #include <time.h> | |
124 | #endif | |
125 | ||
d02b48c6 | 126 | #ifndef _IRIX |
2bfb4dbc | 127 | # include <time.h> |
d02b48c6 RE |
128 | #endif |
129 | #ifdef TIMES | |
2bfb4dbc BL |
130 | # include <sys/types.h> |
131 | # include <sys/times.h> | |
132 | #endif | |
133 | #ifdef USE_TOD | |
134 | # include <sys/time.h> | |
135 | # include <sys/resource.h> | |
d02b48c6 | 136 | #endif |
7d7d2cbc UM |
137 | |
138 | /* Depending on the VMS version, the tms structure is perhaps defined. | |
139 | The __TMS macro will show if it was. If it wasn't defined, we should | |
140 | undefine TIMES, since that tells the rest of the program how things | |
141 | should be handled. -- Richard Levitte */ | |
bc36ee62 | 142 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) |
7d7d2cbc | 143 | #undef TIMES |
d02b48c6 | 144 | #endif |
7d7d2cbc | 145 | |
3132e196 | 146 | #ifdef TIMEB |
d02b48c6 | 147 | #include <sys/timeb.h> |
3132e196 RL |
148 | #endif |
149 | ||
4d8743f4 | 150 | #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE) |
3132e196 RL |
151 | #error "It seems neither struct tms nor struct timeb is supported in this platform!" |
152 | #endif | |
d02b48c6 | 153 | |
dfeab068 RE |
154 | #if defined(sun) || defined(__ultrix) |
155 | #define _POSIX_SOURCE | |
d02b48c6 RE |
156 | #include <limits.h> |
157 | #include <sys/param.h> | |
158 | #endif | |
159 | ||
f0eae953 | 160 | #include <openssl/bn.h> |
cf1b7d96 | 161 | #ifndef OPENSSL_NO_DES |
125cc35b | 162 | #include <openssl/des.h> |
d02b48c6 | 163 | #endif |
ba1b8883 RL |
164 | #ifndef OPENSSL_NO_AES |
165 | #include <openssl/aes.h> | |
166 | #endif | |
e18eef3d BM |
167 | #ifndef OPENSSL_NO_CAMELLIA |
168 | #include <openssl/camellia.h> | |
169 | #endif | |
cf1b7d96 | 170 | #ifndef OPENSSL_NO_MD2 |
ec577822 | 171 | #include <openssl/md2.h> |
d02b48c6 | 172 | #endif |
cf1b7d96 | 173 | #ifndef OPENSSL_NO_MDC2 |
ec577822 | 174 | #include <openssl/mdc2.h> |
d02b48c6 | 175 | #endif |
cf1b7d96 | 176 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
177 | #include <openssl/md4.h> |
178 | #endif | |
cf1b7d96 | 179 | #ifndef OPENSSL_NO_MD5 |
ec577822 | 180 | #include <openssl/md5.h> |
5271ebd9 | 181 | #endif |
cf1b7d96 | 182 | #ifndef OPENSSL_NO_HMAC |
ec577822 | 183 | #include <openssl/hmac.h> |
d02b48c6 | 184 | #endif |
5271ebd9 | 185 | #include <openssl/evp.h> |
cf1b7d96 | 186 | #ifndef OPENSSL_NO_SHA |
ec577822 | 187 | #include <openssl/sha.h> |
d02b48c6 | 188 | #endif |
cf1b7d96 | 189 | #ifndef OPENSSL_NO_RIPEMD |
ec577822 | 190 | #include <openssl/ripemd.h> |
58964a49 | 191 | #endif |
cf1b7d96 | 192 | #ifndef OPENSSL_NO_RC4 |
ec577822 | 193 | #include <openssl/rc4.h> |
d02b48c6 | 194 | #endif |
cf1b7d96 | 195 | #ifndef OPENSSL_NO_RC5 |
ec577822 | 196 | #include <openssl/rc5.h> |
58964a49 | 197 | #endif |
cf1b7d96 | 198 | #ifndef OPENSSL_NO_RC2 |
ec577822 | 199 | #include <openssl/rc2.h> |
d02b48c6 | 200 | #endif |
cf1b7d96 | 201 | #ifndef OPENSSL_NO_IDEA |
ec577822 | 202 | #include <openssl/idea.h> |
d02b48c6 | 203 | #endif |
cf1b7d96 | 204 | #ifndef OPENSSL_NO_BF |
ec577822 | 205 | #include <openssl/blowfish.h> |
d02b48c6 | 206 | #endif |
cf1b7d96 | 207 | #ifndef OPENSSL_NO_CAST |
ec577822 | 208 | #include <openssl/cast.h> |
58964a49 | 209 | #endif |
cf1b7d96 | 210 | #ifndef OPENSSL_NO_RSA |
ec577822 | 211 | #include <openssl/rsa.h> |
f5d7a031 | 212 | #include "./testrsa.h" |
d02b48c6 | 213 | #endif |
ec577822 | 214 | #include <openssl/x509.h> |
cf1b7d96 | 215 | #ifndef OPENSSL_NO_DSA |
823a67b0 | 216 | #include <openssl/dsa.h> |
d02b48c6 RE |
217 | #include "./testdsa.h" |
218 | #endif | |
e172d60d BM |
219 | #ifndef OPENSSL_NO_ECDSA |
220 | #include <openssl/ecdsa.h> | |
221 | #endif | |
222 | #ifndef OPENSSL_NO_ECDH | |
223 | #include <openssl/ecdh.h> | |
224 | #endif | |
d02b48c6 | 225 | |
0991f070 GT |
226 | /* |
227 | * The following "HZ" timing stuff should be sync'd up with the code in | |
228 | * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think | |
229 | * this code is more up to date than libcrypto's so there may be features to | |
230 | * migrate over first. This is used in two places further down AFAICS. | |
231 | * The point is that nothing in openssl actually *uses* that tmdiff stuff, so | |
232 | * either speed.c should be using it or it should go because it's obviously not | |
233 | * useful enough. Anyone want to do a janitorial job on this? | |
234 | */ | |
235 | ||
d02b48c6 RE |
236 | /* The following if from times(3) man page. It may need to be changed */ |
237 | #ifndef HZ | |
450cee5c RL |
238 | # if defined(_SC_CLK_TCK) \ |
239 | && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000) | |
0991f070 | 240 | # define HZ sysconf(_SC_CLK_TCK) |
a4a8f7b3 RL |
241 | # else |
242 | # ifndef CLK_TCK | |
243 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | |
244 | # define HZ 100.0 | |
245 | # else /* _BSD_CLK_TCK_ */ | |
246 | # define HZ ((double)_BSD_CLK_TCK_) | |
247 | # endif | |
248 | # else /* CLK_TCK */ | |
7876e448 RL |
249 | # define HZ ((double)CLK_TCK) |
250 | # endif | |
d02b48c6 RE |
251 | # endif |
252 | #endif | |
253 | ||
4d8743f4 | 254 | #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE) |
66d3e748 RL |
255 | # define HAVE_FORK 1 |
256 | #endif | |
257 | ||
d02b48c6 | 258 | #undef BUFSIZE |
563cd0f2 | 259 | #define BUFSIZE ((long)1024*8+1) |
d02b48c6 RE |
260 | int run=0; |
261 | ||
7876e448 | 262 | static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0; |
0e211563 BL |
263 | static int mr=0; |
264 | static int usertime=1; | |
7876e448 | 265 | |
0e211563 | 266 | static double Time_F(int s); |
646d5695 | 267 | static void print_message(const char *s,long num,int length); |
689c6f25 NL |
268 | static void pkey_print_message(const char *str, const char *str2, |
269 | long num, int bits, int sec); | |
0e211563 | 270 | static void print_result(int alg,int run_no,int count,double time_used); |
66d3e748 | 271 | #ifdef HAVE_FORK |
0e211563 | 272 | static int do_multi(int multi); |
66d3e748 | 273 | #endif |
d02b48c6 | 274 | |
e18eef3d | 275 | #define ALGOR_NUM 24 |
0e211563 BL |
276 | #define SIZE_NUM 5 |
277 | #define RSA_NUM 4 | |
278 | #define DSA_NUM 3 | |
e172d60d | 279 | |
5c6bf031 | 280 | #define EC_NUM 16 |
e172d60d BM |
281 | #define MAX_ECDH_SIZE 256 |
282 | ||
0e211563 BL |
283 | static const char *names[ALGOR_NUM]={ |
284 | "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4", | |
285 | "des cbc","des ede3","idea cbc", | |
ba1b8883 | 286 | "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc", |
e18eef3d BM |
287 | "aes-128 cbc","aes-192 cbc","aes-256 cbc", |
288 | "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc", | |
289 | "evp","sha256","sha512"}; | |
0e211563 | 290 | static double results[ALGOR_NUM][SIZE_NUM]; |
ba1b8883 | 291 | static int lengths[SIZE_NUM]={16,64,256,1024,8*1024}; |
0e211563 BL |
292 | static double rsa_results[RSA_NUM][2]; |
293 | static double dsa_results[DSA_NUM][2]; | |
4913b88f | 294 | #ifndef OPENSSL_NO_ECDSA |
e172d60d | 295 | static double ecdsa_results[EC_NUM][2]; |
4913b88f NL |
296 | #endif |
297 | #ifndef OPENSSL_NO_ECDH | |
e172d60d | 298 | static double ecdh_results[EC_NUM][1]; |
4913b88f | 299 | #endif |
e172d60d | 300 | |
4913b88f NL |
301 | #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH)) |
302 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | |
303 | static int rnd_fake = 0; | |
304 | #endif | |
0e211563 | 305 | |
b83eddc5 DSH |
306 | #ifdef SIGALRM |
307 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | |
308 | #define SIGRETTYPE void | |
309 | #else | |
310 | #define SIGRETTYPE int | |
311 | #endif | |
312 | ||
d02b48c6 | 313 | static SIGRETTYPE sig_done(int sig); |
6b691a5c | 314 | static SIGRETTYPE sig_done(int sig) |
d02b48c6 RE |
315 | { |
316 | signal(SIGALRM,sig_done); | |
317 | run=0; | |
318 | #ifdef LINT | |
319 | sig=sig; | |
320 | #endif | |
321 | } | |
322 | #endif | |
323 | ||
324 | #define START 0 | |
325 | #define STOP 1 | |
326 | ||
4d8743f4 RL |
327 | #if defined(OPENSSL_SYS_NETWARE) |
328 | ||
329 | /* for NetWare the best we can do is use clock() which returns the | |
330 | * time, in hundredths of a second, since the NLM began executing | |
331 | */ | |
332 | static double Time_F(int s) | |
333 | { | |
334 | double ret; | |
335 | ||
336 | static clock_t tstart,tend; | |
337 | ||
338 | if (s == START) | |
339 | { | |
340 | tstart=clock(); | |
341 | return(0); | |
342 | } | |
343 | else | |
344 | { | |
345 | tend=clock(); | |
346 | ret=(double)((double)(tend)-(double)(tstart)); | |
347 | return((ret < 0.001)?0.001:ret); | |
348 | } | |
349 | } | |
350 | ||
351 | #else | |
352 | ||
0e211563 | 353 | static double Time_F(int s) |
d02b48c6 RE |
354 | { |
355 | double ret; | |
2bfb4dbc BL |
356 | |
357 | #ifdef USE_TOD | |
358 | if(usertime) | |
0991f070 | 359 | { |
2bfb4dbc BL |
360 | static struct rusage tstart,tend; |
361 | ||
7876e448 | 362 | getrusage_used = 1; |
2bfb4dbc BL |
363 | if (s == START) |
364 | { | |
365 | getrusage(RUSAGE_SELF,&tstart); | |
366 | return(0); | |
367 | } | |
368 | else | |
369 | { | |
370 | long i; | |
371 | ||
372 | getrusage(RUSAGE_SELF,&tend); | |
373 | i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec; | |
374 | ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec)) | |
375 | +((double)i)/1000000.0; | |
376 | return((ret < 0.001)?0.001:ret); | |
377 | } | |
378 | } | |
379 | else | |
380 | { | |
381 | static struct timeval tstart,tend; | |
382 | long i; | |
383 | ||
7876e448 | 384 | gettimeofday_used = 1; |
2bfb4dbc BL |
385 | if (s == START) |
386 | { | |
387 | gettimeofday(&tstart,NULL); | |
388 | return(0); | |
389 | } | |
390 | else | |
391 | { | |
392 | gettimeofday(&tend,NULL); | |
393 | i=(long)tend.tv_usec-(long)tstart.tv_usec; | |
394 | ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0; | |
395 | return((ret < 0.001)?0.001:ret); | |
396 | } | |
397 | } | |
398 | #else /* ndef USE_TOD */ | |
399 | ||
400 | # ifdef TIMES | |
4e74239c | 401 | if (usertime) |
d02b48c6 | 402 | { |
4e74239c | 403 | static struct tms tstart,tend; |
d02b48c6 | 404 | |
7876e448 | 405 | times_used = 1; |
4e74239c RL |
406 | if (s == START) |
407 | { | |
408 | times(&tstart); | |
409 | return(0); | |
410 | } | |
411 | else | |
412 | { | |
413 | times(&tend); | |
0991f070 GT |
414 | ret = HZ; |
415 | ret=(double)(tend.tms_utime-tstart.tms_utime) / ret; | |
4e74239c RL |
416 | return((ret < 1e-3)?1e-3:ret); |
417 | } | |
d02b48c6 | 418 | } |
2bfb4dbc | 419 | # endif /* times() */ |
3132e196 RL |
420 | # if defined(TIMES) && defined(TIMEB) |
421 | else | |
422 | # endif | |
3e83e686 RL |
423 | # ifdef OPENSSL_SYS_VXWORKS |
424 | { | |
425 | static unsigned long tick_start, tick_end; | |
426 | ||
427 | if( s == START ) | |
428 | { | |
429 | tick_start = tickGet(); | |
430 | return 0; | |
431 | } | |
432 | else | |
433 | { | |
434 | tick_end = tickGet(); | |
435 | ret = (double)(tick_end - tick_start) / (double)sysClkRateGet(); | |
436 | return((ret < 0.001)?0.001:ret); | |
437 | } | |
438 | } | |
439 | # elif defined(TIMEB) | |
d02b48c6 | 440 | { |
4e74239c RL |
441 | static struct timeb tstart,tend; |
442 | long i; | |
443 | ||
7876e448 | 444 | ftime_used = 1; |
4e74239c RL |
445 | if (s == START) |
446 | { | |
447 | ftime(&tstart); | |
448 | return(0); | |
449 | } | |
450 | else | |
451 | { | |
452 | ftime(&tend); | |
453 | i=(long)tend.millitm-(long)tstart.millitm; | |
454 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | |
455 | return((ret < 0.001)?0.001:ret); | |
456 | } | |
d02b48c6 | 457 | } |
3132e196 | 458 | # endif |
2bfb4dbc | 459 | #endif |
d02b48c6 | 460 | } |
4d8743f4 | 461 | #endif /* if defined(OPENSSL_SYS_NETWARE) */ |
d02b48c6 | 462 | |
176f31dd | 463 | |
4913b88f | 464 | #ifndef OPENSSL_NO_ECDH |
176f31dd | 465 | static const int KDF1_SHA1_len = 20; |
965a1cb9 | 466 | static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) |
176f31dd BM |
467 | { |
468 | #ifndef OPENSSL_NO_SHA | |
965a1cb9 | 469 | if (*outlen < SHA_DIGEST_LENGTH) |
176f31dd | 470 | return NULL; |
965a1cb9 NL |
471 | else |
472 | *outlen = SHA_DIGEST_LENGTH; | |
176f31dd BM |
473 | return SHA1(in, inlen, out); |
474 | #else | |
475 | return NULL; | |
4913b88f | 476 | #endif /* OPENSSL_NO_SHA */ |
176f31dd | 477 | } |
4913b88f | 478 | #endif /* OPENSSL_NO_ECDH */ |
176f31dd BM |
479 | |
480 | ||
667ac4ec RE |
481 | int MAIN(int, char **); |
482 | ||
6b691a5c | 483 | int MAIN(int argc, char **argv) |
d02b48c6 | 484 | { |
0b13e9f0 | 485 | #ifndef OPENSSL_NO_ENGINE |
1199e2d8 | 486 | ENGINE *e = NULL; |
0b13e9f0 | 487 | #endif |
d02b48c6 | 488 | unsigned char *buf=NULL,*buf2=NULL; |
18c77bf2 | 489 | int mret=1; |
af28dd6c | 490 | long count=0,save_count=0; |
18c77bf2 | 491 | int i,j,k; |
af28dd6c BM |
492 | #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) |
493 | long rsa_count; | |
494 | #endif | |
cf1b7d96 | 495 | #ifndef OPENSSL_NO_RSA |
5614bb91 | 496 | unsigned rsa_num; |
b2293b1e | 497 | #endif |
83c40e7f | 498 | unsigned char md[EVP_MAX_MD_SIZE]; |
cf1b7d96 | 499 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
500 | unsigned char md2[MD2_DIGEST_LENGTH]; |
501 | #endif | |
cf1b7d96 | 502 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
503 | unsigned char mdc2[MDC2_DIGEST_LENGTH]; |
504 | #endif | |
cf1b7d96 | 505 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
506 | unsigned char md4[MD4_DIGEST_LENGTH]; |
507 | #endif | |
cf1b7d96 | 508 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 | 509 | unsigned char md5[MD5_DIGEST_LENGTH]; |
58964a49 | 510 | unsigned char hmac[MD5_DIGEST_LENGTH]; |
d02b48c6 | 511 | #endif |
cf1b7d96 | 512 | #ifndef OPENSSL_NO_SHA |
d02b48c6 | 513 | unsigned char sha[SHA_DIGEST_LENGTH]; |
31e4ad25 | 514 | #ifndef OPENSSL_NO_SHA256 |
46ceb15c | 515 | unsigned char sha256[SHA256_DIGEST_LENGTH]; |
31e4ad25 AP |
516 | #endif |
517 | #ifndef OPENSSL_NO_SHA512 | |
46ceb15c | 518 | unsigned char sha512[SHA512_DIGEST_LENGTH]; |
d02b48c6 | 519 | #endif |
31e4ad25 | 520 | #endif |
cf1b7d96 | 521 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
522 | unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; |
523 | #endif | |
cf1b7d96 | 524 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
525 | RC4_KEY rc4_ks; |
526 | #endif | |
cf1b7d96 | 527 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
528 | RC5_32_KEY rc5_ks; |
529 | #endif | |
cf1b7d96 | 530 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
531 | RC2_KEY rc2_ks; |
532 | #endif | |
cf1b7d96 | 533 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
534 | IDEA_KEY_SCHEDULE idea_ks; |
535 | #endif | |
cf1b7d96 | 536 | #ifndef OPENSSL_NO_BF |
d02b48c6 | 537 | BF_KEY bf_ks; |
58964a49 | 538 | #endif |
cf1b7d96 | 539 | #ifndef OPENSSL_NO_CAST |
58964a49 | 540 | CAST_KEY cast_ks; |
d02b48c6 | 541 | #endif |
ba1b8883 | 542 | static const unsigned char key16[16]= |
d02b48c6 RE |
543 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, |
544 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | |
e00b165e | 545 | #ifndef OPENSSL_NO_AES |
ba1b8883 RL |
546 | static const unsigned char key24[24]= |
547 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | |
548 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, | |
549 | 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | |
550 | static const unsigned char key32[32]= | |
551 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | |
552 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, | |
553 | 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34, | |
554 | 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56}; | |
e00b165e | 555 | #endif |
e18eef3d BM |
556 | #ifndef OPENSSL_NO_CAMELLIA |
557 | static const unsigned char ckey24[24]= | |
558 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | |
559 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, | |
560 | 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | |
561 | static const unsigned char ckey32[32]= | |
562 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | |
563 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, | |
564 | 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34, | |
565 | 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56}; | |
566 | #endif | |
ba1b8883 RL |
567 | #ifndef OPENSSL_NO_AES |
568 | #define MAX_BLOCK_SIZE 128 | |
569 | #else | |
570 | #define MAX_BLOCK_SIZE 64 | |
571 | #endif | |
572 | unsigned char DES_iv[8]; | |
573 | unsigned char iv[MAX_BLOCK_SIZE/8]; | |
cf1b7d96 | 574 | #ifndef OPENSSL_NO_DES |
c2e4f17c | 575 | DES_cblock *buf_as_des_cblock = NULL; |
125cc35b RL |
576 | static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; |
577 | static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | |
578 | static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | |
c2e4f17c RL |
579 | DES_key_schedule sch; |
580 | DES_key_schedule sch2; | |
581 | DES_key_schedule sch3; | |
d02b48c6 | 582 | #endif |
ba1b8883 RL |
583 | #ifndef OPENSSL_NO_AES |
584 | AES_KEY aes_ks1, aes_ks2, aes_ks3; | |
585 | #endif | |
e18eef3d BM |
586 | #ifndef OPENSSL_NO_CAMELLIA |
587 | CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3; | |
588 | #endif | |
d02b48c6 RE |
589 | #define D_MD2 0 |
590 | #define D_MDC2 1 | |
3009458e RL |
591 | #define D_MD4 2 |
592 | #define D_MD5 3 | |
593 | #define D_HMAC 4 | |
594 | #define D_SHA1 5 | |
595 | #define D_RMD160 6 | |
596 | #define D_RC4 7 | |
597 | #define D_CBC_DES 8 | |
598 | #define D_EDE3_DES 9 | |
599 | #define D_CBC_IDEA 10 | |
600 | #define D_CBC_RC2 11 | |
601 | #define D_CBC_RC5 12 | |
602 | #define D_CBC_BF 13 | |
603 | #define D_CBC_CAST 14 | |
ba1b8883 RL |
604 | #define D_CBC_128_AES 15 |
605 | #define D_CBC_192_AES 16 | |
606 | #define D_CBC_256_AES 17 | |
e18eef3d BM |
607 | #define D_CBC_128_CML 18 |
608 | #define D_CBC_192_CML 19 | |
609 | #define D_CBC_256_CML 20 | |
610 | #define D_EVP 21 | |
611 | #define D_SHA256 22 | |
612 | #define D_SHA512 23 | |
ba1b8883 | 613 | double d=0.0; |
d02b48c6 | 614 | long c[ALGOR_NUM][SIZE_NUM]; |
d02b48c6 RE |
615 | #define R_DSA_512 0 |
616 | #define R_DSA_1024 1 | |
617 | #define R_DSA_2048 2 | |
618 | #define R_RSA_512 0 | |
619 | #define R_RSA_1024 1 | |
620 | #define R_RSA_2048 2 | |
621 | #define R_RSA_4096 3 | |
e172d60d BM |
622 | |
623 | #define R_EC_P160 0 | |
5c6bf031 BM |
624 | #define R_EC_P192 1 |
625 | #define R_EC_P224 2 | |
626 | #define R_EC_P256 3 | |
627 | #define R_EC_P384 4 | |
628 | #define R_EC_P521 5 | |
629 | #define R_EC_K163 6 | |
630 | #define R_EC_K233 7 | |
631 | #define R_EC_K283 8 | |
632 | #define R_EC_K409 9 | |
633 | #define R_EC_K571 10 | |
634 | #define R_EC_B163 11 | |
635 | #define R_EC_B233 12 | |
636 | #define R_EC_B283 13 | |
637 | #define R_EC_B409 14 | |
638 | #define R_EC_B571 15 | |
e172d60d | 639 | |
cf1b7d96 | 640 | #ifndef OPENSSL_NO_RSA |
d02b48c6 | 641 | RSA *rsa_key[RSA_NUM]; |
d02b48c6 | 642 | long rsa_c[RSA_NUM][2]; |
d02b48c6 | 643 | static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096}; |
d02b48c6 RE |
644 | static unsigned char *rsa_data[RSA_NUM]= |
645 | {test512,test1024,test2048,test4096}; | |
646 | static int rsa_data_length[RSA_NUM]={ | |
647 | sizeof(test512),sizeof(test1024), | |
648 | sizeof(test2048),sizeof(test4096)}; | |
58964a49 | 649 | #endif |
cf1b7d96 | 650 | #ifndef OPENSSL_NO_DSA |
58964a49 RE |
651 | DSA *dsa_key[DSA_NUM]; |
652 | long dsa_c[DSA_NUM][2]; | |
58964a49 RE |
653 | static unsigned int dsa_bits[DSA_NUM]={512,1024,2048}; |
654 | #endif | |
e172d60d BM |
655 | #ifndef OPENSSL_NO_EC |
656 | /* We only test over the following curves as they are representative, | |
657 | * To add tests over more curves, simply add the curve NID | |
658 | * and curve name to the following arrays and increase the | |
659 | * EC_NUM value accordingly. | |
660 | */ | |
661 | static unsigned int test_curves[EC_NUM] = | |
662 | { | |
663 | /* Prime Curves */ | |
7eb18f12 | 664 | NID_secp160r1, |
5c6bf031 | 665 | NID_X9_62_prime192v1, |
7eb18f12 BM |
666 | NID_secp224r1, |
667 | NID_X9_62_prime256v1, | |
668 | NID_secp384r1, | |
669 | NID_secp521r1, | |
e172d60d | 670 | /* Binary Curves */ |
7eb18f12 BM |
671 | NID_sect163k1, |
672 | NID_sect233k1, | |
673 | NID_sect283k1, | |
674 | NID_sect409k1, | |
675 | NID_sect571k1, | |
676 | NID_sect163r2, | |
677 | NID_sect233r1, | |
678 | NID_sect283r1, | |
679 | NID_sect409r1, | |
680 | NID_sect571r1 | |
e172d60d | 681 | }; |
689c6f25 | 682 | static const char * test_curves_names[EC_NUM] = |
e172d60d BM |
683 | { |
684 | /* Prime Curves */ | |
685 | "secp160r1", | |
5c6bf031 | 686 | "nistp192", |
e172d60d BM |
687 | "nistp224", |
688 | "nistp256", | |
689 | "nistp384", | |
690 | "nistp521", | |
691 | /* Binary Curves */ | |
692 | "nistk163", | |
693 | "nistk233", | |
694 | "nistk283", | |
695 | "nistk409", | |
696 | "nistk571", | |
697 | "nistb163", | |
698 | "nistb233", | |
699 | "nistb283", | |
700 | "nistb409", | |
701 | "nistb571" | |
702 | }; | |
703 | static int test_curves_bits[EC_NUM] = | |
704 | { | |
5c6bf031 | 705 | 160, 192, 224, 256, 384, 521, |
e172d60d BM |
706 | 163, 233, 283, 409, 571, |
707 | 163, 233, 283, 409, 571 | |
708 | }; | |
709 | ||
710 | #endif | |
711 | ||
712 | #ifndef OPENSSL_NO_ECDSA | |
689c6f25 NL |
713 | unsigned char ecdsasig[256]; |
714 | unsigned int ecdsasiglen; | |
715 | EC_KEY *ecdsa[EC_NUM]; | |
716 | long ecdsa_c[EC_NUM][2]; | |
e172d60d BM |
717 | #endif |
718 | ||
719 | #ifndef OPENSSL_NO_ECDH | |
689c6f25 NL |
720 | EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM]; |
721 | unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE]; | |
722 | int secret_size_a, secret_size_b; | |
723 | int ecdh_checks = 0; | |
724 | int secret_idx = 0; | |
725 | long ecdh_c[EC_NUM][2]; | |
e172d60d BM |
726 | #endif |
727 | ||
d02b48c6 RE |
728 | int rsa_doit[RSA_NUM]; |
729 | int dsa_doit[DSA_NUM]; | |
4913b88f | 730 | #ifndef OPENSSL_NO_ECDSA |
e172d60d | 731 | int ecdsa_doit[EC_NUM]; |
4913b88f NL |
732 | #endif |
733 | #ifndef OPENSSL_NO_ECDH | |
e172d60d | 734 | int ecdh_doit[EC_NUM]; |
4913b88f | 735 | #endif |
58964a49 | 736 | int doit[ALGOR_NUM]; |
d02b48c6 | 737 | int pr_header=0; |
83c40e7f RL |
738 | const EVP_CIPHER *evp_cipher=NULL; |
739 | const EVP_MD *evp_md=NULL; | |
3f37e73b | 740 | int decrypt=0; |
66d3e748 | 741 | #ifdef HAVE_FORK |
0e211563 | 742 | int multi=0; |
66d3e748 | 743 | #endif |
4e74239c RL |
744 | |
745 | #ifndef TIMES | |
746 | usertime=-1; | |
747 | #endif | |
d02b48c6 RE |
748 | |
749 | apps_startup(); | |
396f6314 | 750 | memset(results, 0, sizeof(results)); |
cf1b7d96 | 751 | #ifndef OPENSSL_NO_DSA |
dfeab068 RE |
752 | memset(dsa_key,0,sizeof(dsa_key)); |
753 | #endif | |
e172d60d BM |
754 | #ifndef OPENSSL_NO_ECDSA |
755 | for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL; | |
756 | #endif | |
757 | #ifndef OPENSSL_NO_ECDH | |
758 | for (i=0; i<EC_NUM; i++) | |
759 | { | |
760 | ecdh_a[i] = NULL; | |
761 | ecdh_b[i] = NULL; | |
762 | } | |
763 | #endif | |
764 | ||
d02b48c6 RE |
765 | |
766 | if (bio_err == NULL) | |
767 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | |
58964a49 | 768 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); |
d02b48c6 | 769 | |
3647bee2 DSH |
770 | if (!load_config(bio_err, NULL)) |
771 | goto end; | |
772 | ||
cf1b7d96 | 773 | #ifndef OPENSSL_NO_RSA |
dfeab068 | 774 | memset(rsa_key,0,sizeof(rsa_key)); |
d02b48c6 RE |
775 | for (i=0; i<RSA_NUM; i++) |
776 | rsa_key[i]=NULL; | |
dfeab068 | 777 | #endif |
d02b48c6 | 778 | |
26a3a48d | 779 | if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) |
d02b48c6 RE |
780 | { |
781 | BIO_printf(bio_err,"out of memory\n"); | |
782 | goto end; | |
783 | } | |
cf1b7d96 | 784 | #ifndef OPENSSL_NO_DES |
125cc35b | 785 | buf_as_des_cblock = (DES_cblock *)buf; |
5676d8cb | 786 | #endif |
26a3a48d | 787 | if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) |
d02b48c6 RE |
788 | { |
789 | BIO_printf(bio_err,"out of memory\n"); | |
790 | goto end; | |
791 | } | |
792 | ||
793 | memset(c,0,sizeof(c)); | |
ba1b8883 | 794 | memset(DES_iv,0,sizeof(DES_iv)); |
d02b48c6 RE |
795 | memset(iv,0,sizeof(iv)); |
796 | ||
797 | for (i=0; i<ALGOR_NUM; i++) | |
798 | doit[i]=0; | |
799 | for (i=0; i<RSA_NUM; i++) | |
800 | rsa_doit[i]=0; | |
801 | for (i=0; i<DSA_NUM; i++) | |
802 | dsa_doit[i]=0; | |
e172d60d BM |
803 | #ifndef OPENSSL_NO_ECDSA |
804 | for (i=0; i<EC_NUM; i++) | |
805 | ecdsa_doit[i]=0; | |
806 | #endif | |
807 | #ifndef OPENSSL_NO_ECDH | |
808 | for (i=0; i<EC_NUM; i++) | |
809 | ecdh_doit[i]=0; | |
810 | #endif | |
811 | ||
d02b48c6 RE |
812 | |
813 | j=0; | |
814 | argc--; | |
815 | argv++; | |
816 | while (argc) | |
817 | { | |
4e74239c | 818 | if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0)) |
7876e448 | 819 | { |
4e74239c | 820 | usertime = 0; |
7876e448 RL |
821 | j--; /* Otherwise, -elapsed gets confused with |
822 | an algorithm. */ | |
823 | } | |
646d5695 BL |
824 | else if ((argc > 0) && (strcmp(*argv,"-evp") == 0)) |
825 | { | |
826 | argc--; | |
827 | argv++; | |
828 | if(argc == 0) | |
829 | { | |
830 | BIO_printf(bio_err,"no EVP given\n"); | |
831 | goto end; | |
832 | } | |
83c40e7f RL |
833 | evp_cipher=EVP_get_cipherbyname(*argv); |
834 | if(!evp_cipher) | |
646d5695 | 835 | { |
83c40e7f RL |
836 | evp_md=EVP_get_digestbyname(*argv); |
837 | } | |
838 | if(!evp_cipher && !evp_md) | |
839 | { | |
840 | BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv); | |
646d5695 BL |
841 | goto end; |
842 | } | |
843 | doit[D_EVP]=1; | |
844 | } | |
7876e448 RL |
845 | else if (argc > 0 && !strcmp(*argv,"-decrypt")) |
846 | { | |
3f37e73b | 847 | decrypt=1; |
7876e448 RL |
848 | j--; /* Otherwise, -elapsed gets confused with |
849 | an algorithm. */ | |
850 | } | |
0b13e9f0 | 851 | #ifndef OPENSSL_NO_ENGINE |
7876e448 | 852 | else if ((argc > 0) && (strcmp(*argv,"-engine") == 0)) |
5270e702 RL |
853 | { |
854 | argc--; | |
855 | argv++; | |
856 | if(argc == 0) | |
857 | { | |
858 | BIO_printf(bio_err,"no engine given\n"); | |
859 | goto end; | |
860 | } | |
531d630b RL |
861 | e = setup_engine(bio_err, *argv, 0); |
862 | /* j will be increased again further down. We just | |
5270e702 RL |
863 | don't want speed to confuse an engine with an |
864 | algorithm, especially when none is given (which | |
865 | means all of them should be run) */ | |
866 | j--; | |
867 | } | |
0b13e9f0 | 868 | #endif |
66d3e748 | 869 | #ifdef HAVE_FORK |
0e211563 BL |
870 | else if ((argc > 0) && (strcmp(*argv,"-multi") == 0)) |
871 | { | |
872 | argc--; | |
873 | argv++; | |
874 | if(argc == 0) | |
875 | { | |
876 | BIO_printf(bio_err,"no multi count given\n"); | |
877 | goto end; | |
878 | } | |
879 | multi=atoi(argv[0]); | |
880 | if(multi <= 0) | |
881 | { | |
882 | BIO_printf(bio_err,"bad multi count\n"); | |
883 | goto end; | |
884 | } | |
66d3e748 RL |
885 | j--; /* Otherwise, -mr gets confused with |
886 | an algorithm. */ | |
0e211563 | 887 | } |
66d3e748 | 888 | #endif |
0e211563 BL |
889 | else if (argc > 0 && !strcmp(*argv,"-mr")) |
890 | { | |
891 | mr=1; | |
892 | j--; /* Otherwise, -mr gets confused with | |
893 | an algorithm. */ | |
894 | } | |
5270e702 | 895 | else |
cf1b7d96 | 896 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
897 | if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1; |
898 | else | |
899 | #endif | |
cf1b7d96 | 900 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
901 | if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1; |
902 | else | |
903 | #endif | |
cf1b7d96 | 904 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
905 | if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1; |
906 | else | |
907 | #endif | |
cf1b7d96 | 908 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 RE |
909 | if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1; |
910 | else | |
911 | #endif | |
cf1b7d96 | 912 | #ifndef OPENSSL_NO_MD5 |
58964a49 | 913 | if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1; |
d02b48c6 RE |
914 | else |
915 | #endif | |
cf1b7d96 | 916 | #ifndef OPENSSL_NO_SHA |
d02b48c6 RE |
917 | if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1; |
918 | else | |
46ceb15c AP |
919 | if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1, |
920 | doit[D_SHA256]=1, | |
921 | doit[D_SHA512]=1; | |
922 | else | |
31e4ad25 | 923 | #ifndef OPENSSL_NO_SHA256 |
63ba7e29 | 924 | if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1; |
46ceb15c | 925 | else |
31e4ad25 AP |
926 | #endif |
927 | #ifndef OPENSSL_NO_SHA512 | |
63ba7e29 | 928 | if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1; |
58964a49 RE |
929 | else |
930 | #endif | |
31e4ad25 | 931 | #endif |
cf1b7d96 | 932 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
933 | if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1; |
934 | else | |
935 | if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1; | |
936 | else | |
937 | if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1; | |
938 | else | |
d02b48c6 | 939 | #endif |
cf1b7d96 | 940 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
941 | if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; |
942 | else | |
943 | #endif | |
cf1b7d96 | 944 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
945 | if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; |
946 | else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; | |
947 | else | |
948 | #endif | |
ba1b8883 RL |
949 | #ifndef OPENSSL_NO_AES |
950 | if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1; | |
951 | else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1; | |
952 | else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1; | |
953 | else | |
954 | #endif | |
e18eef3d BM |
955 | #ifndef OPENSSL_NO_CAMELLIA |
956 | if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1; | |
957 | else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1; | |
958 | else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1; | |
959 | else | |
960 | #endif | |
cf1b7d96 | 961 | #ifndef OPENSSL_NO_RSA |
ccb9643f | 962 | #if 0 /* was: #ifdef RSAref */ |
d02b48c6 RE |
963 | if (strcmp(*argv,"rsaref") == 0) |
964 | { | |
5270e702 | 965 | RSA_set_default_openssl_method(RSA_PKCS1_RSAref()); |
d02b48c6 RE |
966 | j--; |
967 | } | |
968 | else | |
969 | #endif | |
c1cd88a0 | 970 | #ifndef RSA_NULL |
e170a5c0 | 971 | if (strcmp(*argv,"openssl") == 0) |
d02b48c6 | 972 | { |
6dc5d570 | 973 | RSA_set_default_method(RSA_PKCS1_SSLeay()); |
d02b48c6 RE |
974 | j--; |
975 | } | |
976 | else | |
c1cd88a0 | 977 | #endif |
cf1b7d96 | 978 | #endif /* !OPENSSL_NO_RSA */ |
d02b48c6 RE |
979 | if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; |
980 | else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; | |
981 | else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2; | |
982 | else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2; | |
983 | else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2; | |
984 | else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2; | |
985 | else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2; | |
986 | else | |
cf1b7d96 | 987 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
988 | if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1; |
989 | else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1; | |
990 | else | |
991 | #endif | |
cf1b7d96 | 992 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
993 | if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1; |
994 | else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1; | |
995 | else | |
996 | #endif | |
cf1b7d96 | 997 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
998 | if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1; |
999 | else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1; | |
1000 | else | |
1001 | #endif | |
cf1b7d96 | 1002 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
1003 | if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1; |
1004 | else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1; | |
58964a49 RE |
1005 | else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1; |
1006 | else | |
1007 | #endif | |
cf1b7d96 | 1008 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
1009 | if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1; |
1010 | else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1; | |
1011 | else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1; | |
d02b48c6 RE |
1012 | else |
1013 | #endif | |
cf1b7d96 | 1014 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
1015 | if (strcmp(*argv,"des") == 0) |
1016 | { | |
1017 | doit[D_CBC_DES]=1; | |
1018 | doit[D_EDE3_DES]=1; | |
1019 | } | |
1020 | else | |
1021 | #endif | |
ba1b8883 RL |
1022 | #ifndef OPENSSL_NO_AES |
1023 | if (strcmp(*argv,"aes") == 0) | |
1024 | { | |
1025 | doit[D_CBC_128_AES]=1; | |
1026 | doit[D_CBC_192_AES]=1; | |
1027 | doit[D_CBC_256_AES]=1; | |
1028 | } | |
1029 | else | |
1030 | #endif | |
e18eef3d BM |
1031 | #ifndef OPENSSL_NO_CAMELLIA |
1032 | if (strcmp(*argv,"camellia") == 0) | |
1033 | { | |
1034 | doit[D_CBC_128_CML]=1; | |
1035 | doit[D_CBC_192_CML]=1; | |
1036 | doit[D_CBC_256_CML]=1; | |
1037 | } | |
1038 | else | |
1039 | #endif | |
cf1b7d96 | 1040 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1041 | if (strcmp(*argv,"rsa") == 0) |
1042 | { | |
1043 | rsa_doit[R_RSA_512]=1; | |
1044 | rsa_doit[R_RSA_1024]=1; | |
1045 | rsa_doit[R_RSA_2048]=1; | |
1046 | rsa_doit[R_RSA_4096]=1; | |
1047 | } | |
1048 | else | |
1049 | #endif | |
cf1b7d96 | 1050 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
1051 | if (strcmp(*argv,"dsa") == 0) |
1052 | { | |
1053 | dsa_doit[R_DSA_512]=1; | |
1054 | dsa_doit[R_DSA_1024]=1; | |
cdb42bcf | 1055 | dsa_doit[R_DSA_2048]=1; |
d02b48c6 RE |
1056 | } |
1057 | else | |
e172d60d BM |
1058 | #endif |
1059 | #ifndef OPENSSL_NO_ECDSA | |
1060 | if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2; | |
7ab2d303 | 1061 | else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2; |
e172d60d BM |
1062 | else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2; |
1063 | else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2; | |
1064 | else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2; | |
1065 | else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2; | |
1066 | else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2; | |
1067 | else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2; | |
1068 | else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2; | |
1069 | else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2; | |
1070 | else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2; | |
1071 | else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2; | |
1072 | else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2; | |
1073 | else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2; | |
1074 | else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2; | |
1075 | else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2; | |
1076 | else if (strcmp(*argv,"ecdsa") == 0) | |
1077 | { | |
1078 | for (i=0; i < EC_NUM; i++) | |
1079 | ecdsa_doit[i]=1; | |
1080 | } | |
1081 | else | |
1082 | #endif | |
1083 | #ifndef OPENSSL_NO_ECDH | |
1084 | if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2; | |
7ab2d303 | 1085 | else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2; |
e172d60d BM |
1086 | else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2; |
1087 | else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2; | |
1088 | else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2; | |
1089 | else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2; | |
1090 | else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2; | |
1091 | else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2; | |
1092 | else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2; | |
1093 | else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2; | |
1094 | else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2; | |
1095 | else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2; | |
1096 | else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2; | |
1097 | else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2; | |
1098 | else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2; | |
1099 | else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2; | |
1100 | else if (strcmp(*argv,"ecdh") == 0) | |
1101 | { | |
1102 | for (i=0; i < EC_NUM; i++) | |
1103 | ecdh_doit[i]=1; | |
1104 | } | |
1105 | else | |
d02b48c6 RE |
1106 | #endif |
1107 | { | |
3009458e RL |
1108 | BIO_printf(bio_err,"Error: bad option or value\n"); |
1109 | BIO_printf(bio_err,"\n"); | |
1110 | BIO_printf(bio_err,"Available values:\n"); | |
cf1b7d96 | 1111 | #ifndef OPENSSL_NO_MD2 |
3009458e RL |
1112 | BIO_printf(bio_err,"md2 "); |
1113 | #endif | |
cf1b7d96 | 1114 | #ifndef OPENSSL_NO_MDC2 |
3009458e RL |
1115 | BIO_printf(bio_err,"mdc2 "); |
1116 | #endif | |
cf1b7d96 | 1117 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
1118 | BIO_printf(bio_err,"md4 "); |
1119 | #endif | |
cf1b7d96 | 1120 | #ifndef OPENSSL_NO_MD5 |
3009458e | 1121 | BIO_printf(bio_err,"md5 "); |
cf1b7d96 | 1122 | #ifndef OPENSSL_NO_HMAC |
3009458e RL |
1123 | BIO_printf(bio_err,"hmac "); |
1124 | #endif | |
1125 | #endif | |
cf1b7d96 | 1126 | #ifndef OPENSSL_NO_SHA1 |
3009458e | 1127 | BIO_printf(bio_err,"sha1 "); |
31e4ad25 AP |
1128 | #endif |
1129 | #ifndef OPENSSL_NO_SHA256 | |
1130 | BIO_printf(bio_err,"sha256 "); | |
1131 | #endif | |
1132 | #ifndef OPENSSL_NO_SHA512 | |
1133 | BIO_printf(bio_err,"sha512 "); | |
3009458e | 1134 | #endif |
cf1b7d96 | 1135 | #ifndef OPENSSL_NO_RIPEMD160 |
3009458e RL |
1136 | BIO_printf(bio_err,"rmd160"); |
1137 | #endif | |
cf1b7d96 RL |
1138 | #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \ |
1139 | !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \ | |
1140 | !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) | |
3009458e RL |
1141 | BIO_printf(bio_err,"\n"); |
1142 | #endif | |
1143 | ||
cf1b7d96 | 1144 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
1145 | BIO_printf(bio_err,"idea-cbc "); |
1146 | #endif | |
cf1b7d96 | 1147 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
1148 | BIO_printf(bio_err,"rc2-cbc "); |
1149 | #endif | |
cf1b7d96 | 1150 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
1151 | BIO_printf(bio_err,"rc5-cbc "); |
1152 | #endif | |
cf1b7d96 | 1153 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
1154 | BIO_printf(bio_err,"bf-cbc"); |
1155 | #endif | |
cf1b7d96 RL |
1156 | #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ |
1157 | !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5) | |
d02b48c6 RE |
1158 | BIO_printf(bio_err,"\n"); |
1159 | #endif | |
ba1b8883 | 1160 | #ifndef OPENSSL_NO_DES |
d02b48c6 | 1161 | BIO_printf(bio_err,"des-cbc des-ede3 "); |
ba1b8883 RL |
1162 | #endif |
1163 | #ifndef OPENSSL_NO_AES | |
1164 | BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc "); | |
1165 | #endif | |
e18eef3d BM |
1166 | #ifndef OPENSSL_NO_CAMELLIA |
1167 | BIO_printf(bio_err,"\n"); | |
1168 | BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc "); | |
1169 | #endif | |
cf1b7d96 | 1170 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
1171 | BIO_printf(bio_err,"rc4"); |
1172 | #endif | |
3009458e RL |
1173 | BIO_printf(bio_err,"\n"); |
1174 | ||
cf1b7d96 | 1175 | #ifndef OPENSSL_NO_RSA |
3009458e | 1176 | BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n"); |
d02b48c6 | 1177 | #endif |
3009458e | 1178 | |
cf1b7d96 | 1179 | #ifndef OPENSSL_NO_DSA |
3009458e RL |
1180 | BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n"); |
1181 | #endif | |
e172d60d | 1182 | #ifndef OPENSSL_NO_ECDSA |
7ab2d303 | 1183 | BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n"); |
e172d60d BM |
1184 | BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n"); |
1185 | BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n"); | |
1186 | BIO_printf(bio_err,"ecdsa\n"); | |
1187 | #endif | |
1188 | #ifndef OPENSSL_NO_ECDH | |
7ab2d303 | 1189 | BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n"); |
e172d60d BM |
1190 | BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n"); |
1191 | BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n"); | |
1192 | BIO_printf(bio_err,"ecdh\n"); | |
1193 | #endif | |
3009458e | 1194 | |
cf1b7d96 | 1195 | #ifndef OPENSSL_NO_IDEA |
3009458e RL |
1196 | BIO_printf(bio_err,"idea "); |
1197 | #endif | |
cf1b7d96 | 1198 | #ifndef OPENSSL_NO_RC2 |
3009458e RL |
1199 | BIO_printf(bio_err,"rc2 "); |
1200 | #endif | |
cf1b7d96 | 1201 | #ifndef OPENSSL_NO_DES |
3009458e | 1202 | BIO_printf(bio_err,"des "); |
d02b48c6 | 1203 | #endif |
ba1b8883 RL |
1204 | #ifndef OPENSSL_NO_AES |
1205 | BIO_printf(bio_err,"aes "); | |
1206 | #endif | |
e18eef3d BM |
1207 | #ifndef OPENSSL_NO_CAMELLIA |
1208 | BIO_printf(bio_err,"camellia "); | |
1209 | #endif | |
cf1b7d96 | 1210 | #ifndef OPENSSL_NO_RSA |
3009458e RL |
1211 | BIO_printf(bio_err,"rsa "); |
1212 | #endif | |
cf1b7d96 | 1213 | #ifndef OPENSSL_NO_BF |
3009458e RL |
1214 | BIO_printf(bio_err,"blowfish"); |
1215 | #endif | |
cf1b7d96 RL |
1216 | #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ |
1217 | !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \ | |
e18eef3d BM |
1218 | !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES) || \ |
1219 | !defined(OPENSSL_NO_CAMELLIA) | |
4e74239c | 1220 | BIO_printf(bio_err,"\n"); |
3009458e RL |
1221 | #endif |
1222 | ||
4e74239c | 1223 | BIO_printf(bio_err,"\n"); |
3009458e | 1224 | BIO_printf(bio_err,"Available options:\n"); |
5d9470ff | 1225 | #if defined(TIMES) || defined(USE_TOD) |
4e74239c | 1226 | BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n"); |
3132e196 | 1227 | #endif |
0b13e9f0 | 1228 | #ifndef OPENSSL_NO_ENGINE |
5270e702 | 1229 | BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n"); |
0b13e9f0 | 1230 | #endif |
0e211563 BL |
1231 | BIO_printf(bio_err,"-evp e use EVP e.\n"); |
1232 | BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n"); | |
1233 | BIO_printf(bio_err,"-mr produce machine readable output.\n"); | |
66d3e748 | 1234 | #ifdef HAVE_FORK |
0e211563 | 1235 | BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n"); |
66d3e748 | 1236 | #endif |
d02b48c6 RE |
1237 | goto end; |
1238 | } | |
1239 | argc--; | |
1240 | argv++; | |
1241 | j++; | |
1242 | } | |
1243 | ||
66d3e748 | 1244 | #ifdef HAVE_FORK |
0e211563 BL |
1245 | if(multi && do_multi(multi)) |
1246 | goto show_res; | |
66d3e748 | 1247 | #endif |
0e211563 | 1248 | |
d02b48c6 RE |
1249 | if (j == 0) |
1250 | { | |
1251 | for (i=0; i<ALGOR_NUM; i++) | |
53d28679 BM |
1252 | { |
1253 | if (i != D_EVP) | |
1254 | doit[i]=1; | |
1255 | } | |
d02b48c6 RE |
1256 | for (i=0; i<RSA_NUM; i++) |
1257 | rsa_doit[i]=1; | |
1258 | for (i=0; i<DSA_NUM; i++) | |
1259 | dsa_doit[i]=1; | |
1260 | } | |
1261 | for (i=0; i<ALGOR_NUM; i++) | |
1262 | if (doit[i]) pr_header++; | |
1263 | ||
0e211563 | 1264 | if (usertime == 0 && !mr) |
4e74239c | 1265 | BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n"); |
0e211563 | 1266 | if (usertime <= 0 && !mr) |
4e74239c RL |
1267 | { |
1268 | BIO_printf(bio_err,"To get the most accurate results, try to run this\n"); | |
1269 | BIO_printf(bio_err,"program when this computer is idle.\n"); | |
1270 | } | |
d02b48c6 | 1271 | |
cf1b7d96 | 1272 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1273 | for (i=0; i<RSA_NUM; i++) |
1274 | { | |
5e4ca422 | 1275 | const unsigned char *p; |
d02b48c6 RE |
1276 | |
1277 | p=rsa_data[i]; | |
1278 | rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]); | |
1279 | if (rsa_key[i] == NULL) | |
1280 | { | |
1281 | BIO_printf(bio_err,"internal error loading RSA key number %d\n",i); | |
1282 | goto end; | |
1283 | } | |
58964a49 RE |
1284 | #if 0 |
1285 | else | |
1286 | { | |
0e211563 BL |
1287 | BIO_printf(bio_err,mr ? "+RK:%d:" |
1288 | : "Loaded RSA key, %d bit modulus and e= 0x", | |
1289 | BN_num_bits(rsa_key[i]->n)); | |
58964a49 RE |
1290 | BN_print(bio_err,rsa_key[i]->e); |
1291 | BIO_printf(bio_err,"\n"); | |
1292 | } | |
1293 | #endif | |
d02b48c6 RE |
1294 | } |
1295 | #endif | |
1296 | ||
cf1b7d96 | 1297 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
1298 | dsa_key[0]=get_dsa512(); |
1299 | dsa_key[1]=get_dsa1024(); | |
1300 | dsa_key[2]=get_dsa2048(); | |
1301 | #endif | |
1302 | ||
cf1b7d96 | 1303 | #ifndef OPENSSL_NO_DES |
c2e4f17c RL |
1304 | DES_set_key_unchecked(&key,&sch); |
1305 | DES_set_key_unchecked(&key2,&sch2); | |
1306 | DES_set_key_unchecked(&key3,&sch3); | |
d02b48c6 | 1307 | #endif |
ba1b8883 RL |
1308 | #ifndef OPENSSL_NO_AES |
1309 | AES_set_encrypt_key(key16,128,&aes_ks1); | |
1310 | AES_set_encrypt_key(key24,192,&aes_ks2); | |
1311 | AES_set_encrypt_key(key32,256,&aes_ks3); | |
1312 | #endif | |
e18eef3d BM |
1313 | #ifndef OPENSSL_NO_CAMELLIA |
1314 | Camellia_set_key(key16,128,&camellia_ks1); | |
1315 | Camellia_set_key(ckey24,192,&camellia_ks2); | |
1316 | Camellia_set_key(ckey32,256,&camellia_ks3); | |
1317 | #endif | |
cf1b7d96 | 1318 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
1319 | idea_set_encrypt_key(key16,&idea_ks); |
1320 | #endif | |
cf1b7d96 | 1321 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
1322 | RC4_set_key(&rc4_ks,16,key16); |
1323 | #endif | |
cf1b7d96 | 1324 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
1325 | RC2_set_key(&rc2_ks,16,key16,128); |
1326 | #endif | |
cf1b7d96 | 1327 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
1328 | RC5_32_set_key(&rc5_ks,16,key16,12); |
1329 | #endif | |
cf1b7d96 | 1330 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
1331 | BF_set_key(&bf_ks,16,key16); |
1332 | #endif | |
cf1b7d96 | 1333 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
1334 | CAST_set_key(&cast_ks,16,key16); |
1335 | #endif | |
cf1b7d96 | 1336 | #ifndef OPENSSL_NO_RSA |
d02b48c6 | 1337 | memset(rsa_c,0,sizeof(rsa_c)); |
f5d7a031 | 1338 | #endif |
d02b48c6 | 1339 | #ifndef SIGALRM |
cf1b7d96 | 1340 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
1341 | BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); |
1342 | count=10; | |
1343 | do { | |
689c6f25 | 1344 | long it; |
d02b48c6 | 1345 | count*=2; |
b83eddc5 | 1346 | Time_F(START); |
689c6f25 | 1347 | for (it=count; it; it--) |
b83eddc5 | 1348 | DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock, |
3d90a324 | 1349 | &sch,DES_ENCRYPT); |
0e211563 | 1350 | d=Time_F(STOP); |
d02b48c6 | 1351 | } while (d <3); |
646d5695 | 1352 | save_count=count; |
d02b48c6 RE |
1353 | c[D_MD2][0]=count/10; |
1354 | c[D_MDC2][0]=count/10; | |
3009458e | 1355 | c[D_MD4][0]=count; |
d02b48c6 | 1356 | c[D_MD5][0]=count; |
58964a49 | 1357 | c[D_HMAC][0]=count; |
d02b48c6 | 1358 | c[D_SHA1][0]=count; |
58964a49 | 1359 | c[D_RMD160][0]=count; |
d02b48c6 RE |
1360 | c[D_RC4][0]=count*5; |
1361 | c[D_CBC_DES][0]=count; | |
1362 | c[D_EDE3_DES][0]=count/3; | |
1363 | c[D_CBC_IDEA][0]=count; | |
1364 | c[D_CBC_RC2][0]=count; | |
58964a49 | 1365 | c[D_CBC_RC5][0]=count; |
d02b48c6 | 1366 | c[D_CBC_BF][0]=count; |
58964a49 | 1367 | c[D_CBC_CAST][0]=count; |
95de3d20 LJ |
1368 | c[D_CBC_128_AES][0]=count; |
1369 | c[D_CBC_192_AES][0]=count; | |
1370 | c[D_CBC_256_AES][0]=count; | |
e18eef3d BM |
1371 | c[D_CBC_128_CML][0]=count; |
1372 | c[D_CBC_192_CML][0]=count; | |
1373 | c[D_CBC_256_CML][0]=count; | |
46ceb15c AP |
1374 | c[D_SHA256][0]=count; |
1375 | c[D_SHA512][0]=count; | |
d02b48c6 RE |
1376 | |
1377 | for (i=1; i<SIZE_NUM; i++) | |
1378 | { | |
1379 | c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i]; | |
1380 | c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i]; | |
3009458e | 1381 | c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i]; |
d02b48c6 | 1382 | c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i]; |
58964a49 | 1383 | c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i]; |
d02b48c6 | 1384 | c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i]; |
58964a49 | 1385 | c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i]; |
46ceb15c AP |
1386 | c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i]; |
1387 | c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i]; | |
d02b48c6 RE |
1388 | } |
1389 | for (i=1; i<SIZE_NUM; i++) | |
1390 | { | |
1391 | long l0,l1; | |
1392 | ||
1393 | l0=(long)lengths[i-1]; | |
1394 | l1=(long)lengths[i]; | |
1395 | c[D_RC4][i]=c[D_RC4][i-1]*l0/l1; | |
1396 | c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1; | |
1397 | c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1; | |
1398 | c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1; | |
1399 | c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1; | |
58964a49 | 1400 | c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1; |
d02b48c6 | 1401 | c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1; |
58964a49 | 1402 | c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1; |
95de3d20 LJ |
1403 | c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1; |
1404 | c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1; | |
1405 | c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1; | |
e18eef3d BM |
1406 | c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1; |
1407 | c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1; | |
1408 | c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1; | |
d02b48c6 | 1409 | } |
cf1b7d96 | 1410 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1411 | rsa_c[R_RSA_512][0]=count/2000; |
1412 | rsa_c[R_RSA_512][1]=count/400; | |
1413 | for (i=1; i<RSA_NUM; i++) | |
1414 | { | |
1415 | rsa_c[i][0]=rsa_c[i-1][0]/8; | |
1416 | rsa_c[i][1]=rsa_c[i-1][1]/4; | |
1417 | if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) | |
1418 | rsa_doit[i]=0; | |
1419 | else | |
1420 | { | |
dfeab068 | 1421 | if (rsa_c[i][0] == 0) |
d02b48c6 RE |
1422 | { |
1423 | rsa_c[i][0]=1; | |
1424 | rsa_c[i][1]=20; | |
1425 | } | |
1426 | } | |
1427 | } | |
f5d7a031 | 1428 | #endif |
d02b48c6 | 1429 | |
f89aebb1 | 1430 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
1431 | dsa_c[R_DSA_512][0]=count/1000; |
1432 | dsa_c[R_DSA_512][1]=count/1000/2; | |
1433 | for (i=1; i<DSA_NUM; i++) | |
1434 | { | |
1435 | dsa_c[i][0]=dsa_c[i-1][0]/4; | |
1436 | dsa_c[i][1]=dsa_c[i-1][1]/4; | |
1437 | if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) | |
1438 | dsa_doit[i]=0; | |
1439 | else | |
1440 | { | |
1441 | if (dsa_c[i] == 0) | |
1442 | { | |
1443 | dsa_c[i][0]=1; | |
1444 | dsa_c[i][1]=1; | |
1445 | } | |
1446 | } | |
1447 | } | |
f89aebb1 | 1448 | #endif |
d02b48c6 | 1449 | |
e172d60d BM |
1450 | #ifndef OPENSSL_NO_ECDSA |
1451 | ecdsa_c[R_EC_P160][0]=count/1000; | |
1452 | ecdsa_c[R_EC_P160][1]=count/1000/2; | |
689c6f25 | 1453 | for (i=R_EC_P192; i<=R_EC_P521; i++) |
e172d60d BM |
1454 | { |
1455 | ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; | |
1456 | ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; | |
1457 | if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) | |
1458 | ecdsa_doit[i]=0; | |
1459 | else | |
1460 | { | |
1461 | if (ecdsa_c[i] == 0) | |
1462 | { | |
1463 | ecdsa_c[i][0]=1; | |
1464 | ecdsa_c[i][1]=1; | |
1465 | } | |
1466 | } | |
1467 | } | |
1468 | ecdsa_c[R_EC_K163][0]=count/1000; | |
1469 | ecdsa_c[R_EC_K163][1]=count/1000/2; | |
1470 | for (i=R_EC_K233; i<=R_EC_K571; i++) | |
1471 | { | |
1472 | ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; | |
1473 | ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; | |
1474 | if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) | |
1475 | ecdsa_doit[i]=0; | |
1476 | else | |
1477 | { | |
1478 | if (ecdsa_c[i] == 0) | |
1479 | { | |
1480 | ecdsa_c[i][0]=1; | |
1481 | ecdsa_c[i][1]=1; | |
1482 | } | |
1483 | } | |
1484 | } | |
1485 | ecdsa_c[R_EC_B163][0]=count/1000; | |
1486 | ecdsa_c[R_EC_B163][1]=count/1000/2; | |
1487 | for (i=R_EC_B233; i<=R_EC_B571; i++) | |
1488 | { | |
1489 | ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; | |
1490 | ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; | |
1491 | if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) | |
1492 | ecdsa_doit[i]=0; | |
1493 | else | |
1494 | { | |
1495 | if (ecdsa_c[i] == 0) | |
1496 | { | |
1497 | ecdsa_c[i][0]=1; | |
1498 | ecdsa_c[i][1]=1; | |
1499 | } | |
1500 | } | |
1501 | } | |
1502 | #endif | |
1503 | ||
1504 | #ifndef OPENSSL_NO_ECDH | |
1505 | ecdh_c[R_EC_P160][0]=count/1000; | |
1506 | ecdh_c[R_EC_P160][1]=count/1000; | |
689c6f25 | 1507 | for (i=R_EC_P192; i<=R_EC_P521; i++) |
e172d60d BM |
1508 | { |
1509 | ecdh_c[i][0]=ecdh_c[i-1][0]/2; | |
1510 | ecdh_c[i][1]=ecdh_c[i-1][1]/2; | |
1511 | if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) | |
1512 | ecdh_doit[i]=0; | |
1513 | else | |
1514 | { | |
1515 | if (ecdh_c[i] == 0) | |
1516 | { | |
1517 | ecdh_c[i][0]=1; | |
1518 | ecdh_c[i][1]=1; | |
1519 | } | |
1520 | } | |
1521 | } | |
1522 | ecdh_c[R_EC_K163][0]=count/1000; | |
1523 | ecdh_c[R_EC_K163][1]=count/1000; | |
1524 | for (i=R_EC_K233; i<=R_EC_K571; i++) | |
1525 | { | |
1526 | ecdh_c[i][0]=ecdh_c[i-1][0]/2; | |
1527 | ecdh_c[i][1]=ecdh_c[i-1][1]/2; | |
1528 | if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) | |
1529 | ecdh_doit[i]=0; | |
1530 | else | |
1531 | { | |
1532 | if (ecdh_c[i] == 0) | |
1533 | { | |
1534 | ecdh_c[i][0]=1; | |
1535 | ecdh_c[i][1]=1; | |
1536 | } | |
1537 | } | |
1538 | } | |
1539 | ecdh_c[R_EC_B163][0]=count/1000; | |
1540 | ecdh_c[R_EC_B163][1]=count/1000; | |
1541 | for (i=R_EC_B233; i<=R_EC_B571; i++) | |
1542 | { | |
1543 | ecdh_c[i][0]=ecdh_c[i-1][0]/2; | |
1544 | ecdh_c[i][1]=ecdh_c[i-1][1]/2; | |
1545 | if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) | |
1546 | ecdh_doit[i]=0; | |
1547 | else | |
1548 | { | |
1549 | if (ecdh_c[i] == 0) | |
1550 | { | |
1551 | ecdh_c[i][0]=1; | |
1552 | ecdh_c[i][1]=1; | |
1553 | } | |
1554 | } | |
1555 | } | |
1556 | #endif | |
1557 | ||
58964a49 | 1558 | #define COND(d) (count < (d)) |
d02b48c6 RE |
1559 | #define COUNT(d) (d) |
1560 | #else | |
63da21c0 BM |
1561 | /* not worth fixing */ |
1562 | # error "You cannot disable DES on systems without SIGALRM." | |
cf1b7d96 | 1563 | #endif /* OPENSSL_NO_DES */ |
63da21c0 | 1564 | #else |
d02b48c6 RE |
1565 | #define COND(c) (run) |
1566 | #define COUNT(d) (count) | |
1567 | signal(SIGALRM,sig_done); | |
63da21c0 | 1568 | #endif /* SIGALRM */ |
d02b48c6 | 1569 | |
cf1b7d96 | 1570 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
1571 | if (doit[D_MD2]) |
1572 | { | |
1573 | for (j=0; j<SIZE_NUM; j++) | |
1574 | { | |
1575 | print_message(names[D_MD2],c[D_MD2][j],lengths[j]); | |
0e211563 | 1576 | Time_F(START); |
d02b48c6 | 1577 | for (count=0,run=1; COND(c[D_MD2][j]); count++) |
0e211563 BL |
1578 | EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL); |
1579 | d=Time_F(STOP); | |
1580 | print_result(D_MD2,j,count,d); | |
d02b48c6 RE |
1581 | } |
1582 | } | |
1583 | #endif | |
cf1b7d96 | 1584 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
1585 | if (doit[D_MDC2]) |
1586 | { | |
1587 | for (j=0; j<SIZE_NUM; j++) | |
1588 | { | |
1589 | print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]); | |
0e211563 | 1590 | Time_F(START); |
d02b48c6 | 1591 | for (count=0,run=1; COND(c[D_MDC2][j]); count++) |
0e211563 BL |
1592 | EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL); |
1593 | d=Time_F(STOP); | |
1594 | print_result(D_MDC2,j,count,d); | |
d02b48c6 RE |
1595 | } |
1596 | } | |
1597 | #endif | |
1598 | ||
cf1b7d96 | 1599 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
1600 | if (doit[D_MD4]) |
1601 | { | |
1602 | for (j=0; j<SIZE_NUM; j++) | |
1603 | { | |
1604 | print_message(names[D_MD4],c[D_MD4][j],lengths[j]); | |
0e211563 | 1605 | Time_F(START); |
3009458e | 1606 | for (count=0,run=1; COND(c[D_MD4][j]); count++) |
0e211563 BL |
1607 | EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL); |
1608 | d=Time_F(STOP); | |
1609 | print_result(D_MD4,j,count,d); | |
3009458e RL |
1610 | } |
1611 | } | |
1612 | #endif | |
1613 | ||
cf1b7d96 | 1614 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 RE |
1615 | if (doit[D_MD5]) |
1616 | { | |
1617 | for (j=0; j<SIZE_NUM; j++) | |
1618 | { | |
1619 | print_message(names[D_MD5],c[D_MD5][j],lengths[j]); | |
0e211563 | 1620 | Time_F(START); |
d02b48c6 | 1621 | for (count=0,run=1; COND(c[D_MD5][j]); count++) |
0e211563 BL |
1622 | EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL); |
1623 | d=Time_F(STOP); | |
1624 | print_result(D_MD5,j,count,d); | |
d02b48c6 RE |
1625 | } |
1626 | } | |
1627 | #endif | |
1628 | ||
cf1b7d96 | 1629 | #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) |
58964a49 | 1630 | if (doit[D_HMAC]) |
d02b48c6 | 1631 | { |
58964a49 | 1632 | HMAC_CTX hctx; |
dbad1690 BL |
1633 | |
1634 | HMAC_CTX_init(&hctx); | |
ff3fa48f | 1635 | HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...", |
de941e28 | 1636 | 16,EVP_md5(), NULL); |
58964a49 | 1637 | |
d02b48c6 RE |
1638 | for (j=0; j<SIZE_NUM; j++) |
1639 | { | |
58964a49 | 1640 | print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]); |
0e211563 | 1641 | Time_F(START); |
58964a49 RE |
1642 | for (count=0,run=1; COND(c[D_HMAC][j]); count++) |
1643 | { | |
de941e28 DSH |
1644 | HMAC_Init_ex(&hctx,NULL,0,NULL,NULL); |
1645 | HMAC_Update(&hctx,buf,lengths[j]); | |
1646 | HMAC_Final(&hctx,&(hmac[0]),NULL); | |
58964a49 | 1647 | } |
0e211563 BL |
1648 | d=Time_F(STOP); |
1649 | print_result(D_HMAC,j,count,d); | |
d02b48c6 | 1650 | } |
dbad1690 | 1651 | HMAC_CTX_cleanup(&hctx); |
d02b48c6 RE |
1652 | } |
1653 | #endif | |
cf1b7d96 | 1654 | #ifndef OPENSSL_NO_SHA |
d02b48c6 RE |
1655 | if (doit[D_SHA1]) |
1656 | { | |
1657 | for (j=0; j<SIZE_NUM; j++) | |
1658 | { | |
1659 | print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]); | |
0e211563 | 1660 | Time_F(START); |
d02b48c6 | 1661 | for (count=0,run=1; COND(c[D_SHA1][j]); count++) |
0e211563 BL |
1662 | EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL); |
1663 | d=Time_F(STOP); | |
1664 | print_result(D_SHA1,j,count,d); | |
d02b48c6 RE |
1665 | } |
1666 | } | |
46ceb15c | 1667 | |
c88f8f76 | 1668 | #ifndef OPENSSL_NO_SHA256 |
46ceb15c AP |
1669 | if (doit[D_SHA256]) |
1670 | { | |
1671 | for (j=0; j<SIZE_NUM; j++) | |
1672 | { | |
1673 | print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]); | |
1674 | Time_F(START); | |
1675 | for (count=0,run=1; COND(c[D_SHA256][j]); count++) | |
1676 | SHA256(buf,lengths[j],sha256); | |
1677 | d=Time_F(STOP); | |
1678 | print_result(D_SHA256,j,count,d); | |
1679 | } | |
1680 | } | |
c88f8f76 | 1681 | #endif |
46ceb15c | 1682 | |
c88f8f76 | 1683 | #ifndef OPENSSL_NO_SHA512 |
46ceb15c AP |
1684 | if (doit[D_SHA512]) |
1685 | { | |
1686 | for (j=0; j<SIZE_NUM; j++) | |
1687 | { | |
1688 | print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]); | |
1689 | Time_F(START); | |
1690 | for (count=0,run=1; COND(c[D_SHA512][j]); count++) | |
1691 | SHA512(buf,lengths[j],sha512); | |
1692 | d=Time_F(STOP); | |
1693 | print_result(D_SHA512,j,count,d); | |
1694 | } | |
1695 | } | |
d02b48c6 | 1696 | #endif |
c88f8f76 AP |
1697 | |
1698 | #endif | |
cf1b7d96 | 1699 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
1700 | if (doit[D_RMD160]) |
1701 | { | |
1702 | for (j=0; j<SIZE_NUM; j++) | |
1703 | { | |
1704 | print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]); | |
0e211563 | 1705 | Time_F(START); |
58964a49 | 1706 | for (count=0,run=1; COND(c[D_RMD160][j]); count++) |
0e211563 BL |
1707 | EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL); |
1708 | d=Time_F(STOP); | |
1709 | print_result(D_RMD160,j,count,d); | |
58964a49 RE |
1710 | } |
1711 | } | |
1712 | #endif | |
cf1b7d96 | 1713 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
1714 | if (doit[D_RC4]) |
1715 | { | |
1716 | for (j=0; j<SIZE_NUM; j++) | |
1717 | { | |
1718 | print_message(names[D_RC4],c[D_RC4][j],lengths[j]); | |
0e211563 | 1719 | Time_F(START); |
d02b48c6 RE |
1720 | for (count=0,run=1; COND(c[D_RC4][j]); count++) |
1721 | RC4(&rc4_ks,(unsigned int)lengths[j], | |
1722 | buf,buf); | |
0e211563 BL |
1723 | d=Time_F(STOP); |
1724 | print_result(D_RC4,j,count,d); | |
d02b48c6 RE |
1725 | } |
1726 | } | |
1727 | #endif | |
cf1b7d96 | 1728 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
1729 | if (doit[D_CBC_DES]) |
1730 | { | |
1731 | for (j=0; j<SIZE_NUM; j++) | |
1732 | { | |
1733 | print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]); | |
0e211563 | 1734 | Time_F(START); |
d02b48c6 | 1735 | for (count=0,run=1; COND(c[D_CBC_DES][j]); count++) |
c2e4f17c | 1736 | DES_ncbc_encrypt(buf,buf,lengths[j],&sch, |
ba1b8883 | 1737 | &DES_iv,DES_ENCRYPT); |
0e211563 BL |
1738 | d=Time_F(STOP); |
1739 | print_result(D_CBC_DES,j,count,d); | |
d02b48c6 RE |
1740 | } |
1741 | } | |
1742 | ||
1743 | if (doit[D_EDE3_DES]) | |
1744 | { | |
1745 | for (j=0; j<SIZE_NUM; j++) | |
1746 | { | |
1747 | print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]); | |
0e211563 | 1748 | Time_F(START); |
d02b48c6 | 1749 | for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++) |
c2e4f17c | 1750 | DES_ede3_cbc_encrypt(buf,buf,lengths[j], |
dbad1690 | 1751 | &sch,&sch2,&sch3, |
ba1b8883 | 1752 | &DES_iv,DES_ENCRYPT); |
0e211563 BL |
1753 | d=Time_F(STOP); |
1754 | print_result(D_EDE3_DES,j,count,d); | |
d02b48c6 RE |
1755 | } |
1756 | } | |
1757 | #endif | |
ba1b8883 RL |
1758 | #ifndef OPENSSL_NO_AES |
1759 | if (doit[D_CBC_128_AES]) | |
1760 | { | |
1761 | for (j=0; j<SIZE_NUM; j++) | |
1762 | { | |
1763 | print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]); | |
1764 | Time_F(START); | |
1765 | for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++) | |
1766 | AES_cbc_encrypt(buf,buf, | |
1767 | (unsigned long)lengths[j],&aes_ks1, | |
1768 | iv,AES_ENCRYPT); | |
1769 | d=Time_F(STOP); | |
1770 | print_result(D_CBC_128_AES,j,count,d); | |
1771 | } | |
1772 | } | |
1773 | if (doit[D_CBC_192_AES]) | |
1774 | { | |
1775 | for (j=0; j<SIZE_NUM; j++) | |
1776 | { | |
1777 | print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]); | |
1778 | Time_F(START); | |
1779 | for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++) | |
1780 | AES_cbc_encrypt(buf,buf, | |
1781 | (unsigned long)lengths[j],&aes_ks2, | |
1782 | iv,AES_ENCRYPT); | |
1783 | d=Time_F(STOP); | |
1784 | print_result(D_CBC_192_AES,j,count,d); | |
1785 | } | |
1786 | } | |
1787 | if (doit[D_CBC_256_AES]) | |
1788 | { | |
1789 | for (j=0; j<SIZE_NUM; j++) | |
1790 | { | |
1791 | print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]); | |
1792 | Time_F(START); | |
1793 | for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++) | |
1794 | AES_cbc_encrypt(buf,buf, | |
1795 | (unsigned long)lengths[j],&aes_ks3, | |
1796 | iv,AES_ENCRYPT); | |
1797 | d=Time_F(STOP); | |
1798 | print_result(D_CBC_256_AES,j,count,d); | |
1799 | } | |
1800 | } | |
1801 | ||
e18eef3d BM |
1802 | #endif |
1803 | #ifndef OPENSSL_NO_CAMELLIA | |
1804 | if (doit[D_CBC_128_CML]) | |
1805 | { | |
1806 | for (j=0; j<SIZE_NUM; j++) | |
1807 | { | |
1808 | print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]); | |
1809 | Time_F(START); | |
1810 | for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++) | |
1811 | Camellia_cbc_encrypt(buf,buf, | |
1812 | (unsigned long)lengths[j],&camellia_ks1, | |
1813 | iv,CAMELLIA_ENCRYPT); | |
1814 | d=Time_F(STOP); | |
1815 | print_result(D_CBC_128_CML,j,count,d); | |
1816 | } | |
1817 | } | |
1818 | if (doit[D_CBC_192_CML]) | |
1819 | { | |
1820 | for (j=0; j<SIZE_NUM; j++) | |
1821 | { | |
1822 | print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]); | |
1823 | Time_F(START); | |
1824 | for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++) | |
1825 | Camellia_cbc_encrypt(buf,buf, | |
1826 | (unsigned long)lengths[j],&camellia_ks2, | |
1827 | iv,CAMELLIA_ENCRYPT); | |
1828 | d=Time_F(STOP); | |
1829 | print_result(D_CBC_192_CML,j,count,d); | |
1830 | } | |
1831 | } | |
1832 | if (doit[D_CBC_256_CML]) | |
1833 | { | |
1834 | for (j=0; j<SIZE_NUM; j++) | |
1835 | { | |
1836 | print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]); | |
1837 | Time_F(START); | |
1838 | for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++) | |
1839 | Camellia_cbc_encrypt(buf,buf, | |
1840 | (unsigned long)lengths[j],&camellia_ks3, | |
1841 | iv,CAMELLIA_ENCRYPT); | |
1842 | d=Time_F(STOP); | |
1843 | print_result(D_CBC_256_CML,j,count,d); | |
1844 | } | |
1845 | } | |
1846 | ||
ba1b8883 | 1847 | #endif |
cf1b7d96 | 1848 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
1849 | if (doit[D_CBC_IDEA]) |
1850 | { | |
1851 | for (j=0; j<SIZE_NUM; j++) | |
1852 | { | |
1853 | print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]); | |
0e211563 | 1854 | Time_F(START); |
d02b48c6 RE |
1855 | for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++) |
1856 | idea_cbc_encrypt(buf,buf, | |
1857 | (unsigned long)lengths[j],&idea_ks, | |
12ba413c | 1858 | iv,IDEA_ENCRYPT); |
0e211563 BL |
1859 | d=Time_F(STOP); |
1860 | print_result(D_CBC_IDEA,j,count,d); | |
d02b48c6 RE |
1861 | } |
1862 | } | |
1863 | #endif | |
cf1b7d96 | 1864 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
1865 | if (doit[D_CBC_RC2]) |
1866 | { | |
1867 | for (j=0; j<SIZE_NUM; j++) | |
1868 | { | |
1869 | print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]); | |
0e211563 | 1870 | Time_F(START); |
d02b48c6 RE |
1871 | for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++) |
1872 | RC2_cbc_encrypt(buf,buf, | |
1873 | (unsigned long)lengths[j],&rc2_ks, | |
12ba413c | 1874 | iv,RC2_ENCRYPT); |
0e211563 BL |
1875 | d=Time_F(STOP); |
1876 | print_result(D_CBC_RC2,j,count,d); | |
d02b48c6 RE |
1877 | } |
1878 | } | |
1879 | #endif | |
cf1b7d96 | 1880 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
1881 | if (doit[D_CBC_RC5]) |
1882 | { | |
1883 | for (j=0; j<SIZE_NUM; j++) | |
1884 | { | |
1885 | print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]); | |
0e211563 | 1886 | Time_F(START); |
58964a49 RE |
1887 | for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++) |
1888 | RC5_32_cbc_encrypt(buf,buf, | |
1889 | (unsigned long)lengths[j],&rc5_ks, | |
12ba413c | 1890 | iv,RC5_ENCRYPT); |
0e211563 BL |
1891 | d=Time_F(STOP); |
1892 | print_result(D_CBC_RC5,j,count,d); | |
58964a49 RE |
1893 | } |
1894 | } | |
1895 | #endif | |
cf1b7d96 | 1896 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
1897 | if (doit[D_CBC_BF]) |
1898 | { | |
1899 | for (j=0; j<SIZE_NUM; j++) | |
1900 | { | |
1901 | print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]); | |
0e211563 | 1902 | Time_F(START); |
d02b48c6 RE |
1903 | for (count=0,run=1; COND(c[D_CBC_BF][j]); count++) |
1904 | BF_cbc_encrypt(buf,buf, | |
1905 | (unsigned long)lengths[j],&bf_ks, | |
12ba413c | 1906 | iv,BF_ENCRYPT); |
0e211563 BL |
1907 | d=Time_F(STOP); |
1908 | print_result(D_CBC_BF,j,count,d); | |
d02b48c6 RE |
1909 | } |
1910 | } | |
1911 | #endif | |
cf1b7d96 | 1912 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
1913 | if (doit[D_CBC_CAST]) |
1914 | { | |
1915 | for (j=0; j<SIZE_NUM; j++) | |
1916 | { | |
1917 | print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]); | |
0e211563 | 1918 | Time_F(START); |
58964a49 RE |
1919 | for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++) |
1920 | CAST_cbc_encrypt(buf,buf, | |
1921 | (unsigned long)lengths[j],&cast_ks, | |
12ba413c | 1922 | iv,CAST_ENCRYPT); |
0e211563 BL |
1923 | d=Time_F(STOP); |
1924 | print_result(D_CBC_CAST,j,count,d); | |
58964a49 RE |
1925 | } |
1926 | } | |
1927 | #endif | |
d02b48c6 | 1928 | |
646d5695 BL |
1929 | if (doit[D_EVP]) |
1930 | { | |
1931 | for (j=0; j<SIZE_NUM; j++) | |
1932 | { | |
83c40e7f RL |
1933 | if (evp_cipher) |
1934 | { | |
1935 | EVP_CIPHER_CTX ctx; | |
1936 | int outl; | |
1937 | ||
1938 | names[D_EVP]=OBJ_nid2ln(evp_cipher->nid); | |
ba1b8883 RL |
1939 | /* -O3 -fschedule-insns messes up an |
1940 | * optimization here! names[D_EVP] | |
1941 | * somehow becomes NULL */ | |
83c40e7f RL |
1942 | print_message(names[D_EVP],save_count, |
1943 | lengths[j]); | |
1944 | ||
1945 | EVP_CIPHER_CTX_init(&ctx); | |
1946 | if(decrypt) | |
1947 | EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); | |
1948 | else | |
1949 | EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); | |
563cd0f2 | 1950 | EVP_CIPHER_CTX_set_padding(&ctx, 0); |
83c40e7f RL |
1951 | |
1952 | Time_F(START); | |
1953 | if(decrypt) | |
1954 | for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) | |
1955 | EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]); | |
1956 | else | |
1957 | for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) | |
1958 | EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]); | |
1959 | if(decrypt) | |
1960 | EVP_DecryptFinal_ex(&ctx,buf,&outl); | |
1961 | else | |
1962 | EVP_EncryptFinal_ex(&ctx,buf,&outl); | |
1963 | d=Time_F(STOP); | |
876e96fd | 1964 | EVP_CIPHER_CTX_cleanup(&ctx); |
83c40e7f RL |
1965 | } |
1966 | if (evp_md) | |
1967 | { | |
1968 | names[D_EVP]=OBJ_nid2ln(evp_md->type); | |
1969 | print_message(names[D_EVP],save_count, | |
1970 | lengths[j]); | |
1971 | ||
1972 | Time_F(START); | |
3f37e73b | 1973 | for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) |
83c40e7f RL |
1974 | EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL); |
1975 | ||
1976 | d=Time_F(STOP); | |
1977 | } | |
0e211563 | 1978 | print_result(D_EVP,j,count,d); |
646d5695 BL |
1979 | } |
1980 | } | |
1981 | ||
373b575f | 1982 | RAND_pseudo_bytes(buf,36); |
cf1b7d96 | 1983 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1984 | for (j=0; j<RSA_NUM; j++) |
1985 | { | |
c91e1259 | 1986 | int ret; |
d02b48c6 | 1987 | if (!rsa_doit[j]) continue; |
c91e1259 | 1988 | ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]); |
03ea28c9 RL |
1989 | if (ret == 0) |
1990 | { | |
1991 | BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n"); | |
1992 | ERR_print_errors(bio_err); | |
1993 | rsa_count=1; | |
1994 | } | |
1995 | else | |
d02b48c6 | 1996 | { |
03ea28c9 RL |
1997 | pkey_print_message("private","rsa", |
1998 | rsa_c[j][0],rsa_bits[j], | |
1999 | RSA_SECONDS); | |
2000 | /* RSA_blinding_on(rsa_key[j],NULL); */ | |
0e211563 | 2001 | Time_F(START); |
03ea28c9 | 2002 | for (count=0,run=1; COND(rsa_c[j][0]); count++) |
d02b48c6 | 2003 | { |
03ea28c9 RL |
2004 | ret=RSA_sign(NID_md5_sha1, buf,36, buf2, |
2005 | &rsa_num, rsa_key[j]); | |
2006 | if (ret == 0) | |
2007 | { | |
2008 | BIO_printf(bio_err, | |
2009 | "RSA sign failure\n"); | |
2010 | ERR_print_errors(bio_err); | |
2011 | count=1; | |
2012 | break; | |
2013 | } | |
d02b48c6 | 2014 | } |
0e211563 BL |
2015 | d=Time_F(STOP); |
2016 | BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n" | |
2017 | : "%ld %d bit private RSA's in %.2fs\n", | |
2018 | count,rsa_bits[j],d); | |
03ea28c9 RL |
2019 | rsa_results[j][0]=d/(double)count; |
2020 | rsa_count=count; | |
d02b48c6 | 2021 | } |
d02b48c6 | 2022 | |
58964a49 | 2023 | #if 1 |
c91e1259 | 2024 | ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]); |
03ea28c9 | 2025 | if (ret <= 0) |
d02b48c6 | 2026 | { |
03ea28c9 RL |
2027 | BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n"); |
2028 | ERR_print_errors(bio_err); | |
51740b12 | 2029 | rsa_doit[j] = 0; |
03ea28c9 RL |
2030 | } |
2031 | else | |
2032 | { | |
2033 | pkey_print_message("public","rsa", | |
2034 | rsa_c[j][1],rsa_bits[j], | |
2035 | RSA_SECONDS); | |
0e211563 | 2036 | Time_F(START); |
03ea28c9 | 2037 | for (count=0,run=1; COND(rsa_c[j][1]); count++) |
d02b48c6 | 2038 | { |
03ea28c9 RL |
2039 | ret=RSA_verify(NID_md5_sha1, buf,36, buf2, |
2040 | rsa_num, rsa_key[j]); | |
2041 | if (ret == 0) | |
2042 | { | |
2043 | BIO_printf(bio_err, | |
2044 | "RSA verify failure\n"); | |
2045 | ERR_print_errors(bio_err); | |
2046 | count=1; | |
2047 | break; | |
2048 | } | |
d02b48c6 | 2049 | } |
0e211563 BL |
2050 | d=Time_F(STOP); |
2051 | BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n" | |
2052 | : "%ld %d bit public RSA's in %.2fs\n", | |
2053 | count,rsa_bits[j],d); | |
03ea28c9 | 2054 | rsa_results[j][1]=d/(double)count; |
d02b48c6 | 2055 | } |
58964a49 | 2056 | #endif |
d02b48c6 RE |
2057 | |
2058 | if (rsa_count <= 1) | |
2059 | { | |
2060 | /* if longer than 10s, don't do any more */ | |
2061 | for (j++; j<RSA_NUM; j++) | |
2062 | rsa_doit[j]=0; | |
2063 | } | |
2064 | } | |
2065 | #endif | |
2066 | ||
373b575f | 2067 | RAND_pseudo_bytes(buf,20); |
cf1b7d96 | 2068 | #ifndef OPENSSL_NO_DSA |
99a97051 UM |
2069 | if (RAND_status() != 1) |
2070 | { | |
2071 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
2072 | rnd_fake = 1; | |
2073 | } | |
d02b48c6 RE |
2074 | for (j=0; j<DSA_NUM; j++) |
2075 | { | |
58964a49 | 2076 | unsigned int kk; |
03ea28c9 | 2077 | int ret; |
58964a49 | 2078 | |
d02b48c6 | 2079 | if (!dsa_doit[j]) continue; |
af436bc1 | 2080 | /* DSA_generate_key(dsa_key[j]); */ |
d02b48c6 | 2081 | /* DSA_sign_setup(dsa_key[j],NULL); */ |
03ea28c9 | 2082 | ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, |
dfeab068 | 2083 | &kk,dsa_key[j]); |
03ea28c9 RL |
2084 | if (ret == 0) |
2085 | { | |
2086 | BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n"); | |
2087 | ERR_print_errors(bio_err); | |
2088 | rsa_count=1; | |
2089 | } | |
2090 | else | |
d02b48c6 | 2091 | { |
03ea28c9 RL |
2092 | pkey_print_message("sign","dsa", |
2093 | dsa_c[j][0],dsa_bits[j], | |
2094 | DSA_SECONDS); | |
0e211563 | 2095 | Time_F(START); |
03ea28c9 | 2096 | for (count=0,run=1; COND(dsa_c[j][0]); count++) |
d02b48c6 | 2097 | { |
03ea28c9 RL |
2098 | ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, |
2099 | &kk,dsa_key[j]); | |
2100 | if (ret == 0) | |
2101 | { | |
2102 | BIO_printf(bio_err, | |
2103 | "DSA sign failure\n"); | |
2104 | ERR_print_errors(bio_err); | |
2105 | count=1; | |
2106 | break; | |
2107 | } | |
d02b48c6 | 2108 | } |
0e211563 BL |
2109 | d=Time_F(STOP); |
2110 | BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n" | |
2111 | : "%ld %d bit DSA signs in %.2fs\n", | |
2112 | count,dsa_bits[j],d); | |
03ea28c9 RL |
2113 | dsa_results[j][0]=d/(double)count; |
2114 | rsa_count=count; | |
d02b48c6 | 2115 | } |
d02b48c6 | 2116 | |
03ea28c9 | 2117 | ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, |
dfeab068 | 2118 | kk,dsa_key[j]); |
03ea28c9 RL |
2119 | if (ret <= 0) |
2120 | { | |
2121 | BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n"); | |
2122 | ERR_print_errors(bio_err); | |
2123 | dsa_doit[j] = 0; | |
2124 | } | |
2125 | else | |
d02b48c6 | 2126 | { |
03ea28c9 RL |
2127 | pkey_print_message("verify","dsa", |
2128 | dsa_c[j][1],dsa_bits[j], | |
2129 | DSA_SECONDS); | |
0e211563 | 2130 | Time_F(START); |
03ea28c9 | 2131 | for (count=0,run=1; COND(dsa_c[j][1]); count++) |
d02b48c6 | 2132 | { |
03ea28c9 RL |
2133 | ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, |
2134 | kk,dsa_key[j]); | |
2135 | if (ret <= 0) | |
2136 | { | |
2137 | BIO_printf(bio_err, | |
2138 | "DSA verify failure\n"); | |
2139 | ERR_print_errors(bio_err); | |
2140 | count=1; | |
2141 | break; | |
2142 | } | |
d02b48c6 | 2143 | } |
0e211563 BL |
2144 | d=Time_F(STOP); |
2145 | BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n" | |
2146 | : "%ld %d bit DSA verify in %.2fs\n", | |
2147 | count,dsa_bits[j],d); | |
03ea28c9 | 2148 | dsa_results[j][1]=d/(double)count; |
d02b48c6 | 2149 | } |
d02b48c6 RE |
2150 | |
2151 | if (rsa_count <= 1) | |
2152 | { | |
2153 | /* if longer than 10s, don't do any more */ | |
2154 | for (j++; j<DSA_NUM; j++) | |
2155 | dsa_doit[j]=0; | |
2156 | } | |
2157 | } | |
99a97051 | 2158 | if (rnd_fake) RAND_cleanup(); |
d02b48c6 | 2159 | #endif |
e172d60d BM |
2160 | |
2161 | #ifndef OPENSSL_NO_ECDSA | |
2162 | if (RAND_status() != 1) | |
2163 | { | |
2164 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
2165 | rnd_fake = 1; | |
2166 | } | |
2167 | for (j=0; j<EC_NUM; j++) | |
2168 | { | |
2169 | int ret; | |
2170 | ||
2171 | if (!ecdsa_doit[j]) continue; /* Ignore Curve */ | |
9dd84053 | 2172 | ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]); |
e172d60d BM |
2173 | if (ecdsa[j] == NULL) |
2174 | { | |
2175 | BIO_printf(bio_err,"ECDSA failure.\n"); | |
2176 | ERR_print_errors(bio_err); | |
2177 | rsa_count=1; | |
2178 | } | |
2179 | else | |
2180 | { | |
9dd84053 NL |
2181 | #if 1 |
2182 | EC_KEY_precompute_mult(ecdsa[j], NULL); | |
2183 | #endif | |
2184 | /* Perform ECDSA signature test */ | |
2185 | EC_KEY_generate_key(ecdsa[j]); | |
2186 | ret = ECDSA_sign(0, buf, 20, ecdsasig, | |
2187 | &ecdsasiglen, ecdsa[j]); | |
2188 | if (ret == 0) | |
e172d60d | 2189 | { |
9dd84053 | 2190 | BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n"); |
e172d60d BM |
2191 | ERR_print_errors(bio_err); |
2192 | rsa_count=1; | |
2193 | } | |
2194 | else | |
2195 | { | |
9dd84053 NL |
2196 | pkey_print_message("sign","ecdsa", |
2197 | ecdsa_c[j][0], | |
2198 | test_curves_bits[j], | |
2199 | ECDSA_SECONDS); | |
2200 | ||
2201 | Time_F(START); | |
2202 | for (count=0,run=1; COND(ecdsa_c[j][0]); | |
2203 | count++) | |
e172d60d | 2204 | { |
9dd84053 NL |
2205 | ret=ECDSA_sign(0, buf, 20, |
2206 | ecdsasig, &ecdsasiglen, | |
2207 | ecdsa[j]); | |
2208 | if (ret == 0) | |
e172d60d | 2209 | { |
9dd84053 NL |
2210 | BIO_printf(bio_err, "ECDSA sign failure\n"); |
2211 | ERR_print_errors(bio_err); | |
2212 | count=1; | |
2213 | break; | |
e172d60d | 2214 | } |
e172d60d | 2215 | } |
9dd84053 | 2216 | d=Time_F(STOP); |
e172d60d | 2217 | |
9dd84053 NL |
2218 | BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" : |
2219 | "%ld %d bit ECDSA signs in %.2fs \n", | |
2220 | count, test_curves_bits[j], d); | |
2221 | ecdsa_results[j][0]=d/(double)count; | |
2222 | rsa_count=count; | |
2223 | } | |
2224 | ||
2225 | /* Perform ECDSA verification test */ | |
2226 | ret=ECDSA_verify(0, buf, 20, ecdsasig, | |
2227 | ecdsasiglen, ecdsa[j]); | |
2228 | if (ret != 1) | |
2229 | { | |
2230 | BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n"); | |
2231 | ERR_print_errors(bio_err); | |
2232 | ecdsa_doit[j] = 0; | |
2233 | } | |
2234 | else | |
2235 | { | |
2236 | pkey_print_message("verify","ecdsa", | |
2237 | ecdsa_c[j][1], | |
2238 | test_curves_bits[j], | |
2239 | ECDSA_SECONDS); | |
2240 | Time_F(START); | |
2241 | for (count=0,run=1; COND(ecdsa_c[j][1]); count++) | |
e172d60d | 2242 | { |
9dd84053 NL |
2243 | ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]); |
2244 | if (ret != 1) | |
e172d60d | 2245 | { |
9dd84053 NL |
2246 | BIO_printf(bio_err, "ECDSA verify failure\n"); |
2247 | ERR_print_errors(bio_err); | |
2248 | count=1; | |
2249 | break; | |
e172d60d | 2250 | } |
e172d60d | 2251 | } |
9dd84053 NL |
2252 | d=Time_F(STOP); |
2253 | BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n" | |
2254 | : "%ld %d bit ECDSA verify in %.2fs\n", | |
2255 | count, test_curves_bits[j], d); | |
2256 | ecdsa_results[j][1]=d/(double)count; | |
2257 | } | |
e172d60d | 2258 | |
9dd84053 NL |
2259 | if (rsa_count <= 1) |
2260 | { | |
2261 | /* if longer than 10s, don't do any more */ | |
2262 | for (j++; j<EC_NUM; j++) | |
2263 | ecdsa_doit[j]=0; | |
e172d60d BM |
2264 | } |
2265 | } | |
2266 | } | |
2267 | if (rnd_fake) RAND_cleanup(); | |
2268 | #endif | |
2269 | ||
2270 | #ifndef OPENSSL_NO_ECDH | |
2271 | if (RAND_status() != 1) | |
2272 | { | |
2273 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
2274 | rnd_fake = 1; | |
2275 | } | |
2276 | for (j=0; j<EC_NUM; j++) | |
2277 | { | |
2278 | if (!ecdh_doit[j]) continue; | |
9dd84053 NL |
2279 | ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]); |
2280 | ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]); | |
e172d60d BM |
2281 | if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) |
2282 | { | |
2283 | BIO_printf(bio_err,"ECDH failure.\n"); | |
2284 | ERR_print_errors(bio_err); | |
2285 | rsa_count=1; | |
2286 | } | |
2287 | else | |
2288 | { | |
9dd84053 NL |
2289 | /* generate two ECDH key pairs */ |
2290 | if (!EC_KEY_generate_key(ecdh_a[j]) || | |
2291 | !EC_KEY_generate_key(ecdh_b[j])) | |
e172d60d | 2292 | { |
9dd84053 | 2293 | BIO_printf(bio_err,"ECDH key generation failure.\n"); |
e172d60d | 2294 | ERR_print_errors(bio_err); |
9dd84053 | 2295 | rsa_count=1; |
e172d60d BM |
2296 | } |
2297 | else | |
2298 | { | |
9dd84053 NL |
2299 | /* If field size is not more than 24 octets, then use SHA-1 hash of result; |
2300 | * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt). | |
2301 | */ | |
2302 | int field_size, outlen; | |
2303 | void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen); | |
2304 | field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j])); | |
2305 | if (field_size <= 24 * 8) | |
e172d60d | 2306 | { |
9dd84053 NL |
2307 | outlen = KDF1_SHA1_len; |
2308 | kdf = KDF1_SHA1; | |
e172d60d BM |
2309 | } |
2310 | else | |
2311 | { | |
9dd84053 NL |
2312 | outlen = (field_size+7)/8; |
2313 | kdf = NULL; | |
2314 | } | |
2315 | secret_size_a = ECDH_compute_key(secret_a, outlen, | |
2316 | EC_KEY_get0_public_key(ecdh_b[j]), | |
2317 | ecdh_a[j], kdf); | |
2318 | secret_size_b = ECDH_compute_key(secret_b, outlen, | |
2319 | EC_KEY_get0_public_key(ecdh_a[j]), | |
2320 | ecdh_b[j], kdf); | |
2321 | if (secret_size_a != secret_size_b) | |
2322 | ecdh_checks = 0; | |
2323 | else | |
2324 | ecdh_checks = 1; | |
e172d60d | 2325 | |
9dd84053 NL |
2326 | for (secret_idx = 0; |
2327 | (secret_idx < secret_size_a) | |
2328 | && (ecdh_checks == 1); | |
2329 | secret_idx++) | |
2330 | { | |
2331 | if (secret_a[secret_idx] != secret_b[secret_idx]) | |
2332 | ecdh_checks = 0; | |
2333 | } | |
e172d60d | 2334 | |
9dd84053 NL |
2335 | if (ecdh_checks == 0) |
2336 | { | |
2337 | BIO_printf(bio_err,"ECDH computations don't match.\n"); | |
2338 | ERR_print_errors(bio_err); | |
2339 | rsa_count=1; | |
e172d60d | 2340 | } |
9dd84053 NL |
2341 | |
2342 | pkey_print_message("","ecdh", | |
2343 | ecdh_c[j][0], | |
2344 | test_curves_bits[j], | |
2345 | ECDH_SECONDS); | |
2346 | Time_F(START); | |
2347 | for (count=0,run=1; COND(ecdh_c[j][0]); count++) | |
2348 | { | |
2349 | ECDH_compute_key(secret_a, outlen, | |
2350 | EC_KEY_get0_public_key(ecdh_b[j]), | |
2351 | ecdh_a[j], kdf); | |
2352 | } | |
2353 | d=Time_F(STOP); | |
2354 | BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n", | |
2355 | count, test_curves_bits[j], d); | |
2356 | ecdh_results[j][0]=d/(double)count; | |
2357 | rsa_count=count; | |
e172d60d BM |
2358 | } |
2359 | } | |
2360 | ||
9dd84053 | 2361 | |
e172d60d BM |
2362 | if (rsa_count <= 1) |
2363 | { | |
2364 | /* if longer than 10s, don't do any more */ | |
2365 | for (j++; j<EC_NUM; j++) | |
2366 | ecdh_doit[j]=0; | |
2367 | } | |
2368 | } | |
2369 | if (rnd_fake) RAND_cleanup(); | |
2370 | #endif | |
b83eddc5 | 2371 | #ifdef HAVE_FORK |
0e211563 | 2372 | show_res: |
b83eddc5 | 2373 | #endif |
0e211563 BL |
2374 | if(!mr) |
2375 | { | |
2376 | fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION)); | |
d02b48c6 | 2377 | fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON)); |
0e211563 BL |
2378 | printf("options:"); |
2379 | printf("%s ",BN_options()); | |
cf1b7d96 | 2380 | #ifndef OPENSSL_NO_MD2 |
0e211563 | 2381 | printf("%s ",MD2_options()); |
d02b48c6 | 2382 | #endif |
cf1b7d96 | 2383 | #ifndef OPENSSL_NO_RC4 |
0e211563 | 2384 | printf("%s ",RC4_options()); |
d02b48c6 | 2385 | #endif |
cf1b7d96 | 2386 | #ifndef OPENSSL_NO_DES |
125cc35b | 2387 | printf("%s ",DES_options()); |
d02b48c6 | 2388 | #endif |
ba1b8883 RL |
2389 | #ifndef OPENSSL_NO_AES |
2390 | printf("%s ",AES_options()); | |
2391 | #endif | |
cf1b7d96 | 2392 | #ifndef OPENSSL_NO_IDEA |
0e211563 | 2393 | printf("%s ",idea_options()); |
d02b48c6 | 2394 | #endif |
cf1b7d96 | 2395 | #ifndef OPENSSL_NO_BF |
0e211563 | 2396 | printf("%s ",BF_options()); |
d02b48c6 | 2397 | #endif |
0e211563 BL |
2398 | fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS)); |
2399 | printf("available timing options: "); | |
7876e448 | 2400 | #ifdef TIMES |
0e211563 | 2401 | printf("TIMES "); |
7876e448 RL |
2402 | #endif |
2403 | #ifdef TIMEB | |
0e211563 | 2404 | printf("TIMEB "); |
7876e448 RL |
2405 | #endif |
2406 | #ifdef USE_TOD | |
0e211563 | 2407 | printf("USE_TOD "); |
7876e448 RL |
2408 | #endif |
2409 | #ifdef HZ | |
2410 | #define as_string(s) (#s) | |
0991f070 GT |
2411 | { |
2412 | double dbl = HZ; | |
2413 | printf("HZ=%g", dbl); | |
2414 | } | |
a4a8f7b3 | 2415 | # ifdef _SC_CLK_TCK |
0e211563 | 2416 | printf(" [sysconf value]"); |
a4a8f7b3 | 2417 | # endif |
7876e448 | 2418 | #endif |
0e211563 BL |
2419 | printf("\n"); |
2420 | printf("timing function used: %s%s%s%s%s%s%s\n", | |
2421 | (ftime_used ? "ftime" : ""), | |
2422 | (ftime_used + times_used > 1 ? "," : ""), | |
2423 | (times_used ? "times" : ""), | |
2424 | (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""), | |
2425 | (gettimeofday_used ? "gettimeofday" : ""), | |
2426 | (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""), | |
2427 | (getrusage_used ? "getrusage" : "")); | |
2428 | } | |
d02b48c6 RE |
2429 | |
2430 | if (pr_header) | |
2431 | { | |
0e211563 BL |
2432 | if(mr) |
2433 | fprintf(stdout,"+H"); | |
2434 | else | |
2435 | { | |
2436 | fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); | |
2437 | fprintf(stdout,"type "); | |
2438 | } | |
d02b48c6 | 2439 | for (j=0; j<SIZE_NUM; j++) |
0e211563 | 2440 | fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]); |
d02b48c6 RE |
2441 | fprintf(stdout,"\n"); |
2442 | } | |
2443 | ||
2444 | for (k=0; k<ALGOR_NUM; k++) | |
2445 | { | |
2446 | if (!doit[k]) continue; | |
0e211563 BL |
2447 | if(mr) |
2448 | fprintf(stdout,"+F:%d:%s",k,names[k]); | |
2449 | else | |
2450 | fprintf(stdout,"%-13s",names[k]); | |
d02b48c6 RE |
2451 | for (j=0; j<SIZE_NUM; j++) |
2452 | { | |
0e211563 | 2453 | if (results[k][j] > 10000 && !mr) |
d02b48c6 RE |
2454 | fprintf(stdout," %11.2fk",results[k][j]/1e3); |
2455 | else | |
0e211563 | 2456 | fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]); |
d02b48c6 RE |
2457 | } |
2458 | fprintf(stdout,"\n"); | |
2459 | } | |
cf1b7d96 | 2460 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
2461 | j=1; |
2462 | for (k=0; k<RSA_NUM; k++) | |
2463 | { | |
2464 | if (!rsa_doit[k]) continue; | |
0e211563 | 2465 | if (j && !mr) |
58964a49 RE |
2466 | { |
2467 | printf("%18ssign verify sign/s verify/s\n"," "); | |
2468 | j=0; | |
2469 | } | |
0e211563 BL |
2470 | if(mr) |
2471 | fprintf(stdout,"+F2:%u:%u:%f:%f\n", | |
2472 | k,rsa_bits[k],rsa_results[k][0], | |
2473 | rsa_results[k][1]); | |
2474 | else | |
46a64376 | 2475 | fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
0e211563 BL |
2476 | rsa_bits[k],rsa_results[k][0],rsa_results[k][1], |
2477 | 1.0/rsa_results[k][0],1.0/rsa_results[k][1]); | |
d02b48c6 RE |
2478 | } |
2479 | #endif | |
cf1b7d96 | 2480 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
2481 | j=1; |
2482 | for (k=0; k<DSA_NUM; k++) | |
2483 | { | |
2484 | if (!dsa_doit[k]) continue; | |
0e211563 BL |
2485 | if (j && !mr) |
2486 | { | |
58964a49 RE |
2487 | printf("%18ssign verify sign/s verify/s\n"," "); |
2488 | j=0; | |
2489 | } | |
0e211563 BL |
2490 | if(mr) |
2491 | fprintf(stdout,"+F3:%u:%u:%f:%f\n", | |
2492 | k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]); | |
2493 | else | |
46a64376 | 2494 | fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", |
0e211563 BL |
2495 | dsa_bits[k],dsa_results[k][0],dsa_results[k][1], |
2496 | 1.0/dsa_results[k][0],1.0/dsa_results[k][1]); | |
d02b48c6 RE |
2497 | } |
2498 | #endif | |
e172d60d BM |
2499 | #ifndef OPENSSL_NO_ECDSA |
2500 | j=1; | |
2501 | for (k=0; k<EC_NUM; k++) | |
2502 | { | |
2503 | if (!ecdsa_doit[k]) continue; | |
2504 | if (j && !mr) | |
2505 | { | |
2506 | printf("%30ssign verify sign/s verify/s\n"," "); | |
2507 | j=0; | |
2508 | } | |
2509 | ||
2510 | if (mr) | |
2511 | fprintf(stdout,"+F4:%u:%u:%f:%f\n", | |
2512 | k, test_curves_bits[k], | |
2513 | ecdsa_results[k][0],ecdsa_results[k][1]); | |
2514 | else | |
2515 | fprintf(stdout, | |
2516 | "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", | |
2517 | test_curves_bits[k], | |
2518 | test_curves_names[k], | |
2519 | ecdsa_results[k][0],ecdsa_results[k][1], | |
2520 | 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]); | |
2521 | } | |
2522 | #endif | |
2523 | ||
2524 | ||
2525 | #ifndef OPENSSL_NO_ECDH | |
2526 | j=1; | |
2527 | for (k=0; k<EC_NUM; k++) | |
2528 | { | |
2529 | if (!ecdh_doit[k]) continue; | |
2530 | if (j && !mr) | |
2531 | { | |
2532 | printf("%30sop op/s\n"," "); | |
2533 | j=0; | |
2534 | } | |
2535 | if (mr) | |
2536 | fprintf(stdout,"+F5:%u:%u:%f:%f\n", | |
2537 | k, test_curves_bits[k], | |
2538 | ecdh_results[k][0], 1.0/ecdh_results[k][0]); | |
2539 | ||
2540 | else | |
2541 | fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n", | |
2542 | test_curves_bits[k], | |
2543 | test_curves_names[k], | |
2544 | ecdh_results[k][0], 1.0/ecdh_results[k][0]); | |
2545 | } | |
2546 | #endif | |
2547 | ||
18c77bf2 | 2548 | mret=0; |
e172d60d | 2549 | |
d02b48c6 | 2550 | end: |
5270e702 | 2551 | ERR_print_errors(bio_err); |
26a3a48d RL |
2552 | if (buf != NULL) OPENSSL_free(buf); |
2553 | if (buf2 != NULL) OPENSSL_free(buf2); | |
cf1b7d96 | 2554 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
2555 | for (i=0; i<RSA_NUM; i++) |
2556 | if (rsa_key[i] != NULL) | |
2557 | RSA_free(rsa_key[i]); | |
2558 | #endif | |
cf1b7d96 | 2559 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
2560 | for (i=0; i<DSA_NUM; i++) |
2561 | if (dsa_key[i] != NULL) | |
2562 | DSA_free(dsa_key[i]); | |
2563 | #endif | |
e172d60d BM |
2564 | |
2565 | #ifndef OPENSSL_NO_ECDSA | |
2566 | for (i=0; i<EC_NUM; i++) | |
2567 | if (ecdsa[i] != NULL) | |
2568 | EC_KEY_free(ecdsa[i]); | |
2569 | #endif | |
2570 | #ifndef OPENSSL_NO_ECDH | |
2571 | for (i=0; i<EC_NUM; i++) | |
2572 | { | |
2573 | if (ecdh_a[i] != NULL) | |
2574 | EC_KEY_free(ecdh_a[i]); | |
2575 | if (ecdh_b[i] != NULL) | |
2576 | EC_KEY_free(ecdh_b[i]); | |
2577 | } | |
2578 | #endif | |
2579 | ||
c04f8cf4 | 2580 | apps_shutdown(); |
1c3e4a36 | 2581 | OPENSSL_EXIT(mret); |
d02b48c6 RE |
2582 | } |
2583 | ||
646d5695 | 2584 | static void print_message(const char *s, long num, int length) |
d02b48c6 RE |
2585 | { |
2586 | #ifdef SIGALRM | |
0e211563 BL |
2587 | BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n" |
2588 | : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length); | |
d58d092b | 2589 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
2590 | alarm(SECONDS); |
2591 | #else | |
0e211563 BL |
2592 | BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n" |
2593 | : "Doing %s %ld times on %d size blocks: ",s,num,length); | |
d58d092b | 2594 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
2595 | #endif |
2596 | #ifdef LINT | |
2597 | num=num; | |
2598 | #endif | |
2599 | } | |
2600 | ||
689c6f25 NL |
2601 | static void pkey_print_message(const char *str, const char *str2, long num, |
2602 | int bits, int tm) | |
d02b48c6 RE |
2603 | { |
2604 | #ifdef SIGALRM | |
0e211563 BL |
2605 | BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n" |
2606 | : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm); | |
d58d092b | 2607 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
2608 | alarm(RSA_SECONDS); |
2609 | #else | |
0e211563 BL |
2610 | BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n" |
2611 | : "Doing %ld %d bit %s %s's: ",num,bits,str,str2); | |
d58d092b | 2612 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
2613 | #endif |
2614 | #ifdef LINT | |
2615 | num=num; | |
2616 | #endif | |
2617 | } | |
58964a49 | 2618 | |
0e211563 BL |
2619 | static void print_result(int alg,int run_no,int count,double time_used) |
2620 | { | |
3ae70939 RL |
2621 | BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n" |
2622 | : "%d %s's in %.2fs\n",count,names[alg],time_used); | |
0e211563 BL |
2623 | results[alg][run_no]=((double)count)/time_used*lengths[run_no]; |
2624 | } | |
2625 | ||
d796e6ac | 2626 | #ifdef HAVE_FORK |
0e211563 BL |
2627 | static char *sstrsep(char **string, const char *delim) |
2628 | { | |
2629 | char isdelim[256]; | |
2630 | char *token = *string; | |
2631 | ||
2632 | if (**string == 0) | |
2633 | return NULL; | |
2634 | ||
54a656ef | 2635 | memset(isdelim, 0, sizeof isdelim); |
0e211563 BL |
2636 | isdelim[0] = 1; |
2637 | ||
2638 | while (*delim) | |
2639 | { | |
2640 | isdelim[(unsigned char)(*delim)] = 1; | |
2641 | delim++; | |
2642 | } | |
2643 | ||
2644 | while (!isdelim[(unsigned char)(**string)]) | |
2645 | { | |
2646 | (*string)++; | |
2647 | } | |
2648 | ||
2649 | if (**string) | |
2650 | { | |
2651 | **string = 0; | |
2652 | (*string)++; | |
2653 | } | |
2654 | ||
2655 | return token; | |
2656 | } | |
2657 | ||
2658 | static int do_multi(int multi) | |
2659 | { | |
2660 | int n; | |
2661 | int fd[2]; | |
2662 | int *fds; | |
2663 | static char sep[]=":"; | |
2664 | ||
2665 | fds=malloc(multi*sizeof *fds); | |
2666 | for(n=0 ; n < multi ; ++n) | |
2667 | { | |
2668 | pipe(fd); | |
2669 | if(fork()) | |
2670 | { | |
2671 | close(fd[1]); | |
2672 | fds[n]=fd[0]; | |
2673 | } | |
2674 | else | |
2675 | { | |
2676 | close(fd[0]); | |
2677 | close(1); | |
2678 | dup(fd[1]); | |
2679 | close(fd[1]); | |
2680 | mr=1; | |
2681 | usertime=0; | |
2682 | return 0; | |
2683 | } | |
2684 | printf("Forked child %d\n",n); | |
2685 | } | |
2686 | ||
2687 | /* for now, assume the pipe is long enough to take all the output */ | |
2688 | for(n=0 ; n < multi ; ++n) | |
2689 | { | |
2690 | FILE *f; | |
2691 | char buf[1024]; | |
2692 | char *p; | |
2693 | ||
2694 | f=fdopen(fds[n],"r"); | |
2695 | while(fgets(buf,sizeof buf,f)) | |
2696 | { | |
2697 | p=strchr(buf,'\n'); | |
2698 | if(p) | |
2699 | *p='\0'; | |
2700 | if(buf[0] != '+') | |
2701 | { | |
2702 | fprintf(stderr,"Don't understand line '%s' from child %d\n", | |
2703 | buf,n); | |
2704 | continue; | |
2705 | } | |
2706 | printf("Got: %s from %d\n",buf,n); | |
2707 | if(!strncmp(buf,"+F:",3)) | |
2708 | { | |
2709 | int alg; | |
2710 | int j; | |
2711 | ||
2712 | p=buf+3; | |
2713 | alg=atoi(sstrsep(&p,sep)); | |
2714 | sstrsep(&p,sep); | |
2715 | for(j=0 ; j < SIZE_NUM ; ++j) | |
2716 | results[alg][j]+=atof(sstrsep(&p,sep)); | |
2717 | } | |
2718 | else if(!strncmp(buf,"+F2:",4)) | |
2719 | { | |
2720 | int k; | |
2721 | double d; | |
2722 | ||
2723 | p=buf+4; | |
2724 | k=atoi(sstrsep(&p,sep)); | |
2725 | sstrsep(&p,sep); | |
2726 | ||
2727 | d=atof(sstrsep(&p,sep)); | |
2728 | if(n) | |
2729 | rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); | |
2730 | else | |
2731 | rsa_results[k][0]=d; | |
2732 | ||
2733 | d=atof(sstrsep(&p,sep)); | |
2734 | if(n) | |
2735 | rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); | |
2736 | else | |
2737 | rsa_results[k][1]=d; | |
2738 | } | |
2739 | else if(!strncmp(buf,"+F2:",4)) | |
2740 | { | |
2741 | int k; | |
2742 | double d; | |
2743 | ||
2744 | p=buf+4; | |
2745 | k=atoi(sstrsep(&p,sep)); | |
2746 | sstrsep(&p,sep); | |
2747 | ||
2748 | d=atof(sstrsep(&p,sep)); | |
2749 | if(n) | |
2750 | rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); | |
2751 | else | |
2752 | rsa_results[k][0]=d; | |
2753 | ||
2754 | d=atof(sstrsep(&p,sep)); | |
2755 | if(n) | |
2756 | rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); | |
2757 | else | |
2758 | rsa_results[k][1]=d; | |
2759 | } | |
2760 | else if(!strncmp(buf,"+F3:",4)) | |
2761 | { | |
2762 | int k; | |
2763 | double d; | |
2764 | ||
2765 | p=buf+4; | |
2766 | k=atoi(sstrsep(&p,sep)); | |
2767 | sstrsep(&p,sep); | |
2768 | ||
2769 | d=atof(sstrsep(&p,sep)); | |
2770 | if(n) | |
2771 | dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); | |
2772 | else | |
2773 | dsa_results[k][0]=d; | |
2774 | ||
2775 | d=atof(sstrsep(&p,sep)); | |
2776 | if(n) | |
2777 | dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); | |
2778 | else | |
2779 | dsa_results[k][1]=d; | |
2780 | } | |
e172d60d BM |
2781 | #ifndef OPENSSL_NO_ECDSA |
2782 | else if(!strncmp(buf,"+F4:",4)) | |
2783 | { | |
2784 | int k; | |
2785 | double d; | |
2786 | ||
2787 | p=buf+4; | |
2788 | k=atoi(sstrsep(&p,sep)); | |
2789 | sstrsep(&p,sep); | |
2790 | ||
2791 | d=atof(sstrsep(&p,sep)); | |
2792 | if(n) | |
2793 | ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d); | |
2794 | else | |
2795 | ecdsa_results[k][0]=d; | |
2796 | ||
2797 | d=atof(sstrsep(&p,sep)); | |
2798 | if(n) | |
2799 | ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d); | |
2800 | else | |
2801 | ecdsa_results[k][1]=d; | |
2802 | } | |
2803 | #endif | |
2804 | ||
2805 | #ifndef OPENSSL_NO_ECDH | |
2806 | else if(!strncmp(buf,"+F5:",4)) | |
2807 | { | |
2808 | int k; | |
2809 | double d; | |
2810 | ||
2811 | p=buf+4; | |
2812 | k=atoi(sstrsep(&p,sep)); | |
2813 | sstrsep(&p,sep); | |
2814 | ||
2815 | d=atof(sstrsep(&p,sep)); | |
2816 | if(n) | |
2817 | ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d); | |
2818 | else | |
2819 | ecdh_results[k][0]=d; | |
2820 | ||
2821 | } | |
2822 | #endif | |
2823 | ||
0e211563 BL |
2824 | else if(!strncmp(buf,"+H:",3)) |
2825 | { | |
2826 | } | |
2827 | else | |
2828 | fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); | |
2829 | } | |
2830 | } | |
2831 | return 1; | |
2832 | } | |
66d3e748 | 2833 | #endif |
85d686e7 | 2834 | #endif |