Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: openssl/apps/speed.c

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

Powered by Google App Engine
This is Rietveld 408576698