]>
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 | */ | |
58 | ||
59 | /* most of this code has been pilfered from my libdes speed.c program */ | |
60 | ||
61 | #undef SECONDS | |
62 | #define SECONDS 3 | |
dfeab068 RE |
63 | #define RSA_SECONDS 10 |
64 | #define DSA_SECONDS 10 | |
d02b48c6 RE |
65 | |
66 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | |
67 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | |
68 | ||
69 | #undef PROG | |
70 | #define PROG speed_main | |
71 | ||
72 | #include <stdio.h> | |
73 | #include <stdlib.h> | |
74 | #include <signal.h> | |
75 | #include <string.h> | |
58964a49 | 76 | #include <math.h> |
d02b48c6 | 77 | #include "apps.h" |
cf1b7d96 | 78 | #ifdef OPENSSL_NO_STDIO |
d02b48c6 RE |
79 | #define APPS_WIN16 |
80 | #endif | |
ec577822 BM |
81 | #include <openssl/crypto.h> |
82 | #include <openssl/rand.h> | |
83 | #include <openssl/err.h> | |
646d5695 BL |
84 | #include <openssl/evp.h> |
85 | #include <openssl/objects.h> | |
a4a8f7b3 | 86 | #include OPENSSL_UNISTD |
d02b48c6 | 87 | |
c3bdbcf6 | 88 | #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX) |
2bfb4dbc | 89 | # define USE_TOD |
bc36ee62 | 90 | #elif !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) |
2bfb4dbc | 91 | # define TIMES |
d02b48c6 | 92 | #endif |
cf1b7d96 | 93 | #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) /* FIXME */ |
3132e196 RL |
94 | # define TIMEB |
95 | #endif | |
d02b48c6 | 96 | |
d02b48c6 | 97 | #ifndef _IRIX |
2bfb4dbc | 98 | # include <time.h> |
d02b48c6 RE |
99 | #endif |
100 | #ifdef TIMES | |
2bfb4dbc BL |
101 | # include <sys/types.h> |
102 | # include <sys/times.h> | |
103 | #endif | |
104 | #ifdef USE_TOD | |
105 | # include <sys/time.h> | |
106 | # include <sys/resource.h> | |
d02b48c6 | 107 | #endif |
7d7d2cbc UM |
108 | |
109 | /* Depending on the VMS version, the tms structure is perhaps defined. | |
110 | The __TMS macro will show if it was. If it wasn't defined, we should | |
111 | undefine TIMES, since that tells the rest of the program how things | |
112 | should be handled. -- Richard Levitte */ | |
bc36ee62 | 113 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) |
7d7d2cbc | 114 | #undef TIMES |
d02b48c6 | 115 | #endif |
7d7d2cbc | 116 | |
3132e196 | 117 | #ifdef TIMEB |
d02b48c6 | 118 | #include <sys/timeb.h> |
3132e196 RL |
119 | #endif |
120 | ||
1cbb729f | 121 | #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) |
3132e196 RL |
122 | #error "It seems neither struct tms nor struct timeb is supported in this platform!" |
123 | #endif | |
d02b48c6 | 124 | |
dfeab068 RE |
125 | #if defined(sun) || defined(__ultrix) |
126 | #define _POSIX_SOURCE | |
d02b48c6 RE |
127 | #include <limits.h> |
128 | #include <sys/param.h> | |
129 | #endif | |
130 | ||
cf1b7d96 | 131 | #ifndef OPENSSL_NO_DES |
c2e4f17c | 132 | #include <openssl/des_old.h> |
d02b48c6 | 133 | #endif |
cf1b7d96 | 134 | #ifndef OPENSSL_NO_MD2 |
ec577822 | 135 | #include <openssl/md2.h> |
d02b48c6 | 136 | #endif |
cf1b7d96 | 137 | #ifndef OPENSSL_NO_MDC2 |
ec577822 | 138 | #include <openssl/mdc2.h> |
d02b48c6 | 139 | #endif |
cf1b7d96 | 140 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
141 | #include <openssl/md4.h> |
142 | #endif | |
cf1b7d96 | 143 | #ifndef OPENSSL_NO_MD5 |
ec577822 | 144 | #include <openssl/md5.h> |
5271ebd9 | 145 | #endif |
cf1b7d96 | 146 | #ifndef OPENSSL_NO_HMAC |
ec577822 | 147 | #include <openssl/hmac.h> |
d02b48c6 | 148 | #endif |
5271ebd9 | 149 | #include <openssl/evp.h> |
cf1b7d96 | 150 | #ifndef OPENSSL_NO_SHA |
ec577822 | 151 | #include <openssl/sha.h> |
d02b48c6 | 152 | #endif |
cf1b7d96 | 153 | #ifndef OPENSSL_NO_RIPEMD |
ec577822 | 154 | #include <openssl/ripemd.h> |
58964a49 | 155 | #endif |
cf1b7d96 | 156 | #ifndef OPENSSL_NO_RC4 |
ec577822 | 157 | #include <openssl/rc4.h> |
d02b48c6 | 158 | #endif |
cf1b7d96 | 159 | #ifndef OPENSSL_NO_RC5 |
ec577822 | 160 | #include <openssl/rc5.h> |
58964a49 | 161 | #endif |
cf1b7d96 | 162 | #ifndef OPENSSL_NO_RC2 |
ec577822 | 163 | #include <openssl/rc2.h> |
d02b48c6 | 164 | #endif |
cf1b7d96 | 165 | #ifndef OPENSSL_NO_IDEA |
ec577822 | 166 | #include <openssl/idea.h> |
d02b48c6 | 167 | #endif |
cf1b7d96 | 168 | #ifndef OPENSSL_NO_BF |
ec577822 | 169 | #include <openssl/blowfish.h> |
d02b48c6 | 170 | #endif |
cf1b7d96 | 171 | #ifndef OPENSSL_NO_CAST |
ec577822 | 172 | #include <openssl/cast.h> |
58964a49 | 173 | #endif |
cf1b7d96 | 174 | #ifndef OPENSSL_NO_RSA |
ec577822 | 175 | #include <openssl/rsa.h> |
f5d7a031 | 176 | #include "./testrsa.h" |
d02b48c6 | 177 | #endif |
ec577822 | 178 | #include <openssl/x509.h> |
cf1b7d96 | 179 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
180 | #include "./testdsa.h" |
181 | #endif | |
182 | ||
183 | /* The following if from times(3) man page. It may need to be changed */ | |
184 | #ifndef HZ | |
a4a8f7b3 RL |
185 | # ifdef _SC_CLK_TCK |
186 | # define HZ ((double)sysconf(_SC_CLK_TCK)) | |
187 | # else | |
188 | # ifndef CLK_TCK | |
189 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | |
190 | # define HZ 100.0 | |
191 | # else /* _BSD_CLK_TCK_ */ | |
192 | # define HZ ((double)_BSD_CLK_TCK_) | |
193 | # endif | |
194 | # else /* CLK_TCK */ | |
7876e448 RL |
195 | # define HZ ((double)CLK_TCK) |
196 | # endif | |
d02b48c6 RE |
197 | # endif |
198 | #endif | |
199 | ||
200 | #undef BUFSIZE | |
58964a49 | 201 | #define BUFSIZE ((long)1024*8+1) |
d02b48c6 RE |
202 | int run=0; |
203 | ||
7876e448 | 204 | static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0; |
0e211563 BL |
205 | static int mr=0; |
206 | static int usertime=1; | |
7876e448 | 207 | |
0e211563 | 208 | static double Time_F(int s); |
646d5695 | 209 | static void print_message(const char *s,long num,int length); |
d02b48c6 | 210 | static void pkey_print_message(char *str,char *str2,long num,int bits,int sec); |
0e211563 BL |
211 | static void print_result(int alg,int run_no,int count,double time_used); |
212 | static int do_multi(int multi); | |
d02b48c6 RE |
213 | #ifdef SIGALRM |
214 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | |
215 | #define SIGRETTYPE void | |
216 | #else | |
217 | #define SIGRETTYPE int | |
218 | #endif | |
219 | ||
0e211563 BL |
220 | #define ALGOR_NUM 16 |
221 | #define SIZE_NUM 5 | |
222 | #define RSA_NUM 4 | |
223 | #define DSA_NUM 3 | |
224 | static const char *names[ALGOR_NUM]={ | |
225 | "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4", | |
226 | "des cbc","des ede3","idea cbc", | |
227 | "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"}; | |
228 | static double results[ALGOR_NUM][SIZE_NUM]; | |
229 | static int lengths[SIZE_NUM]={8,64,256,1024,8*1024}; | |
230 | static double rsa_results[RSA_NUM][2]; | |
231 | static double dsa_results[DSA_NUM][2]; | |
232 | ||
d02b48c6 | 233 | static SIGRETTYPE sig_done(int sig); |
6b691a5c | 234 | static SIGRETTYPE sig_done(int sig) |
d02b48c6 RE |
235 | { |
236 | signal(SIGALRM,sig_done); | |
237 | run=0; | |
238 | #ifdef LINT | |
239 | sig=sig; | |
240 | #endif | |
241 | } | |
242 | #endif | |
243 | ||
244 | #define START 0 | |
245 | #define STOP 1 | |
246 | ||
0e211563 | 247 | static double Time_F(int s) |
d02b48c6 RE |
248 | { |
249 | double ret; | |
2bfb4dbc BL |
250 | |
251 | #ifdef USE_TOD | |
252 | if(usertime) | |
253 | { | |
254 | static struct rusage tstart,tend; | |
255 | ||
7876e448 | 256 | getrusage_used = 1; |
2bfb4dbc BL |
257 | if (s == START) |
258 | { | |
259 | getrusage(RUSAGE_SELF,&tstart); | |
260 | return(0); | |
261 | } | |
262 | else | |
263 | { | |
264 | long i; | |
265 | ||
266 | getrusage(RUSAGE_SELF,&tend); | |
267 | i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec; | |
268 | ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec)) | |
269 | +((double)i)/1000000.0; | |
270 | return((ret < 0.001)?0.001:ret); | |
271 | } | |
272 | } | |
273 | else | |
274 | { | |
275 | static struct timeval tstart,tend; | |
276 | long i; | |
277 | ||
7876e448 | 278 | gettimeofday_used = 1; |
2bfb4dbc BL |
279 | if (s == START) |
280 | { | |
281 | gettimeofday(&tstart,NULL); | |
282 | return(0); | |
283 | } | |
284 | else | |
285 | { | |
286 | gettimeofday(&tend,NULL); | |
287 | i=(long)tend.tv_usec-(long)tstart.tv_usec; | |
288 | ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0; | |
289 | return((ret < 0.001)?0.001:ret); | |
290 | } | |
291 | } | |
292 | #else /* ndef USE_TOD */ | |
293 | ||
294 | # ifdef TIMES | |
4e74239c | 295 | if (usertime) |
d02b48c6 | 296 | { |
4e74239c | 297 | static struct tms tstart,tend; |
d02b48c6 | 298 | |
7876e448 | 299 | times_used = 1; |
4e74239c RL |
300 | if (s == START) |
301 | { | |
302 | times(&tstart); | |
303 | return(0); | |
304 | } | |
305 | else | |
306 | { | |
307 | times(&tend); | |
308 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | |
309 | return((ret < 1e-3)?1e-3:ret); | |
310 | } | |
d02b48c6 | 311 | } |
2bfb4dbc | 312 | # endif /* times() */ |
3132e196 RL |
313 | # if defined(TIMES) && defined(TIMEB) |
314 | else | |
315 | # endif | |
316 | # ifdef TIMEB | |
d02b48c6 | 317 | { |
4e74239c RL |
318 | static struct timeb tstart,tend; |
319 | long i; | |
320 | ||
7876e448 | 321 | ftime_used = 1; |
4e74239c RL |
322 | if (s == START) |
323 | { | |
324 | ftime(&tstart); | |
325 | return(0); | |
326 | } | |
327 | else | |
328 | { | |
329 | ftime(&tend); | |
330 | i=(long)tend.millitm-(long)tstart.millitm; | |
331 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | |
332 | return((ret < 0.001)?0.001:ret); | |
333 | } | |
d02b48c6 | 334 | } |
3132e196 | 335 | # endif |
2bfb4dbc | 336 | #endif |
d02b48c6 RE |
337 | } |
338 | ||
667ac4ec RE |
339 | int MAIN(int, char **); |
340 | ||
6b691a5c | 341 | int MAIN(int argc, char **argv) |
d02b48c6 | 342 | { |
5270e702 | 343 | ENGINE *e; |
d02b48c6 | 344 | unsigned char *buf=NULL,*buf2=NULL; |
18c77bf2 | 345 | int mret=1; |
646d5695 | 346 | long count,rsa_count,save_count=0; |
18c77bf2 | 347 | int i,j,k; |
cf1b7d96 | 348 | #ifndef OPENSSL_NO_RSA |
5614bb91 | 349 | unsigned rsa_num; |
b2293b1e | 350 | #endif |
cf1b7d96 | 351 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
352 | unsigned char md2[MD2_DIGEST_LENGTH]; |
353 | #endif | |
cf1b7d96 | 354 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
355 | unsigned char mdc2[MDC2_DIGEST_LENGTH]; |
356 | #endif | |
cf1b7d96 | 357 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
358 | unsigned char md4[MD4_DIGEST_LENGTH]; |
359 | #endif | |
cf1b7d96 | 360 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 | 361 | unsigned char md5[MD5_DIGEST_LENGTH]; |
58964a49 | 362 | unsigned char hmac[MD5_DIGEST_LENGTH]; |
d02b48c6 | 363 | #endif |
cf1b7d96 | 364 | #ifndef OPENSSL_NO_SHA |
d02b48c6 RE |
365 | unsigned char sha[SHA_DIGEST_LENGTH]; |
366 | #endif | |
cf1b7d96 | 367 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
368 | unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; |
369 | #endif | |
cf1b7d96 | 370 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
371 | RC4_KEY rc4_ks; |
372 | #endif | |
cf1b7d96 | 373 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
374 | RC5_32_KEY rc5_ks; |
375 | #endif | |
cf1b7d96 | 376 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
377 | RC2_KEY rc2_ks; |
378 | #endif | |
cf1b7d96 | 379 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
380 | IDEA_KEY_SCHEDULE idea_ks; |
381 | #endif | |
cf1b7d96 | 382 | #ifndef OPENSSL_NO_BF |
d02b48c6 | 383 | BF_KEY bf_ks; |
58964a49 | 384 | #endif |
cf1b7d96 | 385 | #ifndef OPENSSL_NO_CAST |
58964a49 | 386 | CAST_KEY cast_ks; |
d02b48c6 RE |
387 | #endif |
388 | static unsigned char key16[16]= | |
389 | {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | |
390 | 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | |
391 | unsigned char iv[8]; | |
cf1b7d96 | 392 | #ifndef OPENSSL_NO_DES |
c2e4f17c | 393 | DES_cblock *buf_as_des_cblock = NULL; |
d02b48c6 RE |
394 | static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; |
395 | static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | |
396 | static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | |
c2e4f17c RL |
397 | DES_key_schedule sch; |
398 | DES_key_schedule sch2; | |
399 | DES_key_schedule sch3; | |
d02b48c6 RE |
400 | #endif |
401 | #define D_MD2 0 | |
402 | #define D_MDC2 1 | |
3009458e RL |
403 | #define D_MD4 2 |
404 | #define D_MD5 3 | |
405 | #define D_HMAC 4 | |
406 | #define D_SHA1 5 | |
407 | #define D_RMD160 6 | |
408 | #define D_RC4 7 | |
409 | #define D_CBC_DES 8 | |
410 | #define D_EDE3_DES 9 | |
411 | #define D_CBC_IDEA 10 | |
412 | #define D_CBC_RC2 11 | |
413 | #define D_CBC_RC5 12 | |
414 | #define D_CBC_BF 13 | |
415 | #define D_CBC_CAST 14 | |
646d5695 | 416 | #define D_EVP 15 |
0e211563 | 417 | double d; |
d02b48c6 | 418 | long c[ALGOR_NUM][SIZE_NUM]; |
d02b48c6 RE |
419 | #define R_DSA_512 0 |
420 | #define R_DSA_1024 1 | |
421 | #define R_DSA_2048 2 | |
422 | #define R_RSA_512 0 | |
423 | #define R_RSA_1024 1 | |
424 | #define R_RSA_2048 2 | |
425 | #define R_RSA_4096 3 | |
cf1b7d96 | 426 | #ifndef OPENSSL_NO_RSA |
d02b48c6 | 427 | RSA *rsa_key[RSA_NUM]; |
d02b48c6 | 428 | long rsa_c[RSA_NUM][2]; |
d02b48c6 | 429 | static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096}; |
d02b48c6 RE |
430 | static unsigned char *rsa_data[RSA_NUM]= |
431 | {test512,test1024,test2048,test4096}; | |
432 | static int rsa_data_length[RSA_NUM]={ | |
433 | sizeof(test512),sizeof(test1024), | |
434 | sizeof(test2048),sizeof(test4096)}; | |
58964a49 | 435 | #endif |
cf1b7d96 | 436 | #ifndef OPENSSL_NO_DSA |
58964a49 RE |
437 | DSA *dsa_key[DSA_NUM]; |
438 | long dsa_c[DSA_NUM][2]; | |
58964a49 RE |
439 | static unsigned int dsa_bits[DSA_NUM]={512,1024,2048}; |
440 | #endif | |
d02b48c6 RE |
441 | int rsa_doit[RSA_NUM]; |
442 | int dsa_doit[DSA_NUM]; | |
58964a49 | 443 | int doit[ALGOR_NUM]; |
d02b48c6 | 444 | int pr_header=0; |
646d5695 | 445 | const EVP_CIPHER *evp=NULL; |
3f37e73b | 446 | int decrypt=0; |
0e211563 | 447 | int multi=0; |
4e74239c RL |
448 | |
449 | #ifndef TIMES | |
450 | usertime=-1; | |
451 | #endif | |
d02b48c6 RE |
452 | |
453 | apps_startup(); | |
396f6314 | 454 | memset(results, 0, sizeof(results)); |
cf1b7d96 | 455 | #ifndef OPENSSL_NO_DSA |
dfeab068 RE |
456 | memset(dsa_key,0,sizeof(dsa_key)); |
457 | #endif | |
d02b48c6 RE |
458 | |
459 | if (bio_err == NULL) | |
460 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | |
58964a49 | 461 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); |
d02b48c6 | 462 | |
cf1b7d96 | 463 | #ifndef OPENSSL_NO_RSA |
dfeab068 | 464 | memset(rsa_key,0,sizeof(rsa_key)); |
d02b48c6 RE |
465 | for (i=0; i<RSA_NUM; i++) |
466 | rsa_key[i]=NULL; | |
dfeab068 | 467 | #endif |
d02b48c6 | 468 | |
26a3a48d | 469 | if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) |
d02b48c6 RE |
470 | { |
471 | BIO_printf(bio_err,"out of memory\n"); | |
472 | goto end; | |
473 | } | |
cf1b7d96 | 474 | #ifndef OPENSSL_NO_DES |
12ba413c | 475 | buf_as_des_cblock = (des_cblock *)buf; |
5676d8cb | 476 | #endif |
26a3a48d | 477 | if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) |
d02b48c6 RE |
478 | { |
479 | BIO_printf(bio_err,"out of memory\n"); | |
480 | goto end; | |
481 | } | |
482 | ||
483 | memset(c,0,sizeof(c)); | |
484 | memset(iv,0,sizeof(iv)); | |
485 | ||
486 | for (i=0; i<ALGOR_NUM; i++) | |
487 | doit[i]=0; | |
488 | for (i=0; i<RSA_NUM; i++) | |
489 | rsa_doit[i]=0; | |
490 | for (i=0; i<DSA_NUM; i++) | |
491 | dsa_doit[i]=0; | |
492 | ||
493 | j=0; | |
494 | argc--; | |
495 | argv++; | |
496 | while (argc) | |
497 | { | |
4e74239c | 498 | if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0)) |
7876e448 | 499 | { |
4e74239c | 500 | usertime = 0; |
7876e448 RL |
501 | j--; /* Otherwise, -elapsed gets confused with |
502 | an algorithm. */ | |
503 | } | |
646d5695 BL |
504 | else if ((argc > 0) && (strcmp(*argv,"-evp") == 0)) |
505 | { | |
506 | argc--; | |
507 | argv++; | |
508 | if(argc == 0) | |
509 | { | |
510 | BIO_printf(bio_err,"no EVP given\n"); | |
511 | goto end; | |
512 | } | |
513 | evp=EVP_get_cipherbyname(*argv); | |
514 | if(!evp) | |
515 | { | |
516 | BIO_printf(bio_err,"%s is an unknown cipher\n",*argv); | |
517 | goto end; | |
518 | } | |
519 | doit[D_EVP]=1; | |
520 | } | |
7876e448 RL |
521 | else if (argc > 0 && !strcmp(*argv,"-decrypt")) |
522 | { | |
3f37e73b | 523 | decrypt=1; |
7876e448 RL |
524 | j--; /* Otherwise, -elapsed gets confused with |
525 | an algorithm. */ | |
526 | } | |
527 | else if ((argc > 0) && (strcmp(*argv,"-engine") == 0)) | |
5270e702 RL |
528 | { |
529 | argc--; | |
530 | argv++; | |
531 | if(argc == 0) | |
532 | { | |
533 | BIO_printf(bio_err,"no engine given\n"); | |
534 | goto end; | |
535 | } | |
531d630b RL |
536 | e = setup_engine(bio_err, *argv, 0); |
537 | /* j will be increased again further down. We just | |
5270e702 RL |
538 | don't want speed to confuse an engine with an |
539 | algorithm, especially when none is given (which | |
540 | means all of them should be run) */ | |
541 | j--; | |
542 | } | |
0e211563 BL |
543 | else if ((argc > 0) && (strcmp(*argv,"-multi") == 0)) |
544 | { | |
545 | argc--; | |
546 | argv++; | |
547 | if(argc == 0) | |
548 | { | |
549 | BIO_printf(bio_err,"no multi count given\n"); | |
550 | goto end; | |
551 | } | |
552 | multi=atoi(argv[0]); | |
553 | if(multi <= 0) | |
554 | { | |
555 | BIO_printf(bio_err,"bad multi count\n"); | |
556 | goto end; | |
557 | } | |
558 | } | |
559 | else if (argc > 0 && !strcmp(*argv,"-mr")) | |
560 | { | |
561 | mr=1; | |
562 | j--; /* Otherwise, -mr gets confused with | |
563 | an algorithm. */ | |
564 | } | |
5270e702 | 565 | else |
cf1b7d96 | 566 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
567 | if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1; |
568 | else | |
569 | #endif | |
cf1b7d96 | 570 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
571 | if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1; |
572 | else | |
573 | #endif | |
cf1b7d96 | 574 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
575 | if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1; |
576 | else | |
577 | #endif | |
cf1b7d96 | 578 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 RE |
579 | if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1; |
580 | else | |
581 | #endif | |
cf1b7d96 | 582 | #ifndef OPENSSL_NO_MD5 |
58964a49 | 583 | if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1; |
d02b48c6 RE |
584 | else |
585 | #endif | |
cf1b7d96 | 586 | #ifndef OPENSSL_NO_SHA |
d02b48c6 RE |
587 | if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1; |
588 | else | |
58964a49 RE |
589 | if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1; |
590 | else | |
591 | #endif | |
cf1b7d96 | 592 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
593 | if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1; |
594 | else | |
595 | if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1; | |
596 | else | |
597 | if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1; | |
598 | else | |
d02b48c6 | 599 | #endif |
cf1b7d96 | 600 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
601 | if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; |
602 | else | |
603 | #endif | |
cf1b7d96 | 604 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
605 | if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; |
606 | else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; | |
607 | else | |
608 | #endif | |
cf1b7d96 | 609 | #ifndef OPENSSL_NO_RSA |
ccb9643f | 610 | #if 0 /* was: #ifdef RSAref */ |
d02b48c6 RE |
611 | if (strcmp(*argv,"rsaref") == 0) |
612 | { | |
5270e702 | 613 | RSA_set_default_openssl_method(RSA_PKCS1_RSAref()); |
d02b48c6 RE |
614 | j--; |
615 | } | |
616 | else | |
617 | #endif | |
c1cd88a0 | 618 | #ifndef RSA_NULL |
e170a5c0 | 619 | if (strcmp(*argv,"openssl") == 0) |
d02b48c6 | 620 | { |
6dc5d570 | 621 | RSA_set_default_method(RSA_PKCS1_SSLeay()); |
d02b48c6 RE |
622 | j--; |
623 | } | |
624 | else | |
c1cd88a0 | 625 | #endif |
cf1b7d96 | 626 | #endif /* !OPENSSL_NO_RSA */ |
d02b48c6 RE |
627 | if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; |
628 | else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; | |
629 | else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2; | |
630 | else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2; | |
631 | else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2; | |
632 | else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2; | |
633 | else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2; | |
634 | else | |
cf1b7d96 | 635 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
636 | if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1; |
637 | else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1; | |
638 | else | |
639 | #endif | |
cf1b7d96 | 640 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
641 | if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1; |
642 | else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1; | |
643 | else | |
644 | #endif | |
cf1b7d96 | 645 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
646 | if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1; |
647 | else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1; | |
648 | else | |
649 | #endif | |
cf1b7d96 | 650 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
651 | if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1; |
652 | else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1; | |
58964a49 RE |
653 | else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1; |
654 | else | |
655 | #endif | |
cf1b7d96 | 656 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
657 | if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1; |
658 | else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1; | |
659 | else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1; | |
d02b48c6 RE |
660 | else |
661 | #endif | |
cf1b7d96 | 662 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
663 | if (strcmp(*argv,"des") == 0) |
664 | { | |
665 | doit[D_CBC_DES]=1; | |
666 | doit[D_EDE3_DES]=1; | |
667 | } | |
668 | else | |
669 | #endif | |
cf1b7d96 | 670 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
671 | if (strcmp(*argv,"rsa") == 0) |
672 | { | |
673 | rsa_doit[R_RSA_512]=1; | |
674 | rsa_doit[R_RSA_1024]=1; | |
675 | rsa_doit[R_RSA_2048]=1; | |
676 | rsa_doit[R_RSA_4096]=1; | |
677 | } | |
678 | else | |
679 | #endif | |
cf1b7d96 | 680 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
681 | if (strcmp(*argv,"dsa") == 0) |
682 | { | |
683 | dsa_doit[R_DSA_512]=1; | |
684 | dsa_doit[R_DSA_1024]=1; | |
685 | } | |
686 | else | |
687 | #endif | |
688 | { | |
3009458e RL |
689 | BIO_printf(bio_err,"Error: bad option or value\n"); |
690 | BIO_printf(bio_err,"\n"); | |
691 | BIO_printf(bio_err,"Available values:\n"); | |
cf1b7d96 | 692 | #ifndef OPENSSL_NO_MD2 |
3009458e RL |
693 | BIO_printf(bio_err,"md2 "); |
694 | #endif | |
cf1b7d96 | 695 | #ifndef OPENSSL_NO_MDC2 |
3009458e RL |
696 | BIO_printf(bio_err,"mdc2 "); |
697 | #endif | |
cf1b7d96 | 698 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
699 | BIO_printf(bio_err,"md4 "); |
700 | #endif | |
cf1b7d96 | 701 | #ifndef OPENSSL_NO_MD5 |
3009458e | 702 | BIO_printf(bio_err,"md5 "); |
cf1b7d96 | 703 | #ifndef OPENSSL_NO_HMAC |
3009458e RL |
704 | BIO_printf(bio_err,"hmac "); |
705 | #endif | |
706 | #endif | |
cf1b7d96 | 707 | #ifndef OPENSSL_NO_SHA1 |
3009458e RL |
708 | BIO_printf(bio_err,"sha1 "); |
709 | #endif | |
cf1b7d96 | 710 | #ifndef OPENSSL_NO_RIPEMD160 |
3009458e RL |
711 | BIO_printf(bio_err,"rmd160"); |
712 | #endif | |
cf1b7d96 RL |
713 | #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \ |
714 | !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \ | |
715 | !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) | |
3009458e RL |
716 | BIO_printf(bio_err,"\n"); |
717 | #endif | |
718 | ||
cf1b7d96 | 719 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
720 | BIO_printf(bio_err,"idea-cbc "); |
721 | #endif | |
cf1b7d96 | 722 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
723 | BIO_printf(bio_err,"rc2-cbc "); |
724 | #endif | |
cf1b7d96 | 725 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
726 | BIO_printf(bio_err,"rc5-cbc "); |
727 | #endif | |
cf1b7d96 | 728 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
729 | BIO_printf(bio_err,"bf-cbc"); |
730 | #endif | |
cf1b7d96 RL |
731 | #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ |
732 | !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5) | |
d02b48c6 RE |
733 | BIO_printf(bio_err,"\n"); |
734 | #endif | |
3009458e | 735 | |
d02b48c6 | 736 | BIO_printf(bio_err,"des-cbc des-ede3 "); |
cf1b7d96 | 737 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
738 | BIO_printf(bio_err,"rc4"); |
739 | #endif | |
3009458e RL |
740 | BIO_printf(bio_err,"\n"); |
741 | ||
cf1b7d96 | 742 | #ifndef OPENSSL_NO_RSA |
3009458e | 743 | BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n"); |
d02b48c6 | 744 | #endif |
3009458e | 745 | |
cf1b7d96 | 746 | #ifndef OPENSSL_NO_DSA |
3009458e RL |
747 | BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n"); |
748 | #endif | |
749 | ||
cf1b7d96 | 750 | #ifndef OPENSSL_NO_IDEA |
3009458e RL |
751 | BIO_printf(bio_err,"idea "); |
752 | #endif | |
cf1b7d96 | 753 | #ifndef OPENSSL_NO_RC2 |
3009458e RL |
754 | BIO_printf(bio_err,"rc2 "); |
755 | #endif | |
cf1b7d96 | 756 | #ifndef OPENSSL_NO_DES |
3009458e | 757 | BIO_printf(bio_err,"des "); |
d02b48c6 | 758 | #endif |
cf1b7d96 | 759 | #ifndef OPENSSL_NO_RSA |
3009458e RL |
760 | BIO_printf(bio_err,"rsa "); |
761 | #endif | |
cf1b7d96 | 762 | #ifndef OPENSSL_NO_BF |
3009458e RL |
763 | BIO_printf(bio_err,"blowfish"); |
764 | #endif | |
cf1b7d96 RL |
765 | #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ |
766 | !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \ | |
767 | !defined(OPENSSL_NO_BF) | |
4e74239c | 768 | BIO_printf(bio_err,"\n"); |
3009458e RL |
769 | #endif |
770 | ||
4e74239c | 771 | BIO_printf(bio_err,"\n"); |
3009458e | 772 | BIO_printf(bio_err,"Available options:\n"); |
5270e702 | 773 | #ifdef TIMES |
4e74239c | 774 | BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n"); |
3132e196 | 775 | #endif |
5270e702 | 776 | BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n"); |
0e211563 BL |
777 | BIO_printf(bio_err,"-evp e use EVP e.\n"); |
778 | BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n"); | |
779 | BIO_printf(bio_err,"-mr produce machine readable output.\n"); | |
780 | BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n"); | |
d02b48c6 RE |
781 | goto end; |
782 | } | |
783 | argc--; | |
784 | argv++; | |
785 | j++; | |
786 | } | |
787 | ||
0e211563 BL |
788 | if(multi && do_multi(multi)) |
789 | goto show_res; | |
790 | ||
d02b48c6 RE |
791 | if (j == 0) |
792 | { | |
793 | for (i=0; i<ALGOR_NUM; i++) | |
53d28679 BM |
794 | { |
795 | if (i != D_EVP) | |
796 | doit[i]=1; | |
797 | } | |
d02b48c6 RE |
798 | for (i=0; i<RSA_NUM; i++) |
799 | rsa_doit[i]=1; | |
800 | for (i=0; i<DSA_NUM; i++) | |
801 | dsa_doit[i]=1; | |
802 | } | |
803 | for (i=0; i<ALGOR_NUM; i++) | |
804 | if (doit[i]) pr_header++; | |
805 | ||
0e211563 | 806 | if (usertime == 0 && !mr) |
4e74239c | 807 | BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n"); |
0e211563 | 808 | if (usertime <= 0 && !mr) |
4e74239c RL |
809 | { |
810 | BIO_printf(bio_err,"To get the most accurate results, try to run this\n"); | |
811 | BIO_printf(bio_err,"program when this computer is idle.\n"); | |
812 | } | |
d02b48c6 | 813 | |
cf1b7d96 | 814 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
815 | for (i=0; i<RSA_NUM; i++) |
816 | { | |
5e4ca422 | 817 | const unsigned char *p; |
d02b48c6 RE |
818 | |
819 | p=rsa_data[i]; | |
820 | rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]); | |
821 | if (rsa_key[i] == NULL) | |
822 | { | |
823 | BIO_printf(bio_err,"internal error loading RSA key number %d\n",i); | |
824 | goto end; | |
825 | } | |
58964a49 RE |
826 | #if 0 |
827 | else | |
828 | { | |
0e211563 BL |
829 | BIO_printf(bio_err,mr ? "+RK:%d:" |
830 | : "Loaded RSA key, %d bit modulus and e= 0x", | |
831 | BN_num_bits(rsa_key[i]->n)); | |
58964a49 RE |
832 | BN_print(bio_err,rsa_key[i]->e); |
833 | BIO_printf(bio_err,"\n"); | |
834 | } | |
835 | #endif | |
d02b48c6 RE |
836 | } |
837 | #endif | |
838 | ||
cf1b7d96 | 839 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
840 | dsa_key[0]=get_dsa512(); |
841 | dsa_key[1]=get_dsa1024(); | |
842 | dsa_key[2]=get_dsa2048(); | |
843 | #endif | |
844 | ||
cf1b7d96 | 845 | #ifndef OPENSSL_NO_DES |
c2e4f17c RL |
846 | DES_set_key_unchecked(&key,&sch); |
847 | DES_set_key_unchecked(&key2,&sch2); | |
848 | DES_set_key_unchecked(&key3,&sch3); | |
d02b48c6 | 849 | #endif |
cf1b7d96 | 850 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
851 | idea_set_encrypt_key(key16,&idea_ks); |
852 | #endif | |
cf1b7d96 | 853 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
854 | RC4_set_key(&rc4_ks,16,key16); |
855 | #endif | |
cf1b7d96 | 856 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
857 | RC2_set_key(&rc2_ks,16,key16,128); |
858 | #endif | |
cf1b7d96 | 859 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
860 | RC5_32_set_key(&rc5_ks,16,key16,12); |
861 | #endif | |
cf1b7d96 | 862 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
863 | BF_set_key(&bf_ks,16,key16); |
864 | #endif | |
cf1b7d96 | 865 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
866 | CAST_set_key(&cast_ks,16,key16); |
867 | #endif | |
cf1b7d96 | 868 | #ifndef OPENSSL_NO_RSA |
d02b48c6 | 869 | memset(rsa_c,0,sizeof(rsa_c)); |
f5d7a031 | 870 | #endif |
d02b48c6 | 871 | #ifndef SIGALRM |
cf1b7d96 | 872 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
873 | BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); |
874 | count=10; | |
875 | do { | |
876 | long i; | |
877 | count*=2; | |
4e74239c | 878 | Time_F(START,usertime); |
d02b48c6 | 879 | for (i=count; i; i--) |
12ba413c | 880 | des_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock, |
3d90a324 | 881 | &sch,DES_ENCRYPT); |
0e211563 | 882 | d=Time_F(STOP); |
d02b48c6 | 883 | } while (d <3); |
646d5695 | 884 | save_count=count; |
d02b48c6 RE |
885 | c[D_MD2][0]=count/10; |
886 | c[D_MDC2][0]=count/10; | |
3009458e | 887 | c[D_MD4][0]=count; |
d02b48c6 | 888 | c[D_MD5][0]=count; |
58964a49 | 889 | c[D_HMAC][0]=count; |
d02b48c6 | 890 | c[D_SHA1][0]=count; |
58964a49 | 891 | c[D_RMD160][0]=count; |
d02b48c6 RE |
892 | c[D_RC4][0]=count*5; |
893 | c[D_CBC_DES][0]=count; | |
894 | c[D_EDE3_DES][0]=count/3; | |
895 | c[D_CBC_IDEA][0]=count; | |
896 | c[D_CBC_RC2][0]=count; | |
58964a49 | 897 | c[D_CBC_RC5][0]=count; |
d02b48c6 | 898 | c[D_CBC_BF][0]=count; |
58964a49 | 899 | c[D_CBC_CAST][0]=count; |
d02b48c6 RE |
900 | |
901 | for (i=1; i<SIZE_NUM; i++) | |
902 | { | |
903 | c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i]; | |
904 | c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i]; | |
3009458e | 905 | c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i]; |
d02b48c6 | 906 | c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i]; |
58964a49 | 907 | c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i]; |
d02b48c6 | 908 | c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i]; |
58964a49 | 909 | c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i]; |
d02b48c6 RE |
910 | } |
911 | for (i=1; i<SIZE_NUM; i++) | |
912 | { | |
913 | long l0,l1; | |
914 | ||
915 | l0=(long)lengths[i-1]; | |
916 | l1=(long)lengths[i]; | |
917 | c[D_RC4][i]=c[D_RC4][i-1]*l0/l1; | |
918 | c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1; | |
919 | c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1; | |
920 | c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1; | |
921 | c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1; | |
58964a49 | 922 | c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1; |
d02b48c6 | 923 | c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1; |
58964a49 | 924 | c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1; |
d02b48c6 | 925 | } |
cf1b7d96 | 926 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
927 | rsa_c[R_RSA_512][0]=count/2000; |
928 | rsa_c[R_RSA_512][1]=count/400; | |
929 | for (i=1; i<RSA_NUM; i++) | |
930 | { | |
931 | rsa_c[i][0]=rsa_c[i-1][0]/8; | |
932 | rsa_c[i][1]=rsa_c[i-1][1]/4; | |
933 | if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) | |
934 | rsa_doit[i]=0; | |
935 | else | |
936 | { | |
dfeab068 | 937 | if (rsa_c[i][0] == 0) |
d02b48c6 RE |
938 | { |
939 | rsa_c[i][0]=1; | |
940 | rsa_c[i][1]=20; | |
941 | } | |
942 | } | |
943 | } | |
f5d7a031 | 944 | #endif |
d02b48c6 | 945 | |
f89aebb1 | 946 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
947 | dsa_c[R_DSA_512][0]=count/1000; |
948 | dsa_c[R_DSA_512][1]=count/1000/2; | |
949 | for (i=1; i<DSA_NUM; i++) | |
950 | { | |
951 | dsa_c[i][0]=dsa_c[i-1][0]/4; | |
952 | dsa_c[i][1]=dsa_c[i-1][1]/4; | |
953 | if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) | |
954 | dsa_doit[i]=0; | |
955 | else | |
956 | { | |
957 | if (dsa_c[i] == 0) | |
958 | { | |
959 | dsa_c[i][0]=1; | |
960 | dsa_c[i][1]=1; | |
961 | } | |
962 | } | |
963 | } | |
f89aebb1 | 964 | #endif |
d02b48c6 | 965 | |
58964a49 | 966 | #define COND(d) (count < (d)) |
d02b48c6 RE |
967 | #define COUNT(d) (d) |
968 | #else | |
63da21c0 BM |
969 | /* not worth fixing */ |
970 | # error "You cannot disable DES on systems without SIGALRM." | |
cf1b7d96 | 971 | #endif /* OPENSSL_NO_DES */ |
63da21c0 | 972 | #else |
d02b48c6 RE |
973 | #define COND(c) (run) |
974 | #define COUNT(d) (count) | |
975 | signal(SIGALRM,sig_done); | |
63da21c0 | 976 | #endif /* SIGALRM */ |
d02b48c6 | 977 | |
cf1b7d96 | 978 | #ifndef OPENSSL_NO_MD2 |
d02b48c6 RE |
979 | if (doit[D_MD2]) |
980 | { | |
981 | for (j=0; j<SIZE_NUM; j++) | |
982 | { | |
983 | print_message(names[D_MD2],c[D_MD2][j],lengths[j]); | |
0e211563 | 984 | Time_F(START); |
d02b48c6 | 985 | for (count=0,run=1; COND(c[D_MD2][j]); count++) |
0e211563 BL |
986 | EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL); |
987 | d=Time_F(STOP); | |
988 | print_result(D_MD2,j,count,d); | |
d02b48c6 RE |
989 | } |
990 | } | |
991 | #endif | |
cf1b7d96 | 992 | #ifndef OPENSSL_NO_MDC2 |
d02b48c6 RE |
993 | if (doit[D_MDC2]) |
994 | { | |
995 | for (j=0; j<SIZE_NUM; j++) | |
996 | { | |
997 | print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]); | |
0e211563 | 998 | Time_F(START); |
d02b48c6 | 999 | for (count=0,run=1; COND(c[D_MDC2][j]); count++) |
0e211563 BL |
1000 | EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL); |
1001 | d=Time_F(STOP); | |
1002 | print_result(D_MDC2,j,count,d); | |
d02b48c6 RE |
1003 | } |
1004 | } | |
1005 | #endif | |
1006 | ||
cf1b7d96 | 1007 | #ifndef OPENSSL_NO_MD4 |
3009458e RL |
1008 | if (doit[D_MD4]) |
1009 | { | |
1010 | for (j=0; j<SIZE_NUM; j++) | |
1011 | { | |
1012 | print_message(names[D_MD4],c[D_MD4][j],lengths[j]); | |
0e211563 | 1013 | Time_F(START); |
3009458e | 1014 | for (count=0,run=1; COND(c[D_MD4][j]); count++) |
0e211563 BL |
1015 | EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL); |
1016 | d=Time_F(STOP); | |
1017 | print_result(D_MD4,j,count,d); | |
3009458e RL |
1018 | } |
1019 | } | |
1020 | #endif | |
1021 | ||
cf1b7d96 | 1022 | #ifndef OPENSSL_NO_MD5 |
d02b48c6 RE |
1023 | if (doit[D_MD5]) |
1024 | { | |
1025 | for (j=0; j<SIZE_NUM; j++) | |
1026 | { | |
1027 | print_message(names[D_MD5],c[D_MD5][j],lengths[j]); | |
0e211563 | 1028 | Time_F(START); |
d02b48c6 | 1029 | for (count=0,run=1; COND(c[D_MD5][j]); count++) |
0e211563 BL |
1030 | EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL); |
1031 | d=Time_F(STOP); | |
1032 | print_result(D_MD5,j,count,d); | |
d02b48c6 RE |
1033 | } |
1034 | } | |
1035 | #endif | |
1036 | ||
cf1b7d96 | 1037 | #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) |
58964a49 | 1038 | if (doit[D_HMAC]) |
d02b48c6 | 1039 | { |
58964a49 | 1040 | HMAC_CTX hctx; |
dbad1690 BL |
1041 | |
1042 | HMAC_CTX_init(&hctx); | |
58964a49 RE |
1043 | HMAC_Init(&hctx,(unsigned char *)"This is a key...", |
1044 | 16,EVP_md5()); | |
1045 | ||
d02b48c6 RE |
1046 | for (j=0; j<SIZE_NUM; j++) |
1047 | { | |
58964a49 | 1048 | print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]); |
0e211563 | 1049 | Time_F(START); |
58964a49 RE |
1050 | for (count=0,run=1; COND(c[D_HMAC][j]); count++) |
1051 | { | |
1052 | HMAC_Init(&hctx,NULL,0,NULL); | |
1053 | HMAC_Update(&hctx,buf,lengths[j]); | |
1054 | HMAC_Final(&hctx,&(hmac[0]),NULL); | |
1055 | } | |
0e211563 BL |
1056 | d=Time_F(STOP); |
1057 | print_result(D_HMAC,j,count,d); | |
d02b48c6 | 1058 | } |
dbad1690 | 1059 | HMAC_CTX_cleanup(&hctx); |
d02b48c6 RE |
1060 | } |
1061 | #endif | |
cf1b7d96 | 1062 | #ifndef OPENSSL_NO_SHA |
d02b48c6 RE |
1063 | if (doit[D_SHA1]) |
1064 | { | |
1065 | for (j=0; j<SIZE_NUM; j++) | |
1066 | { | |
1067 | print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]); | |
0e211563 | 1068 | Time_F(START); |
d02b48c6 | 1069 | for (count=0,run=1; COND(c[D_SHA1][j]); count++) |
0e211563 BL |
1070 | EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL); |
1071 | d=Time_F(STOP); | |
1072 | print_result(D_SHA1,j,count,d); | |
d02b48c6 RE |
1073 | } |
1074 | } | |
1075 | #endif | |
cf1b7d96 | 1076 | #ifndef OPENSSL_NO_RIPEMD |
58964a49 RE |
1077 | if (doit[D_RMD160]) |
1078 | { | |
1079 | for (j=0; j<SIZE_NUM; j++) | |
1080 | { | |
1081 | print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]); | |
0e211563 | 1082 | Time_F(START); |
58964a49 | 1083 | for (count=0,run=1; COND(c[D_RMD160][j]); count++) |
0e211563 BL |
1084 | EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL); |
1085 | d=Time_F(STOP); | |
1086 | print_result(D_RMD160,j,count,d); | |
58964a49 RE |
1087 | } |
1088 | } | |
1089 | #endif | |
cf1b7d96 | 1090 | #ifndef OPENSSL_NO_RC4 |
d02b48c6 RE |
1091 | if (doit[D_RC4]) |
1092 | { | |
1093 | for (j=0; j<SIZE_NUM; j++) | |
1094 | { | |
1095 | print_message(names[D_RC4],c[D_RC4][j],lengths[j]); | |
0e211563 | 1096 | Time_F(START); |
d02b48c6 RE |
1097 | for (count=0,run=1; COND(c[D_RC4][j]); count++) |
1098 | RC4(&rc4_ks,(unsigned int)lengths[j], | |
1099 | buf,buf); | |
0e211563 BL |
1100 | d=Time_F(STOP); |
1101 | print_result(D_RC4,j,count,d); | |
d02b48c6 RE |
1102 | } |
1103 | } | |
1104 | #endif | |
cf1b7d96 | 1105 | #ifndef OPENSSL_NO_DES |
d02b48c6 RE |
1106 | if (doit[D_CBC_DES]) |
1107 | { | |
1108 | for (j=0; j<SIZE_NUM; j++) | |
1109 | { | |
1110 | print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]); | |
0e211563 | 1111 | Time_F(START); |
d02b48c6 | 1112 | for (count=0,run=1; COND(c[D_CBC_DES][j]); count++) |
c2e4f17c | 1113 | DES_ncbc_encrypt(buf,buf,lengths[j],&sch, |
edf0bfb5 | 1114 | &iv,DES_ENCRYPT); |
0e211563 BL |
1115 | d=Time_F(STOP); |
1116 | print_result(D_CBC_DES,j,count,d); | |
d02b48c6 RE |
1117 | } |
1118 | } | |
1119 | ||
1120 | if (doit[D_EDE3_DES]) | |
1121 | { | |
1122 | for (j=0; j<SIZE_NUM; j++) | |
1123 | { | |
1124 | print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]); | |
0e211563 | 1125 | Time_F(START); |
d02b48c6 | 1126 | for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++) |
c2e4f17c | 1127 | DES_ede3_cbc_encrypt(buf,buf,lengths[j], |
dbad1690 | 1128 | &sch,&sch2,&sch3, |
edf0bfb5 | 1129 | &iv,DES_ENCRYPT); |
0e211563 BL |
1130 | d=Time_F(STOP); |
1131 | print_result(D_EDE3_DES,j,count,d); | |
d02b48c6 RE |
1132 | } |
1133 | } | |
1134 | #endif | |
cf1b7d96 | 1135 | #ifndef OPENSSL_NO_IDEA |
d02b48c6 RE |
1136 | if (doit[D_CBC_IDEA]) |
1137 | { | |
1138 | for (j=0; j<SIZE_NUM; j++) | |
1139 | { | |
1140 | print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]); | |
0e211563 | 1141 | Time_F(START); |
d02b48c6 RE |
1142 | for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++) |
1143 | idea_cbc_encrypt(buf,buf, | |
1144 | (unsigned long)lengths[j],&idea_ks, | |
12ba413c | 1145 | iv,IDEA_ENCRYPT); |
0e211563 BL |
1146 | d=Time_F(STOP); |
1147 | print_result(D_CBC_IDEA,j,count,d); | |
d02b48c6 RE |
1148 | } |
1149 | } | |
1150 | #endif | |
cf1b7d96 | 1151 | #ifndef OPENSSL_NO_RC2 |
d02b48c6 RE |
1152 | if (doit[D_CBC_RC2]) |
1153 | { | |
1154 | for (j=0; j<SIZE_NUM; j++) | |
1155 | { | |
1156 | print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]); | |
0e211563 | 1157 | Time_F(START); |
d02b48c6 RE |
1158 | for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++) |
1159 | RC2_cbc_encrypt(buf,buf, | |
1160 | (unsigned long)lengths[j],&rc2_ks, | |
12ba413c | 1161 | iv,RC2_ENCRYPT); |
0e211563 BL |
1162 | d=Time_F(STOP); |
1163 | print_result(D_CBC_RC2,j,count,d); | |
d02b48c6 RE |
1164 | } |
1165 | } | |
1166 | #endif | |
cf1b7d96 | 1167 | #ifndef OPENSSL_NO_RC5 |
58964a49 RE |
1168 | if (doit[D_CBC_RC5]) |
1169 | { | |
1170 | for (j=0; j<SIZE_NUM; j++) | |
1171 | { | |
1172 | print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]); | |
0e211563 | 1173 | Time_F(START); |
58964a49 RE |
1174 | for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++) |
1175 | RC5_32_cbc_encrypt(buf,buf, | |
1176 | (unsigned long)lengths[j],&rc5_ks, | |
12ba413c | 1177 | iv,RC5_ENCRYPT); |
0e211563 BL |
1178 | d=Time_F(STOP); |
1179 | print_result(D_CBC_RC5,j,count,d); | |
58964a49 RE |
1180 | } |
1181 | } | |
1182 | #endif | |
cf1b7d96 | 1183 | #ifndef OPENSSL_NO_BF |
d02b48c6 RE |
1184 | if (doit[D_CBC_BF]) |
1185 | { | |
1186 | for (j=0; j<SIZE_NUM; j++) | |
1187 | { | |
1188 | print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]); | |
0e211563 | 1189 | Time_F(START); |
d02b48c6 RE |
1190 | for (count=0,run=1; COND(c[D_CBC_BF][j]); count++) |
1191 | BF_cbc_encrypt(buf,buf, | |
1192 | (unsigned long)lengths[j],&bf_ks, | |
12ba413c | 1193 | iv,BF_ENCRYPT); |
0e211563 BL |
1194 | d=Time_F(STOP); |
1195 | print_result(D_CBC_BF,j,count,d); | |
d02b48c6 RE |
1196 | } |
1197 | } | |
1198 | #endif | |
cf1b7d96 | 1199 | #ifndef OPENSSL_NO_CAST |
58964a49 RE |
1200 | if (doit[D_CBC_CAST]) |
1201 | { | |
1202 | for (j=0; j<SIZE_NUM; j++) | |
1203 | { | |
1204 | print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]); | |
0e211563 | 1205 | Time_F(START); |
58964a49 RE |
1206 | for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++) |
1207 | CAST_cbc_encrypt(buf,buf, | |
1208 | (unsigned long)lengths[j],&cast_ks, | |
12ba413c | 1209 | iv,CAST_ENCRYPT); |
0e211563 BL |
1210 | d=Time_F(STOP); |
1211 | print_result(D_CBC_CAST,j,count,d); | |
58964a49 RE |
1212 | } |
1213 | } | |
1214 | #endif | |
d02b48c6 | 1215 | |
646d5695 BL |
1216 | if (doit[D_EVP]) |
1217 | { | |
1218 | for (j=0; j<SIZE_NUM; j++) | |
1219 | { | |
1220 | EVP_CIPHER_CTX ctx; | |
1221 | int outl; | |
1222 | ||
1223 | names[D_EVP]=OBJ_nid2ln(evp->nid); | |
1224 | print_message(names[D_EVP],save_count, | |
1225 | lengths[j]); | |
cecd2638 | 1226 | EVP_CIPHER_CTX_init(&ctx); |
3f37e73b | 1227 | if(decrypt) |
581f1c84 | 1228 | EVP_DecryptInit_ex(&ctx,evp,NULL,key16,iv); |
3f37e73b | 1229 | else |
581f1c84 | 1230 | EVP_EncryptInit_ex(&ctx,evp,NULL,key16,iv); |
3f37e73b | 1231 | |
0e211563 | 1232 | Time_F(START); |
3f37e73b BL |
1233 | if(decrypt) |
1234 | for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) | |
1235 | EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]); | |
1236 | else | |
1237 | for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) | |
1238 | EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]); | |
1239 | if(decrypt) | |
581f1c84 | 1240 | EVP_DecryptFinal_ex(&ctx,buf,&outl); |
3f37e73b | 1241 | else |
581f1c84 | 1242 | EVP_EncryptFinal_ex(&ctx,buf,&outl); |
0e211563 BL |
1243 | d=Time_F(STOP); |
1244 | print_result(D_EVP,j,count,d); | |
646d5695 BL |
1245 | } |
1246 | } | |
1247 | ||
373b575f | 1248 | RAND_pseudo_bytes(buf,36); |
cf1b7d96 | 1249 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1250 | for (j=0; j<RSA_NUM; j++) |
1251 | { | |
c91e1259 | 1252 | int ret; |
d02b48c6 | 1253 | if (!rsa_doit[j]) continue; |
c91e1259 | 1254 | ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]); |
03ea28c9 RL |
1255 | if (ret == 0) |
1256 | { | |
1257 | BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n"); | |
1258 | ERR_print_errors(bio_err); | |
1259 | rsa_count=1; | |
1260 | } | |
1261 | else | |
d02b48c6 | 1262 | { |
03ea28c9 RL |
1263 | pkey_print_message("private","rsa", |
1264 | rsa_c[j][0],rsa_bits[j], | |
1265 | RSA_SECONDS); | |
1266 | /* RSA_blinding_on(rsa_key[j],NULL); */ | |
0e211563 | 1267 | Time_F(START); |
03ea28c9 | 1268 | for (count=0,run=1; COND(rsa_c[j][0]); count++) |
d02b48c6 | 1269 | { |
03ea28c9 RL |
1270 | ret=RSA_sign(NID_md5_sha1, buf,36, buf2, |
1271 | &rsa_num, rsa_key[j]); | |
1272 | if (ret == 0) | |
1273 | { | |
1274 | BIO_printf(bio_err, | |
1275 | "RSA sign failure\n"); | |
1276 | ERR_print_errors(bio_err); | |
1277 | count=1; | |
1278 | break; | |
1279 | } | |
d02b48c6 | 1280 | } |
0e211563 BL |
1281 | d=Time_F(STOP); |
1282 | BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n" | |
1283 | : "%ld %d bit private RSA's in %.2fs\n", | |
1284 | count,rsa_bits[j],d); | |
03ea28c9 RL |
1285 | rsa_results[j][0]=d/(double)count; |
1286 | rsa_count=count; | |
d02b48c6 | 1287 | } |
d02b48c6 | 1288 | |
58964a49 | 1289 | #if 1 |
c91e1259 | 1290 | ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]); |
03ea28c9 | 1291 | if (ret <= 0) |
d02b48c6 | 1292 | { |
03ea28c9 RL |
1293 | BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n"); |
1294 | ERR_print_errors(bio_err); | |
51740b12 | 1295 | rsa_doit[j] = 0; |
03ea28c9 RL |
1296 | } |
1297 | else | |
1298 | { | |
1299 | pkey_print_message("public","rsa", | |
1300 | rsa_c[j][1],rsa_bits[j], | |
1301 | RSA_SECONDS); | |
0e211563 | 1302 | Time_F(START); |
03ea28c9 | 1303 | for (count=0,run=1; COND(rsa_c[j][1]); count++) |
d02b48c6 | 1304 | { |
03ea28c9 RL |
1305 | ret=RSA_verify(NID_md5_sha1, buf,36, buf2, |
1306 | rsa_num, rsa_key[j]); | |
1307 | if (ret == 0) | |
1308 | { | |
1309 | BIO_printf(bio_err, | |
1310 | "RSA verify failure\n"); | |
1311 | ERR_print_errors(bio_err); | |
1312 | count=1; | |
1313 | break; | |
1314 | } | |
d02b48c6 | 1315 | } |
0e211563 BL |
1316 | d=Time_F(STOP); |
1317 | BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n" | |
1318 | : "%ld %d bit public RSA's in %.2fs\n", | |
1319 | count,rsa_bits[j],d); | |
03ea28c9 | 1320 | rsa_results[j][1]=d/(double)count; |
d02b48c6 | 1321 | } |
58964a49 | 1322 | #endif |
d02b48c6 RE |
1323 | |
1324 | if (rsa_count <= 1) | |
1325 | { | |
1326 | /* if longer than 10s, don't do any more */ | |
1327 | for (j++; j<RSA_NUM; j++) | |
1328 | rsa_doit[j]=0; | |
1329 | } | |
1330 | } | |
1331 | #endif | |
1332 | ||
373b575f | 1333 | RAND_pseudo_bytes(buf,20); |
cf1b7d96 | 1334 | #ifndef OPENSSL_NO_DSA |
99a97051 UM |
1335 | if (RAND_status() != 1) |
1336 | { | |
1337 | RAND_seed(rnd_seed, sizeof rnd_seed); | |
1338 | rnd_fake = 1; | |
1339 | } | |
d02b48c6 RE |
1340 | for (j=0; j<DSA_NUM; j++) |
1341 | { | |
58964a49 | 1342 | unsigned int kk; |
03ea28c9 | 1343 | int ret; |
58964a49 | 1344 | |
d02b48c6 | 1345 | if (!dsa_doit[j]) continue; |
af436bc1 | 1346 | /* DSA_generate_key(dsa_key[j]); */ |
d02b48c6 | 1347 | /* DSA_sign_setup(dsa_key[j],NULL); */ |
03ea28c9 | 1348 | ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, |
dfeab068 | 1349 | &kk,dsa_key[j]); |
03ea28c9 RL |
1350 | if (ret == 0) |
1351 | { | |
1352 | BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n"); | |
1353 | ERR_print_errors(bio_err); | |
1354 | rsa_count=1; | |
1355 | } | |
1356 | else | |
d02b48c6 | 1357 | { |
03ea28c9 RL |
1358 | pkey_print_message("sign","dsa", |
1359 | dsa_c[j][0],dsa_bits[j], | |
1360 | DSA_SECONDS); | |
0e211563 | 1361 | Time_F(START); |
03ea28c9 | 1362 | for (count=0,run=1; COND(dsa_c[j][0]); count++) |
d02b48c6 | 1363 | { |
03ea28c9 RL |
1364 | ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, |
1365 | &kk,dsa_key[j]); | |
1366 | if (ret == 0) | |
1367 | { | |
1368 | BIO_printf(bio_err, | |
1369 | "DSA sign failure\n"); | |
1370 | ERR_print_errors(bio_err); | |
1371 | count=1; | |
1372 | break; | |
1373 | } | |
d02b48c6 | 1374 | } |
0e211563 BL |
1375 | d=Time_F(STOP); |
1376 | BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n" | |
1377 | : "%ld %d bit DSA signs in %.2fs\n", | |
1378 | count,dsa_bits[j],d); | |
03ea28c9 RL |
1379 | dsa_results[j][0]=d/(double)count; |
1380 | rsa_count=count; | |
d02b48c6 | 1381 | } |
d02b48c6 | 1382 | |
03ea28c9 | 1383 | ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, |
dfeab068 | 1384 | kk,dsa_key[j]); |
03ea28c9 RL |
1385 | if (ret <= 0) |
1386 | { | |
1387 | BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n"); | |
1388 | ERR_print_errors(bio_err); | |
1389 | dsa_doit[j] = 0; | |
1390 | } | |
1391 | else | |
d02b48c6 | 1392 | { |
03ea28c9 RL |
1393 | pkey_print_message("verify","dsa", |
1394 | dsa_c[j][1],dsa_bits[j], | |
1395 | DSA_SECONDS); | |
0e211563 | 1396 | Time_F(START); |
03ea28c9 | 1397 | for (count=0,run=1; COND(dsa_c[j][1]); count++) |
d02b48c6 | 1398 | { |
03ea28c9 RL |
1399 | ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, |
1400 | kk,dsa_key[j]); | |
1401 | if (ret <= 0) | |
1402 | { | |
1403 | BIO_printf(bio_err, | |
1404 | "DSA verify failure\n"); | |
1405 | ERR_print_errors(bio_err); | |
1406 | count=1; | |
1407 | break; | |
1408 | } | |
d02b48c6 | 1409 | } |
0e211563 BL |
1410 | d=Time_F(STOP); |
1411 | BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n" | |
1412 | : "%ld %d bit DSA verify in %.2fs\n", | |
1413 | count,dsa_bits[j],d); | |
03ea28c9 | 1414 | dsa_results[j][1]=d/(double)count; |
d02b48c6 | 1415 | } |
d02b48c6 RE |
1416 | |
1417 | if (rsa_count <= 1) | |
1418 | { | |
1419 | /* if longer than 10s, don't do any more */ | |
1420 | for (j++; j<DSA_NUM; j++) | |
1421 | dsa_doit[j]=0; | |
1422 | } | |
1423 | } | |
99a97051 | 1424 | if (rnd_fake) RAND_cleanup(); |
d02b48c6 | 1425 | #endif |
0e211563 BL |
1426 | show_res: |
1427 | if(!mr) | |
1428 | { | |
1429 | fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION)); | |
d02b48c6 | 1430 | fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON)); |
0e211563 BL |
1431 | printf("options:"); |
1432 | printf("%s ",BN_options()); | |
cf1b7d96 | 1433 | #ifndef OPENSSL_NO_MD2 |
0e211563 | 1434 | printf("%s ",MD2_options()); |
d02b48c6 | 1435 | #endif |
cf1b7d96 | 1436 | #ifndef OPENSSL_NO_RC4 |
0e211563 | 1437 | printf("%s ",RC4_options()); |
d02b48c6 | 1438 | #endif |
cf1b7d96 | 1439 | #ifndef OPENSSL_NO_DES |
0e211563 | 1440 | printf("%s ",des_options()); |
d02b48c6 | 1441 | #endif |
cf1b7d96 | 1442 | #ifndef OPENSSL_NO_IDEA |
0e211563 | 1443 | printf("%s ",idea_options()); |
d02b48c6 | 1444 | #endif |
cf1b7d96 | 1445 | #ifndef OPENSSL_NO_BF |
0e211563 | 1446 | printf("%s ",BF_options()); |
d02b48c6 | 1447 | #endif |
0e211563 BL |
1448 | fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS)); |
1449 | printf("available timing options: "); | |
7876e448 | 1450 | #ifdef TIMES |
0e211563 | 1451 | printf("TIMES "); |
7876e448 RL |
1452 | #endif |
1453 | #ifdef TIMEB | |
0e211563 | 1454 | printf("TIMEB "); |
7876e448 RL |
1455 | #endif |
1456 | #ifdef USE_TOD | |
0e211563 | 1457 | printf("USE_TOD "); |
7876e448 RL |
1458 | #endif |
1459 | #ifdef HZ | |
1460 | #define as_string(s) (#s) | |
0e211563 | 1461 | printf("HZ=%g", HZ); |
a4a8f7b3 | 1462 | # ifdef _SC_CLK_TCK |
0e211563 | 1463 | printf(" [sysconf value]"); |
a4a8f7b3 | 1464 | # endif |
7876e448 | 1465 | #endif |
0e211563 BL |
1466 | printf("\n"); |
1467 | printf("timing function used: %s%s%s%s%s%s%s\n", | |
1468 | (ftime_used ? "ftime" : ""), | |
1469 | (ftime_used + times_used > 1 ? "," : ""), | |
1470 | (times_used ? "times" : ""), | |
1471 | (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""), | |
1472 | (gettimeofday_used ? "gettimeofday" : ""), | |
1473 | (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""), | |
1474 | (getrusage_used ? "getrusage" : "")); | |
1475 | } | |
d02b48c6 RE |
1476 | |
1477 | if (pr_header) | |
1478 | { | |
0e211563 BL |
1479 | if(mr) |
1480 | fprintf(stdout,"+H"); | |
1481 | else | |
1482 | { | |
1483 | fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); | |
1484 | fprintf(stdout,"type "); | |
1485 | } | |
d02b48c6 | 1486 | for (j=0; j<SIZE_NUM; j++) |
0e211563 | 1487 | fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]); |
d02b48c6 RE |
1488 | fprintf(stdout,"\n"); |
1489 | } | |
1490 | ||
1491 | for (k=0; k<ALGOR_NUM; k++) | |
1492 | { | |
1493 | if (!doit[k]) continue; | |
0e211563 BL |
1494 | if(mr) |
1495 | fprintf(stdout,"+F:%d:%s",k,names[k]); | |
1496 | else | |
1497 | fprintf(stdout,"%-13s",names[k]); | |
d02b48c6 RE |
1498 | for (j=0; j<SIZE_NUM; j++) |
1499 | { | |
0e211563 | 1500 | if (results[k][j] > 10000 && !mr) |
d02b48c6 RE |
1501 | fprintf(stdout," %11.2fk",results[k][j]/1e3); |
1502 | else | |
0e211563 | 1503 | fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]); |
d02b48c6 RE |
1504 | } |
1505 | fprintf(stdout,"\n"); | |
1506 | } | |
cf1b7d96 | 1507 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1508 | j=1; |
1509 | for (k=0; k<RSA_NUM; k++) | |
1510 | { | |
1511 | if (!rsa_doit[k]) continue; | |
0e211563 | 1512 | if (j && !mr) |
58964a49 RE |
1513 | { |
1514 | printf("%18ssign verify sign/s verify/s\n"," "); | |
1515 | j=0; | |
1516 | } | |
0e211563 BL |
1517 | if(mr) |
1518 | fprintf(stdout,"+F2:%u:%u:%f:%f\n", | |
1519 | k,rsa_bits[k],rsa_results[k][0], | |
1520 | rsa_results[k][1]); | |
1521 | else | |
1522 | fprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n", | |
1523 | rsa_bits[k],rsa_results[k][0],rsa_results[k][1], | |
1524 | 1.0/rsa_results[k][0],1.0/rsa_results[k][1]); | |
d02b48c6 RE |
1525 | } |
1526 | #endif | |
cf1b7d96 | 1527 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
1528 | j=1; |
1529 | for (k=0; k<DSA_NUM; k++) | |
1530 | { | |
1531 | if (!dsa_doit[k]) continue; | |
0e211563 BL |
1532 | if (j && !mr) |
1533 | { | |
58964a49 RE |
1534 | printf("%18ssign verify sign/s verify/s\n"," "); |
1535 | j=0; | |
1536 | } | |
0e211563 BL |
1537 | if(mr) |
1538 | fprintf(stdout,"+F3:%u:%u:%f:%f\n", | |
1539 | k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]); | |
1540 | else | |
1541 | fprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n", | |
1542 | dsa_bits[k],dsa_results[k][0],dsa_results[k][1], | |
1543 | 1.0/dsa_results[k][0],1.0/dsa_results[k][1]); | |
d02b48c6 RE |
1544 | } |
1545 | #endif | |
18c77bf2 | 1546 | mret=0; |
d02b48c6 | 1547 | end: |
5270e702 | 1548 | ERR_print_errors(bio_err); |
26a3a48d RL |
1549 | if (buf != NULL) OPENSSL_free(buf); |
1550 | if (buf2 != NULL) OPENSSL_free(buf2); | |
cf1b7d96 | 1551 | #ifndef OPENSSL_NO_RSA |
d02b48c6 RE |
1552 | for (i=0; i<RSA_NUM; i++) |
1553 | if (rsa_key[i] != NULL) | |
1554 | RSA_free(rsa_key[i]); | |
1555 | #endif | |
cf1b7d96 | 1556 | #ifndef OPENSSL_NO_DSA |
d02b48c6 RE |
1557 | for (i=0; i<DSA_NUM; i++) |
1558 | if (dsa_key[i] != NULL) | |
1559 | DSA_free(dsa_key[i]); | |
1560 | #endif | |
c04f8cf4 | 1561 | apps_shutdown(); |
18c77bf2 | 1562 | EXIT(mret); |
d02b48c6 RE |
1563 | } |
1564 | ||
646d5695 | 1565 | static void print_message(const char *s, long num, int length) |
d02b48c6 RE |
1566 | { |
1567 | #ifdef SIGALRM | |
0e211563 BL |
1568 | BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n" |
1569 | : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length); | |
d58d092b | 1570 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
1571 | alarm(SECONDS); |
1572 | #else | |
0e211563 BL |
1573 | BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n" |
1574 | : "Doing %s %ld times on %d size blocks: ",s,num,length); | |
d58d092b | 1575 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
1576 | #endif |
1577 | #ifdef LINT | |
1578 | num=num; | |
1579 | #endif | |
1580 | } | |
1581 | ||
6b691a5c UM |
1582 | static void pkey_print_message(char *str, char *str2, long num, int bits, |
1583 | int tm) | |
d02b48c6 RE |
1584 | { |
1585 | #ifdef SIGALRM | |
0e211563 BL |
1586 | BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n" |
1587 | : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm); | |
d58d092b | 1588 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
1589 | alarm(RSA_SECONDS); |
1590 | #else | |
0e211563 BL |
1591 | BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n" |
1592 | : "Doing %ld %d bit %s %s's: ",num,bits,str,str2); | |
d58d092b | 1593 | (void)BIO_flush(bio_err); |
d02b48c6 RE |
1594 | #endif |
1595 | #ifdef LINT | |
1596 | num=num; | |
1597 | #endif | |
1598 | } | |
58964a49 | 1599 | |
0e211563 BL |
1600 | static void print_result(int alg,int run_no,int count,double time_used) |
1601 | { | |
1602 | BIO_printf(bio_err,mr ? "+R:%ld:%s:%f\n" | |
1603 | : "%ld %s's in %.2fs\n",count,names[alg],time_used); | |
1604 | results[alg][run_no]=((double)count)/time_used*lengths[run_no]; | |
1605 | } | |
1606 | ||
1607 | static char *sstrsep(char **string, const char *delim) | |
1608 | { | |
1609 | char isdelim[256]; | |
1610 | char *token = *string; | |
1611 | ||
1612 | if (**string == 0) | |
1613 | return NULL; | |
1614 | ||
1615 | memset(isdelim, 0, 256); | |
1616 | isdelim[0] = 1; | |
1617 | ||
1618 | while (*delim) | |
1619 | { | |
1620 | isdelim[(unsigned char)(*delim)] = 1; | |
1621 | delim++; | |
1622 | } | |
1623 | ||
1624 | while (!isdelim[(unsigned char)(**string)]) | |
1625 | { | |
1626 | (*string)++; | |
1627 | } | |
1628 | ||
1629 | if (**string) | |
1630 | { | |
1631 | **string = 0; | |
1632 | (*string)++; | |
1633 | } | |
1634 | ||
1635 | return token; | |
1636 | } | |
1637 | ||
1638 | static int do_multi(int multi) | |
1639 | { | |
1640 | int n; | |
1641 | int fd[2]; | |
1642 | int *fds; | |
1643 | static char sep[]=":"; | |
1644 | ||
1645 | fds=malloc(multi*sizeof *fds); | |
1646 | for(n=0 ; n < multi ; ++n) | |
1647 | { | |
1648 | pipe(fd); | |
1649 | if(fork()) | |
1650 | { | |
1651 | close(fd[1]); | |
1652 | fds[n]=fd[0]; | |
1653 | } | |
1654 | else | |
1655 | { | |
1656 | close(fd[0]); | |
1657 | close(1); | |
1658 | dup(fd[1]); | |
1659 | close(fd[1]); | |
1660 | mr=1; | |
1661 | usertime=0; | |
1662 | return 0; | |
1663 | } | |
1664 | printf("Forked child %d\n",n); | |
1665 | } | |
1666 | ||
1667 | /* for now, assume the pipe is long enough to take all the output */ | |
1668 | for(n=0 ; n < multi ; ++n) | |
1669 | { | |
1670 | FILE *f; | |
1671 | char buf[1024]; | |
1672 | char *p; | |
1673 | ||
1674 | f=fdopen(fds[n],"r"); | |
1675 | while(fgets(buf,sizeof buf,f)) | |
1676 | { | |
1677 | p=strchr(buf,'\n'); | |
1678 | if(p) | |
1679 | *p='\0'; | |
1680 | if(buf[0] != '+') | |
1681 | { | |
1682 | fprintf(stderr,"Don't understand line '%s' from child %d\n", | |
1683 | buf,n); | |
1684 | continue; | |
1685 | } | |
1686 | printf("Got: %s from %d\n",buf,n); | |
1687 | if(!strncmp(buf,"+F:",3)) | |
1688 | { | |
1689 | int alg; | |
1690 | int j; | |
1691 | ||
1692 | p=buf+3; | |
1693 | alg=atoi(sstrsep(&p,sep)); | |
1694 | sstrsep(&p,sep); | |
1695 | for(j=0 ; j < SIZE_NUM ; ++j) | |
1696 | results[alg][j]+=atof(sstrsep(&p,sep)); | |
1697 | } | |
1698 | else if(!strncmp(buf,"+F2:",4)) | |
1699 | { | |
1700 | int k; | |
1701 | double d; | |
1702 | ||
1703 | p=buf+4; | |
1704 | k=atoi(sstrsep(&p,sep)); | |
1705 | sstrsep(&p,sep); | |
1706 | ||
1707 | d=atof(sstrsep(&p,sep)); | |
1708 | if(n) | |
1709 | rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); | |
1710 | else | |
1711 | rsa_results[k][0]=d; | |
1712 | ||
1713 | d=atof(sstrsep(&p,sep)); | |
1714 | if(n) | |
1715 | rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); | |
1716 | else | |
1717 | rsa_results[k][1]=d; | |
1718 | } | |
1719 | else if(!strncmp(buf,"+F2:",4)) | |
1720 | { | |
1721 | int k; | |
1722 | double d; | |
1723 | ||
1724 | p=buf+4; | |
1725 | k=atoi(sstrsep(&p,sep)); | |
1726 | sstrsep(&p,sep); | |
1727 | ||
1728 | d=atof(sstrsep(&p,sep)); | |
1729 | if(n) | |
1730 | rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); | |
1731 | else | |
1732 | rsa_results[k][0]=d; | |
1733 | ||
1734 | d=atof(sstrsep(&p,sep)); | |
1735 | if(n) | |
1736 | rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); | |
1737 | else | |
1738 | rsa_results[k][1]=d; | |
1739 | } | |
1740 | else if(!strncmp(buf,"+F3:",4)) | |
1741 | { | |
1742 | int k; | |
1743 | double d; | |
1744 | ||
1745 | p=buf+4; | |
1746 | k=atoi(sstrsep(&p,sep)); | |
1747 | sstrsep(&p,sep); | |
1748 | ||
1749 | d=atof(sstrsep(&p,sep)); | |
1750 | if(n) | |
1751 | dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); | |
1752 | else | |
1753 | dsa_results[k][0]=d; | |
1754 | ||
1755 | d=atof(sstrsep(&p,sep)); | |
1756 | if(n) | |
1757 | dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); | |
1758 | else | |
1759 | dsa_results[k][1]=d; | |
1760 | } | |
1761 | else if(!strncmp(buf,"+H:",3)) | |
1762 | { | |
1763 | } | |
1764 | else | |
1765 | fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); | |
1766 | } | |
1767 | } | |
1768 | return 1; | |
1769 | } | |
1770 |