Annotation of src/usr.bin/openssl/speed.c, Revision 1.10
1.10 ! deraadt 1: /* $OpenBSD: speed.c,v 1.9 2015/08/22 16:36:05 jsing Exp $ */
1.1 jsing 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: #define SECONDS 3
77: #define RSA_SECONDS 10
78: #define DSA_SECONDS 10
79: #define ECDSA_SECONDS 10
80: #define ECDH_SECONDS 10
81:
82: /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
83: /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
84:
85: #include <math.h>
86: #include <signal.h>
87: #include <stdio.h>
88: #include <stdlib.h>
89: #include <limits.h>
90: #include <string.h>
91: #include <unistd.h>
92:
93: #include "apps.h"
94:
95: #include <openssl/bn.h>
96: #include <openssl/crypto.h>
97: #include <openssl/err.h>
98: #include <openssl/evp.h>
99: #include <openssl/modes.h>
100: #include <openssl/objects.h>
101: #include <openssl/x509.h>
102:
103: #ifndef OPENSSL_NO_AES
104: #include <openssl/aes.h>
105: #endif
106: #ifndef OPENSSL_NO_BF
107: #include <openssl/blowfish.h>
108: #endif
109: #ifndef OPENSSL_NO_CAST
110: #include <openssl/cast.h>
111: #endif
112: #ifndef OPENSSL_NO_CAMELLIA
113: #include <openssl/camellia.h>
114: #endif
115: #ifndef OPENSSL_NO_DES
116: #include <openssl/des.h>
117: #endif
118: #include <openssl/dsa.h>
119: #include <openssl/ecdh.h>
120: #include <openssl/ecdsa.h>
121: #ifndef OPENSSL_NO_HMAC
122: #include <openssl/hmac.h>
123: #endif
124: #ifndef OPENSSL_NO_IDEA
125: #include <openssl/idea.h>
126: #endif
127: #ifndef OPENSSL_NO_MD4
128: #include <openssl/md4.h>
129: #endif
130: #ifndef OPENSSL_NO_MD5
131: #include <openssl/md5.h>
132: #endif
133: #ifndef OPENSSL_NO_RC2
134: #include <openssl/rc2.h>
135: #endif
136: #ifndef OPENSSL_NO_RC4
137: #include <openssl/rc4.h>
138: #endif
139: #ifndef OPENSSL_NO_RC5
140: #include <openssl/rc5.h>
141: #endif
142: #include <openssl/rsa.h>
143: #ifndef OPENSSL_NO_RIPEMD
144: #include <openssl/ripemd.h>
145: #endif
146: #ifndef OPENSSL_NO_SHA
147: #include <openssl/sha.h>
148: #endif
149: #ifndef OPENSSL_NO_WHIRLPOOL
150: #include <openssl/whrlpool.h>
151: #endif
152:
153: #include "./testdsa.h"
154: #include "./testrsa.h"
155:
1.10 ! deraadt 156: #define BUFSIZE (1024*8+1)
1.1 jsing 157: int run = 0;
158:
159: static int mr = 0;
160: static int usertime = 1;
161:
162: static double Time_F(int s);
163: static void print_message(const char *s, long num, int length);
164: static void
165: pkey_print_message(const char *str, const char *str2,
166: long num, int bits, int sec);
167: static void print_result(int alg, int run_no, int count, double time_used);
168: static int do_multi(int multi);
169:
170: #define ALGOR_NUM 30
171: #define SIZE_NUM 5
172: #define RSA_NUM 4
173: #define DSA_NUM 3
174:
175: #define EC_NUM 16
176: #define MAX_ECDH_SIZE 256
177:
178: static const char *names[ALGOR_NUM] = {
1.7 miod 179: "md2", NULL /* was mdc2 */, "md4", "md5", "hmac(md5)", "sha1", "rmd160",
180: "rc4", "des cbc", "des ede3", "idea cbc", "seed cbc",
1.1 jsing 181: "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
182: "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
183: "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
184: "evp", "sha256", "sha512", "whirlpool",
1.7 miod 185: "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash" };
1.1 jsing 186: static double results[ALGOR_NUM][SIZE_NUM];
187: static int lengths[SIZE_NUM] = {16, 64, 256, 1024, 8 * 1024};
188: static double rsa_results[RSA_NUM][2];
189: static double dsa_results[DSA_NUM][2];
190: static double ecdsa_results[EC_NUM][2];
191: static double ecdh_results[EC_NUM][1];
192:
193: static void sig_done(int sig);
194:
195: static void
196: sig_done(int sig)
197: {
198: signal(SIGALRM, sig_done);
199: run = 0;
200: }
201:
202: #define START 0
203: #define STOP 1
204:
205:
206: static double
207: Time_F(int s)
208: {
209: return app_tminterval(s, usertime);
210: }
211:
212:
213: static const int KDF1_SHA1_len = 20;
214: static void *
215: KDF1_SHA1(const void *in, size_t inlen, void *out, size_t * outlen)
216: {
217: #ifndef OPENSSL_NO_SHA
218: if (*outlen < SHA_DIGEST_LENGTH)
219: return NULL;
220: else
221: *outlen = SHA_DIGEST_LENGTH;
222: return SHA1(in, inlen, out);
223: #else
224: return NULL;
225: #endif /* OPENSSL_NO_SHA */
226: }
227:
228: int
229: speed_main(int argc, char **argv)
230: {
231: unsigned char *buf = NULL, *buf2 = NULL;
232: int mret = 1;
233: long count = 0, save_count = 0;
234: int i, j, k;
235: long rsa_count;
236: unsigned rsa_num;
237: unsigned char md[EVP_MAX_MD_SIZE];
238: #ifndef OPENSSL_NO_MD4
239: unsigned char md4[MD4_DIGEST_LENGTH];
240: #endif
241: #ifndef OPENSSL_NO_MD5
242: unsigned char md5[MD5_DIGEST_LENGTH];
243: unsigned char hmac[MD5_DIGEST_LENGTH];
244: #endif
245: #ifndef OPENSSL_NO_SHA
246: unsigned char sha[SHA_DIGEST_LENGTH];
247: #ifndef OPENSSL_NO_SHA256
248: unsigned char sha256[SHA256_DIGEST_LENGTH];
249: #endif
250: #ifndef OPENSSL_NO_SHA512
251: unsigned char sha512[SHA512_DIGEST_LENGTH];
252: #endif
253: #endif
254: #ifndef OPENSSL_NO_WHIRLPOOL
255: unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
256: #endif
257: #ifndef OPENSSL_NO_RIPEMD
258: unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
259: #endif
260: #ifndef OPENSSL_NO_RC4
261: RC4_KEY rc4_ks;
262: #endif
263: #ifndef OPENSSL_NO_RC5
264: RC5_32_KEY rc5_ks;
265: #endif
266: #ifndef OPENSSL_NO_RC2
267: RC2_KEY rc2_ks;
268: #endif
269: #ifndef OPENSSL_NO_IDEA
270: IDEA_KEY_SCHEDULE idea_ks;
271: #endif
272: #ifndef OPENSSL_NO_BF
273: BF_KEY bf_ks;
274: #endif
275: #ifndef OPENSSL_NO_CAST
276: CAST_KEY cast_ks;
277: #endif
278: static const unsigned char key16[16] =
279: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
280: 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
281: #ifndef OPENSSL_NO_AES
282: static const unsigned char key24[24] =
283: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
284: 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
285: 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
286: static const unsigned char key32[32] =
287: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
288: 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
289: 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
290: 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
291: #endif
292: #ifndef OPENSSL_NO_CAMELLIA
293: static const unsigned char ckey24[24] =
294: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
295: 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
296: 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
297: static const unsigned char ckey32[32] =
298: {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
299: 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
300: 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
301: 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56};
302: #endif
303: #ifndef OPENSSL_NO_AES
304: #define MAX_BLOCK_SIZE 128
305: #else
306: #define MAX_BLOCK_SIZE 64
307: #endif
308: unsigned char DES_iv[8];
309: unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
310: #ifndef OPENSSL_NO_DES
311: static DES_cblock key = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
312: static DES_cblock key2 = {0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12};
313: static DES_cblock key3 = {0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34};
314: DES_key_schedule sch;
315: DES_key_schedule sch2;
316: DES_key_schedule sch3;
317: #endif
318: #ifndef OPENSSL_NO_AES
319: AES_KEY aes_ks1, aes_ks2, aes_ks3;
320: #endif
321: #ifndef OPENSSL_NO_CAMELLIA
322: CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
323: #endif
324: #define D_MD2 0
325: #define D_MD4 2
326: #define D_MD5 3
327: #define D_HMAC 4
328: #define D_SHA1 5
329: #define D_RMD160 6
330: #define D_RC4 7
331: #define D_CBC_DES 8
332: #define D_EDE3_DES 9
333: #define D_CBC_IDEA 10
334: #define D_CBC_SEED 11
335: #define D_CBC_RC2 12
336: #define D_CBC_RC5 13
337: #define D_CBC_BF 14
338: #define D_CBC_CAST 15
339: #define D_CBC_128_AES 16
340: #define D_CBC_192_AES 17
341: #define D_CBC_256_AES 18
342: #define D_CBC_128_CML 19
343: #define D_CBC_192_CML 20
344: #define D_CBC_256_CML 21
345: #define D_EVP 22
346: #define D_SHA256 23
347: #define D_SHA512 24
348: #define D_WHIRLPOOL 25
349: #define D_IGE_128_AES 26
350: #define D_IGE_192_AES 27
351: #define D_IGE_256_AES 28
352: #define D_GHASH 29
353: double d = 0.0;
354: long c[ALGOR_NUM][SIZE_NUM];
355: #define R_DSA_512 0
356: #define R_DSA_1024 1
357: #define R_DSA_2048 2
358: #define R_RSA_512 0
359: #define R_RSA_1024 1
360: #define R_RSA_2048 2
361: #define R_RSA_4096 3
362:
363: #define R_EC_P160 0
364: #define R_EC_P192 1
365: #define R_EC_P224 2
366: #define R_EC_P256 3
367: #define R_EC_P384 4
368: #define R_EC_P521 5
369: #define R_EC_K163 6
370: #define R_EC_K233 7
371: #define R_EC_K283 8
372: #define R_EC_K409 9
373: #define R_EC_K571 10
374: #define R_EC_B163 11
375: #define R_EC_B233 12
376: #define R_EC_B283 13
377: #define R_EC_B409 14
378: #define R_EC_B571 15
379:
380: RSA *rsa_key[RSA_NUM];
381: long rsa_c[RSA_NUM][2];
382: static unsigned int rsa_bits[RSA_NUM] = {512, 1024, 2048, 4096};
383: static unsigned char *rsa_data[RSA_NUM] =
384: {test512, test1024, test2048, test4096};
385: static int rsa_data_length[RSA_NUM] = {
386: sizeof(test512), sizeof(test1024),
387: sizeof(test2048), sizeof(test4096)};
388: DSA *dsa_key[DSA_NUM];
389: long dsa_c[DSA_NUM][2];
390: static unsigned int dsa_bits[DSA_NUM] = {512, 1024, 2048};
391: #ifndef OPENSSL_NO_EC
392: /*
393: * We only test over the following curves as they are representative,
394: * To add tests over more curves, simply add the curve NID and curve
395: * name to the following arrays and increase the EC_NUM value
396: * accordingly.
397: */
398: static unsigned int test_curves[EC_NUM] =
399: {
400: /* Prime Curves */
401: NID_secp160r1,
402: NID_X9_62_prime192v1,
403: NID_secp224r1,
404: NID_X9_62_prime256v1,
405: NID_secp384r1,
406: NID_secp521r1,
407: /* Binary Curves */
408: NID_sect163k1,
409: NID_sect233k1,
410: NID_sect283k1,
411: NID_sect409k1,
412: NID_sect571k1,
413: NID_sect163r2,
414: NID_sect233r1,
415: NID_sect283r1,
416: NID_sect409r1,
417: NID_sect571r1
418: };
419: static const char *test_curves_names[EC_NUM] =
420: {
421: /* Prime Curves */
422: "secp160r1",
423: "nistp192",
424: "nistp224",
425: "nistp256",
426: "nistp384",
427: "nistp521",
428: /* Binary Curves */
429: "nistk163",
430: "nistk233",
431: "nistk283",
432: "nistk409",
433: "nistk571",
434: "nistb163",
435: "nistb233",
436: "nistb283",
437: "nistb409",
438: "nistb571"
439: };
440: static int test_curves_bits[EC_NUM] =
441: {
442: 160, 192, 224, 256, 384, 521,
443: 163, 233, 283, 409, 571,
444: 163, 233, 283, 409, 571
445: };
446:
447: #endif
448:
449: unsigned char ecdsasig[256];
450: unsigned int ecdsasiglen;
451: EC_KEY *ecdsa[EC_NUM];
452: long ecdsa_c[EC_NUM][2];
453:
454: EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
455: unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
456: int secret_size_a, secret_size_b;
457: int ecdh_checks = 0;
458: int secret_idx = 0;
459: long ecdh_c[EC_NUM][2];
460:
461: int rsa_doit[RSA_NUM];
462: int dsa_doit[DSA_NUM];
463: int ecdsa_doit[EC_NUM];
464: int ecdh_doit[EC_NUM];
465: int doit[ALGOR_NUM];
466: int pr_header = 0;
467: const EVP_CIPHER *evp_cipher = NULL;
468: const EVP_MD *evp_md = NULL;
469: int decrypt = 0;
470: int multi = 0;
471: const char *errstr = NULL;
472:
473: usertime = -1;
474:
475: memset(results, 0, sizeof(results));
476: memset(dsa_key, 0, sizeof(dsa_key));
477: for (i = 0; i < EC_NUM; i++)
478: ecdsa[i] = NULL;
479: for (i = 0; i < EC_NUM; i++) {
480: ecdh_a[i] = NULL;
481: ecdh_b[i] = NULL;
482: }
483:
484: memset(rsa_key, 0, sizeof(rsa_key));
485: for (i = 0; i < RSA_NUM; i++)
486: rsa_key[i] = NULL;
487:
1.10 ! deraadt 488: if ((buf = malloc(BUFSIZE)) == NULL) {
1.1 jsing 489: BIO_printf(bio_err, "out of memory\n");
490: goto end;
491: }
1.10 ! deraadt 492: if ((buf2 = malloc(BUFSIZE)) == NULL) {
1.1 jsing 493: BIO_printf(bio_err, "out of memory\n");
494: goto end;
495: }
496: memset(c, 0, sizeof(c));
497: memset(DES_iv, 0, sizeof(DES_iv));
498: memset(iv, 0, sizeof(iv));
499:
500: for (i = 0; i < ALGOR_NUM; i++)
501: doit[i] = 0;
502: for (i = 0; i < RSA_NUM; i++)
503: rsa_doit[i] = 0;
504: for (i = 0; i < DSA_NUM; i++)
505: dsa_doit[i] = 0;
506: for (i = 0; i < EC_NUM; i++)
507: ecdsa_doit[i] = 0;
508: for (i = 0; i < EC_NUM; i++)
509: ecdh_doit[i] = 0;
510:
511:
512: j = 0;
513: argc--;
514: argv++;
515: while (argc) {
516: if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
517: usertime = 0;
518: j--; /* Otherwise, -elapsed gets confused with an
519: * algorithm. */
520: } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
521: argc--;
522: argv++;
523: if (argc == 0) {
524: BIO_printf(bio_err, "no EVP given\n");
525: goto end;
526: }
527: evp_cipher = EVP_get_cipherbyname(*argv);
528: if (!evp_cipher) {
529: evp_md = EVP_get_digestbyname(*argv);
530: }
531: if (!evp_cipher && !evp_md) {
532: BIO_printf(bio_err, "%s is an unknown cipher or digest\n", *argv);
533: goto end;
534: }
535: doit[D_EVP] = 1;
536: } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
537: decrypt = 1;
538: j--; /* Otherwise, -elapsed gets confused with an
539: * algorithm. */
540: }
541: #ifndef OPENSSL_NO_ENGINE
542: else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
543: argc--;
544: argv++;
545: if (argc == 0) {
546: BIO_printf(bio_err, "no engine given\n");
547: goto end;
548: }
549: setup_engine(bio_err, *argv, 0);
550: /*
551: * j will be increased again further down. We just
552: * don't want speed to confuse an engine with an
553: * algorithm, especially when none is given (which
554: * means all of them should be run)
555: */
556: j--;
557: }
558: #endif
559: else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
560: argc--;
561: argv++;
562: if (argc == 0) {
563: BIO_printf(bio_err, "no multi count given\n");
564: goto end;
565: }
566: multi = strtonum(argv[0], 1, INT_MAX, &errstr);
567: if (errstr) {
568: BIO_printf(bio_err, "bad multi count: %s", errstr);
569: goto end;
570: }
571: j--; /* Otherwise, -mr gets confused with an
572: * algorithm. */
573: }
574: else if (argc > 0 && !strcmp(*argv, "-mr")) {
575: mr = 1;
576: j--; /* Otherwise, -mr gets confused with an
577: * algorithm. */
578: } else
579: #ifndef OPENSSL_NO_MD4
580: if (strcmp(*argv, "md4") == 0)
581: doit[D_MD4] = 1;
582: else
583: #endif
584: #ifndef OPENSSL_NO_MD5
585: if (strcmp(*argv, "md5") == 0)
586: doit[D_MD5] = 1;
587: else
588: #endif
589: #ifndef OPENSSL_NO_MD5
590: if (strcmp(*argv, "hmac") == 0)
591: doit[D_HMAC] = 1;
592: else
593: #endif
594: #ifndef OPENSSL_NO_SHA
595: if (strcmp(*argv, "sha1") == 0)
596: doit[D_SHA1] = 1;
597: else if (strcmp(*argv, "sha") == 0)
598: doit[D_SHA1] = 1,
599: doit[D_SHA256] = 1,
600: doit[D_SHA512] = 1;
601: else
602: #ifndef OPENSSL_NO_SHA256
603: if (strcmp(*argv, "sha256") == 0)
604: doit[D_SHA256] = 1;
605: else
606: #endif
607: #ifndef OPENSSL_NO_SHA512
608: if (strcmp(*argv, "sha512") == 0)
609: doit[D_SHA512] = 1;
610: else
611: #endif
612: #endif
613: #ifndef OPENSSL_NO_WHIRLPOOL
614: if (strcmp(*argv, "whirlpool") == 0)
615: doit[D_WHIRLPOOL] = 1;
616: else
617: #endif
618: #ifndef OPENSSL_NO_RIPEMD
619: if (strcmp(*argv, "ripemd") == 0)
620: doit[D_RMD160] = 1;
621: else if (strcmp(*argv, "rmd160") == 0)
622: doit[D_RMD160] = 1;
623: else if (strcmp(*argv, "ripemd160") == 0)
624: doit[D_RMD160] = 1;
625: else
626: #endif
627: #ifndef OPENSSL_NO_RC4
628: if (strcmp(*argv, "rc4") == 0)
629: doit[D_RC4] = 1;
630: else
631: #endif
632: #ifndef OPENSSL_NO_DES
633: if (strcmp(*argv, "des-cbc") == 0)
634: doit[D_CBC_DES] = 1;
635: else if (strcmp(*argv, "des-ede3") == 0)
636: doit[D_EDE3_DES] = 1;
637: else
638: #endif
639: #ifndef OPENSSL_NO_AES
640: if (strcmp(*argv, "aes-128-cbc") == 0)
641: doit[D_CBC_128_AES] = 1;
642: else if (strcmp(*argv, "aes-192-cbc") == 0)
643: doit[D_CBC_192_AES] = 1;
644: else if (strcmp(*argv, "aes-256-cbc") == 0)
645: doit[D_CBC_256_AES] = 1;
646: else if (strcmp(*argv, "aes-128-ige") == 0)
647: doit[D_IGE_128_AES] = 1;
648: else if (strcmp(*argv, "aes-192-ige") == 0)
649: doit[D_IGE_192_AES] = 1;
650: else if (strcmp(*argv, "aes-256-ige") == 0)
651: doit[D_IGE_256_AES] = 1;
652: else
653: #endif
654: #ifndef OPENSSL_NO_CAMELLIA
655: if (strcmp(*argv, "camellia-128-cbc") == 0)
656: doit[D_CBC_128_CML] = 1;
657: else if (strcmp(*argv, "camellia-192-cbc") == 0)
658: doit[D_CBC_192_CML] = 1;
659: else if (strcmp(*argv, "camellia-256-cbc") == 0)
660: doit[D_CBC_256_CML] = 1;
661: else
662: #endif
663: #ifndef RSA_NULL
664: if (strcmp(*argv, "openssl") == 0) {
665: RSA_set_default_method(RSA_PKCS1_SSLeay());
666: j--;
667: } else
668: #endif
669: if (strcmp(*argv, "dsa512") == 0)
670: dsa_doit[R_DSA_512] = 2;
671: else if (strcmp(*argv, "dsa1024") == 0)
672: dsa_doit[R_DSA_1024] = 2;
673: else if (strcmp(*argv, "dsa2048") == 0)
674: dsa_doit[R_DSA_2048] = 2;
675: else if (strcmp(*argv, "rsa512") == 0)
676: rsa_doit[R_RSA_512] = 2;
677: else if (strcmp(*argv, "rsa1024") == 0)
678: rsa_doit[R_RSA_1024] = 2;
679: else if (strcmp(*argv, "rsa2048") == 0)
680: rsa_doit[R_RSA_2048] = 2;
681: else if (strcmp(*argv, "rsa4096") == 0)
682: rsa_doit[R_RSA_4096] = 2;
683: else
684: #ifndef OPENSSL_NO_RC2
685: if (strcmp(*argv, "rc2-cbc") == 0)
686: doit[D_CBC_RC2] = 1;
687: else if (strcmp(*argv, "rc2") == 0)
688: doit[D_CBC_RC2] = 1;
689: else
690: #endif
691: #ifndef OPENSSL_NO_RC5
692: if (strcmp(*argv, "rc5-cbc") == 0)
693: doit[D_CBC_RC5] = 1;
694: else if (strcmp(*argv, "rc5") == 0)
695: doit[D_CBC_RC5] = 1;
696: else
697: #endif
698: #ifndef OPENSSL_NO_IDEA
699: if (strcmp(*argv, "idea-cbc") == 0)
700: doit[D_CBC_IDEA] = 1;
701: else if (strcmp(*argv, "idea") == 0)
702: doit[D_CBC_IDEA] = 1;
703: else
704: #endif
705: #ifndef OPENSSL_NO_BF
706: if (strcmp(*argv, "bf-cbc") == 0)
707: doit[D_CBC_BF] = 1;
708: else if (strcmp(*argv, "blowfish") == 0)
709: doit[D_CBC_BF] = 1;
710: else if (strcmp(*argv, "bf") == 0)
711: doit[D_CBC_BF] = 1;
712: else
713: #endif
714: #ifndef OPENSSL_NO_CAST
715: if (strcmp(*argv, "cast-cbc") == 0)
716: doit[D_CBC_CAST] = 1;
717: else if (strcmp(*argv, "cast") == 0)
718: doit[D_CBC_CAST] = 1;
719: else if (strcmp(*argv, "cast5") == 0)
720: doit[D_CBC_CAST] = 1;
721: else
722: #endif
723: #ifndef OPENSSL_NO_DES
724: if (strcmp(*argv, "des") == 0) {
725: doit[D_CBC_DES] = 1;
726: doit[D_EDE3_DES] = 1;
727: } else
728: #endif
729: #ifndef OPENSSL_NO_AES
730: if (strcmp(*argv, "aes") == 0) {
731: doit[D_CBC_128_AES] = 1;
732: doit[D_CBC_192_AES] = 1;
733: doit[D_CBC_256_AES] = 1;
734: } else if (strcmp(*argv, "ghash") == 0) {
735: doit[D_GHASH] = 1;
736: } else
737: #endif
738: #ifndef OPENSSL_NO_CAMELLIA
739: if (strcmp(*argv, "camellia") == 0) {
740: doit[D_CBC_128_CML] = 1;
741: doit[D_CBC_192_CML] = 1;
742: doit[D_CBC_256_CML] = 1;
743: } else
744: #endif
745: if (strcmp(*argv, "rsa") == 0) {
746: rsa_doit[R_RSA_512] = 1;
747: rsa_doit[R_RSA_1024] = 1;
748: rsa_doit[R_RSA_2048] = 1;
749: rsa_doit[R_RSA_4096] = 1;
750: } else
751: if (strcmp(*argv, "dsa") == 0) {
752: dsa_doit[R_DSA_512] = 1;
753: dsa_doit[R_DSA_1024] = 1;
754: dsa_doit[R_DSA_2048] = 1;
755: } else
756: if (strcmp(*argv, "ecdsap160") == 0)
757: ecdsa_doit[R_EC_P160] = 2;
758: else if (strcmp(*argv, "ecdsap192") == 0)
759: ecdsa_doit[R_EC_P192] = 2;
760: else if (strcmp(*argv, "ecdsap224") == 0)
761: ecdsa_doit[R_EC_P224] = 2;
762: else if (strcmp(*argv, "ecdsap256") == 0)
763: ecdsa_doit[R_EC_P256] = 2;
764: else if (strcmp(*argv, "ecdsap384") == 0)
765: ecdsa_doit[R_EC_P384] = 2;
766: else if (strcmp(*argv, "ecdsap521") == 0)
767: ecdsa_doit[R_EC_P521] = 2;
768: else if (strcmp(*argv, "ecdsak163") == 0)
769: ecdsa_doit[R_EC_K163] = 2;
770: else if (strcmp(*argv, "ecdsak233") == 0)
771: ecdsa_doit[R_EC_K233] = 2;
772: else if (strcmp(*argv, "ecdsak283") == 0)
773: ecdsa_doit[R_EC_K283] = 2;
774: else if (strcmp(*argv, "ecdsak409") == 0)
775: ecdsa_doit[R_EC_K409] = 2;
776: else if (strcmp(*argv, "ecdsak571") == 0)
777: ecdsa_doit[R_EC_K571] = 2;
778: else if (strcmp(*argv, "ecdsab163") == 0)
779: ecdsa_doit[R_EC_B163] = 2;
780: else if (strcmp(*argv, "ecdsab233") == 0)
781: ecdsa_doit[R_EC_B233] = 2;
782: else if (strcmp(*argv, "ecdsab283") == 0)
783: ecdsa_doit[R_EC_B283] = 2;
784: else if (strcmp(*argv, "ecdsab409") == 0)
785: ecdsa_doit[R_EC_B409] = 2;
786: else if (strcmp(*argv, "ecdsab571") == 0)
787: ecdsa_doit[R_EC_B571] = 2;
788: else if (strcmp(*argv, "ecdsa") == 0) {
789: for (i = 0; i < EC_NUM; i++)
790: ecdsa_doit[i] = 1;
791: } else
792: if (strcmp(*argv, "ecdhp160") == 0)
793: ecdh_doit[R_EC_P160] = 2;
794: else if (strcmp(*argv, "ecdhp192") == 0)
795: ecdh_doit[R_EC_P192] = 2;
796: else if (strcmp(*argv, "ecdhp224") == 0)
797: ecdh_doit[R_EC_P224] = 2;
798: else if (strcmp(*argv, "ecdhp256") == 0)
799: ecdh_doit[R_EC_P256] = 2;
800: else if (strcmp(*argv, "ecdhp384") == 0)
801: ecdh_doit[R_EC_P384] = 2;
802: else if (strcmp(*argv, "ecdhp521") == 0)
803: ecdh_doit[R_EC_P521] = 2;
804: else if (strcmp(*argv, "ecdhk163") == 0)
805: ecdh_doit[R_EC_K163] = 2;
806: else if (strcmp(*argv, "ecdhk233") == 0)
807: ecdh_doit[R_EC_K233] = 2;
808: else if (strcmp(*argv, "ecdhk283") == 0)
809: ecdh_doit[R_EC_K283] = 2;
810: else if (strcmp(*argv, "ecdhk409") == 0)
811: ecdh_doit[R_EC_K409] = 2;
812: else if (strcmp(*argv, "ecdhk571") == 0)
813: ecdh_doit[R_EC_K571] = 2;
814: else if (strcmp(*argv, "ecdhb163") == 0)
815: ecdh_doit[R_EC_B163] = 2;
816: else if (strcmp(*argv, "ecdhb233") == 0)
817: ecdh_doit[R_EC_B233] = 2;
818: else if (strcmp(*argv, "ecdhb283") == 0)
819: ecdh_doit[R_EC_B283] = 2;
820: else if (strcmp(*argv, "ecdhb409") == 0)
821: ecdh_doit[R_EC_B409] = 2;
822: else if (strcmp(*argv, "ecdhb571") == 0)
823: ecdh_doit[R_EC_B571] = 2;
824: else if (strcmp(*argv, "ecdh") == 0) {
825: for (i = 0; i < EC_NUM; i++)
826: ecdh_doit[i] = 1;
827: } else
828: {
829: BIO_printf(bio_err, "Error: bad option or value\n");
830: BIO_printf(bio_err, "\n");
831: BIO_printf(bio_err, "Available values:\n");
832: #ifndef OPENSSL_NO_MD4
833: BIO_printf(bio_err, "md4 ");
834: #endif
835: #ifndef OPENSSL_NO_MD5
836: BIO_printf(bio_err, "md5 ");
837: #ifndef OPENSSL_NO_HMAC
838: BIO_printf(bio_err, "hmac ");
839: #endif
840: #endif
841: #ifndef OPENSSL_NO_SHA1
842: BIO_printf(bio_err, "sha1 ");
843: #endif
844: #ifndef OPENSSL_NO_SHA256
845: BIO_printf(bio_err, "sha256 ");
846: #endif
847: #ifndef OPENSSL_NO_SHA512
848: BIO_printf(bio_err, "sha512 ");
849: #endif
850: #ifndef OPENSSL_NO_WHIRLPOOL
851: BIO_printf(bio_err, "whirlpool");
852: #endif
853: #ifndef OPENSSL_NO_RIPEMD160
854: BIO_printf(bio_err, "rmd160");
855: #endif
1.6 doug 856: #if !defined(OPENSSL_NO_MD2) || \
1.1 jsing 857: !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
858: !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
859: !defined(OPENSSL_NO_WHIRLPOOL)
860: BIO_printf(bio_err, "\n");
861: #endif
862:
863: #ifndef OPENSSL_NO_IDEA
864: BIO_printf(bio_err, "idea-cbc ");
865: #endif
866: #ifndef OPENSSL_NO_RC2
867: BIO_printf(bio_err, "rc2-cbc ");
868: #endif
869: #ifndef OPENSSL_NO_RC5
870: BIO_printf(bio_err, "rc5-cbc ");
871: #endif
872: #ifndef OPENSSL_NO_BF
873: BIO_printf(bio_err, "bf-cbc");
874: #endif
875: #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
876: !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
877: BIO_printf(bio_err, "\n");
878: #endif
879: #ifndef OPENSSL_NO_DES
880: BIO_printf(bio_err, "des-cbc des-ede3 ");
881: #endif
882: #ifndef OPENSSL_NO_AES
883: BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
884: BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
885: #endif
886: #ifndef OPENSSL_NO_CAMELLIA
887: BIO_printf(bio_err, "\n");
888: BIO_printf(bio_err, "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
889: #endif
890: #ifndef OPENSSL_NO_RC4
891: BIO_printf(bio_err, "rc4");
892: #endif
893: BIO_printf(bio_err, "\n");
894:
895: BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
896:
897: BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
898: BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
899: BIO_printf(bio_err, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
900: BIO_printf(bio_err, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
901: BIO_printf(bio_err, "ecdsa\n");
902: BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
903: BIO_printf(bio_err, "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
904: BIO_printf(bio_err, "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
905: BIO_printf(bio_err, "ecdh\n");
906:
907: #ifndef OPENSSL_NO_IDEA
908: BIO_printf(bio_err, "idea ");
909: #endif
910: #ifndef OPENSSL_NO_RC2
911: BIO_printf(bio_err, "rc2 ");
912: #endif
913: #ifndef OPENSSL_NO_DES
914: BIO_printf(bio_err, "des ");
915: #endif
916: #ifndef OPENSSL_NO_AES
917: BIO_printf(bio_err, "aes ");
918: #endif
919: #ifndef OPENSSL_NO_CAMELLIA
920: BIO_printf(bio_err, "camellia ");
921: #endif
922: BIO_printf(bio_err, "rsa ");
923: #ifndef OPENSSL_NO_BF
924: BIO_printf(bio_err, "blowfish");
925: #endif
926: #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
927: !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
928: !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
929: !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
930: BIO_printf(bio_err, "\n");
931: #endif
932:
933: BIO_printf(bio_err, "\n");
934: BIO_printf(bio_err, "Available options:\n");
935: BIO_printf(bio_err, "-elapsed measure time in real time instead of CPU user time.\n");
936: #ifndef OPENSSL_NO_ENGINE
937: BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n");
938: #endif
939: BIO_printf(bio_err, "-evp e use EVP e.\n");
940: BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n");
941: BIO_printf(bio_err, "-mr produce machine readable output.\n");
942: BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n");
943: goto end;
944: }
945: argc--;
946: argv++;
947: j++;
948: }
949:
950: if (multi && do_multi(multi))
951: goto show_res;
952:
953: if (j == 0) {
954: for (i = 0; i < ALGOR_NUM; i++) {
955: if (i != D_EVP)
956: doit[i] = 1;
957: }
958: for (i = 0; i < RSA_NUM; i++)
959: rsa_doit[i] = 1;
960: for (i = 0; i < DSA_NUM; i++)
961: dsa_doit[i] = 1;
962: for (i = 0; i < EC_NUM; i++)
963: ecdsa_doit[i] = 1;
964: for (i = 0; i < EC_NUM; i++)
965: ecdh_doit[i] = 1;
966: }
967: for (i = 0; i < ALGOR_NUM; i++)
968: if (doit[i])
969: pr_header++;
970:
971: if (usertime == 0 && !mr)
972: BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
973:
974: for (i = 0; i < RSA_NUM; i++) {
975: const unsigned char *p;
976:
977: p = rsa_data[i];
978: rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
979: if (rsa_key[i] == NULL) {
980: BIO_printf(bio_err, "internal error loading RSA key number %d\n", i);
981: goto end;
982: }
983: }
984:
985: dsa_key[0] = get_dsa512();
986: dsa_key[1] = get_dsa1024();
987: dsa_key[2] = get_dsa2048();
988:
989: #ifndef OPENSSL_NO_DES
990: DES_set_key_unchecked(&key, &sch);
991: DES_set_key_unchecked(&key2, &sch2);
992: DES_set_key_unchecked(&key3, &sch3);
993: #endif
994: #ifndef OPENSSL_NO_AES
995: AES_set_encrypt_key(key16, 128, &aes_ks1);
996: AES_set_encrypt_key(key24, 192, &aes_ks2);
997: AES_set_encrypt_key(key32, 256, &aes_ks3);
998: #endif
999: #ifndef OPENSSL_NO_CAMELLIA
1000: Camellia_set_key(key16, 128, &camellia_ks1);
1001: Camellia_set_key(ckey24, 192, &camellia_ks2);
1002: Camellia_set_key(ckey32, 256, &camellia_ks3);
1003: #endif
1004: #ifndef OPENSSL_NO_IDEA
1005: idea_set_encrypt_key(key16, &idea_ks);
1006: #endif
1007: #ifndef OPENSSL_NO_RC4
1008: RC4_set_key(&rc4_ks, 16, key16);
1009: #endif
1010: #ifndef OPENSSL_NO_RC2
1011: RC2_set_key(&rc2_ks, 16, key16, 128);
1012: #endif
1013: #ifndef OPENSSL_NO_RC5
1014: RC5_32_set_key(&rc5_ks, 16, key16, 12);
1015: #endif
1016: #ifndef OPENSSL_NO_BF
1017: BF_set_key(&bf_ks, 16, key16);
1018: #endif
1019: #ifndef OPENSSL_NO_CAST
1020: CAST_set_key(&cast_ks, 16, key16);
1021: #endif
1022: memset(rsa_c, 0, sizeof(rsa_c));
1023: #define COND(c) (run && count<0x7fffffff)
1024: #define COUNT(d) (count)
1025: signal(SIGALRM, sig_done);
1026:
1027: #ifndef OPENSSL_NO_MD4
1028: if (doit[D_MD4]) {
1029: for (j = 0; j < SIZE_NUM; j++) {
1030: print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1031: Time_F(START);
1032: for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1033: EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md4[0]), NULL, EVP_md4(), NULL);
1034: d = Time_F(STOP);
1035: print_result(D_MD4, j, count, d);
1036: }
1037: }
1038: #endif
1039:
1040: #ifndef OPENSSL_NO_MD5
1041: if (doit[D_MD5]) {
1042: for (j = 0; j < SIZE_NUM; j++) {
1043: print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1044: Time_F(START);
1045: for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1046: EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md5[0]), NULL, EVP_get_digestbyname("md5"), NULL);
1047: d = Time_F(STOP);
1048: print_result(D_MD5, j, count, d);
1049: }
1050: }
1051: #endif
1052:
1053: #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1054: if (doit[D_HMAC]) {
1055: HMAC_CTX hctx;
1056:
1057: HMAC_CTX_init(&hctx);
1058: HMAC_Init_ex(&hctx, (unsigned char *) "This is a key...",
1059: 16, EVP_md5(), NULL);
1060:
1061: for (j = 0; j < SIZE_NUM; j++) {
1062: print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1063: Time_F(START);
1064: for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1065: HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1066: HMAC_Update(&hctx, buf, lengths[j]);
1067: HMAC_Final(&hctx, &(hmac[0]), NULL);
1068: }
1069: d = Time_F(STOP);
1070: print_result(D_HMAC, j, count, d);
1071: }
1072: HMAC_CTX_cleanup(&hctx);
1073: }
1074: #endif
1075: #ifndef OPENSSL_NO_SHA
1076: if (doit[D_SHA1]) {
1077: for (j = 0; j < SIZE_NUM; j++) {
1078: print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1079: Time_F(START);
1080: for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1081: EVP_Digest(buf, (unsigned long) lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL);
1082: d = Time_F(STOP);
1083: print_result(D_SHA1, j, count, d);
1084: }
1085: }
1086: #ifndef OPENSSL_NO_SHA256
1087: if (doit[D_SHA256]) {
1088: for (j = 0; j < SIZE_NUM; j++) {
1089: print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1090: Time_F(START);
1091: for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1092: SHA256(buf, lengths[j], sha256);
1093: d = Time_F(STOP);
1094: print_result(D_SHA256, j, count, d);
1095: }
1096: }
1097: #endif
1098:
1099: #ifndef OPENSSL_NO_SHA512
1100: if (doit[D_SHA512]) {
1101: for (j = 0; j < SIZE_NUM; j++) {
1102: print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1103: Time_F(START);
1104: for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1105: SHA512(buf, lengths[j], sha512);
1106: d = Time_F(STOP);
1107: print_result(D_SHA512, j, count, d);
1108: }
1109: }
1110: #endif
1111: #endif
1112:
1113: #ifndef OPENSSL_NO_WHIRLPOOL
1114: if (doit[D_WHIRLPOOL]) {
1115: for (j = 0; j < SIZE_NUM; j++) {
1116: print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1117: Time_F(START);
1118: for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1119: WHIRLPOOL(buf, lengths[j], whirlpool);
1120: d = Time_F(STOP);
1121: print_result(D_WHIRLPOOL, j, count, d);
1122: }
1123: }
1124: #endif
1125:
1126: #ifndef OPENSSL_NO_RIPEMD
1127: if (doit[D_RMD160]) {
1128: for (j = 0; j < SIZE_NUM; j++) {
1129: print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1130: Time_F(START);
1131: for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1132: EVP_Digest(buf, (unsigned long) lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL);
1133: d = Time_F(STOP);
1134: print_result(D_RMD160, j, count, d);
1135: }
1136: }
1137: #endif
1138: #ifndef OPENSSL_NO_RC4
1139: if (doit[D_RC4]) {
1140: for (j = 0; j < SIZE_NUM; j++) {
1141: print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1142: Time_F(START);
1143: for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1144: RC4(&rc4_ks, (unsigned int) lengths[j],
1145: buf, buf);
1146: d = Time_F(STOP);
1147: print_result(D_RC4, j, count, d);
1148: }
1149: }
1150: #endif
1151: #ifndef OPENSSL_NO_DES
1152: if (doit[D_CBC_DES]) {
1153: for (j = 0; j < SIZE_NUM; j++) {
1154: print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1155: Time_F(START);
1156: for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1157: DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1158: &DES_iv, DES_ENCRYPT);
1159: d = Time_F(STOP);
1160: print_result(D_CBC_DES, j, count, d);
1161: }
1162: }
1163: if (doit[D_EDE3_DES]) {
1164: for (j = 0; j < SIZE_NUM; j++) {
1165: print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1166: Time_F(START);
1167: for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1168: DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1169: &sch, &sch2, &sch3,
1170: &DES_iv, DES_ENCRYPT);
1171: d = Time_F(STOP);
1172: print_result(D_EDE3_DES, j, count, d);
1173: }
1174: }
1175: #endif
1176: #ifndef OPENSSL_NO_AES
1177: if (doit[D_CBC_128_AES]) {
1178: for (j = 0; j < SIZE_NUM; j++) {
1179: print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]);
1180: Time_F(START);
1181: for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1182: AES_cbc_encrypt(buf, buf,
1183: (unsigned long) lengths[j], &aes_ks1,
1184: iv, AES_ENCRYPT);
1185: d = Time_F(STOP);
1186: print_result(D_CBC_128_AES, j, count, d);
1187: }
1188: }
1189: if (doit[D_CBC_192_AES]) {
1190: for (j = 0; j < SIZE_NUM; j++) {
1191: print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]);
1192: Time_F(START);
1193: for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1194: AES_cbc_encrypt(buf, buf,
1195: (unsigned long) lengths[j], &aes_ks2,
1196: iv, AES_ENCRYPT);
1197: d = Time_F(STOP);
1198: print_result(D_CBC_192_AES, j, count, d);
1199: }
1200: }
1201: if (doit[D_CBC_256_AES]) {
1202: for (j = 0; j < SIZE_NUM; j++) {
1203: print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]);
1204: Time_F(START);
1205: for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1206: AES_cbc_encrypt(buf, buf,
1207: (unsigned long) lengths[j], &aes_ks3,
1208: iv, AES_ENCRYPT);
1209: d = Time_F(STOP);
1210: print_result(D_CBC_256_AES, j, count, d);
1211: }
1212: }
1213: if (doit[D_IGE_128_AES]) {
1214: for (j = 0; j < SIZE_NUM; j++) {
1215: print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]);
1216: Time_F(START);
1217: for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1218: AES_ige_encrypt(buf, buf2,
1219: (unsigned long) lengths[j], &aes_ks1,
1220: iv, AES_ENCRYPT);
1221: d = Time_F(STOP);
1222: print_result(D_IGE_128_AES, j, count, d);
1223: }
1224: }
1225: if (doit[D_IGE_192_AES]) {
1226: for (j = 0; j < SIZE_NUM; j++) {
1227: print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]);
1228: Time_F(START);
1229: for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1230: AES_ige_encrypt(buf, buf2,
1231: (unsigned long) lengths[j], &aes_ks2,
1232: iv, AES_ENCRYPT);
1233: d = Time_F(STOP);
1234: print_result(D_IGE_192_AES, j, count, d);
1235: }
1236: }
1237: if (doit[D_IGE_256_AES]) {
1238: for (j = 0; j < SIZE_NUM; j++) {
1239: print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]);
1240: Time_F(START);
1241: for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1242: AES_ige_encrypt(buf, buf2,
1243: (unsigned long) lengths[j], &aes_ks3,
1244: iv, AES_ENCRYPT);
1245: d = Time_F(STOP);
1246: print_result(D_IGE_256_AES, j, count, d);
1247: }
1248: }
1249: if (doit[D_GHASH]) {
1250: GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1251: CRYPTO_gcm128_setiv(ctx, (unsigned char *) "0123456789ab", 12);
1252:
1253: for (j = 0; j < SIZE_NUM; j++) {
1254: print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1255: Time_F(START);
1256: for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1257: CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1258: d = Time_F(STOP);
1259: print_result(D_GHASH, j, count, d);
1260: }
1261: CRYPTO_gcm128_release(ctx);
1262: }
1263: #endif
1264: #ifndef OPENSSL_NO_CAMELLIA
1265: if (doit[D_CBC_128_CML]) {
1266: for (j = 0; j < SIZE_NUM; j++) {
1267: print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]);
1268: Time_F(START);
1269: for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1270: Camellia_cbc_encrypt(buf, buf,
1271: (unsigned long) lengths[j], &camellia_ks1,
1272: iv, CAMELLIA_ENCRYPT);
1273: d = Time_F(STOP);
1274: print_result(D_CBC_128_CML, j, count, d);
1275: }
1276: }
1277: if (doit[D_CBC_192_CML]) {
1278: for (j = 0; j < SIZE_NUM; j++) {
1279: print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]);
1280: Time_F(START);
1281: for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1282: Camellia_cbc_encrypt(buf, buf,
1283: (unsigned long) lengths[j], &camellia_ks2,
1284: iv, CAMELLIA_ENCRYPT);
1285: d = Time_F(STOP);
1286: print_result(D_CBC_192_CML, j, count, d);
1287: }
1288: }
1289: if (doit[D_CBC_256_CML]) {
1290: for (j = 0; j < SIZE_NUM; j++) {
1291: print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]);
1292: Time_F(START);
1293: for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1294: Camellia_cbc_encrypt(buf, buf,
1295: (unsigned long) lengths[j], &camellia_ks3,
1296: iv, CAMELLIA_ENCRYPT);
1297: d = Time_F(STOP);
1298: print_result(D_CBC_256_CML, j, count, d);
1299: }
1300: }
1301: #endif
1302: #ifndef OPENSSL_NO_IDEA
1303: if (doit[D_CBC_IDEA]) {
1304: for (j = 0; j < SIZE_NUM; j++) {
1305: print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1306: Time_F(START);
1307: for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1308: idea_cbc_encrypt(buf, buf,
1309: (unsigned long) lengths[j], &idea_ks,
1310: iv, IDEA_ENCRYPT);
1311: d = Time_F(STOP);
1312: print_result(D_CBC_IDEA, j, count, d);
1313: }
1314: }
1315: #endif
1316: #ifndef OPENSSL_NO_RC2
1317: if (doit[D_CBC_RC2]) {
1318: for (j = 0; j < SIZE_NUM; j++) {
1319: print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1320: Time_F(START);
1321: for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1322: RC2_cbc_encrypt(buf, buf,
1323: (unsigned long) lengths[j], &rc2_ks,
1324: iv, RC2_ENCRYPT);
1325: d = Time_F(STOP);
1326: print_result(D_CBC_RC2, j, count, d);
1327: }
1328: }
1329: #endif
1330: #ifndef OPENSSL_NO_RC5
1331: if (doit[D_CBC_RC5]) {
1332: for (j = 0; j < SIZE_NUM; j++) {
1333: print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
1334: Time_F(START);
1335: for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
1336: RC5_32_cbc_encrypt(buf, buf,
1337: (unsigned long) lengths[j], &rc5_ks,
1338: iv, RC5_ENCRYPT);
1339: d = Time_F(STOP);
1340: print_result(D_CBC_RC5, j, count, d);
1341: }
1342: }
1343: #endif
1344: #ifndef OPENSSL_NO_BF
1345: if (doit[D_CBC_BF]) {
1346: for (j = 0; j < SIZE_NUM; j++) {
1347: print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1348: Time_F(START);
1349: for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1350: BF_cbc_encrypt(buf, buf,
1351: (unsigned long) lengths[j], &bf_ks,
1352: iv, BF_ENCRYPT);
1353: d = Time_F(STOP);
1354: print_result(D_CBC_BF, j, count, d);
1355: }
1356: }
1357: #endif
1358: #ifndef OPENSSL_NO_CAST
1359: if (doit[D_CBC_CAST]) {
1360: for (j = 0; j < SIZE_NUM; j++) {
1361: print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1362: Time_F(START);
1363: for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1364: CAST_cbc_encrypt(buf, buf,
1365: (unsigned long) lengths[j], &cast_ks,
1366: iv, CAST_ENCRYPT);
1367: d = Time_F(STOP);
1368: print_result(D_CBC_CAST, j, count, d);
1369: }
1370: }
1371: #endif
1372:
1373: if (doit[D_EVP]) {
1374: for (j = 0; j < SIZE_NUM; j++) {
1375: if (evp_cipher) {
1376: EVP_CIPHER_CTX ctx;
1377: int outl;
1378:
1379: names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1380: /*
1381: * -O3 -fschedule-insns messes up an
1382: * optimization here! names[D_EVP] somehow
1383: * becomes NULL
1384: */
1385: print_message(names[D_EVP], save_count,
1386: lengths[j]);
1387:
1388: EVP_CIPHER_CTX_init(&ctx);
1389: if (decrypt)
1390: EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1391: else
1392: EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1393: EVP_CIPHER_CTX_set_padding(&ctx, 0);
1394:
1395: Time_F(START);
1396: if (decrypt)
1397: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1398: EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1399: else
1400: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1401: EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1402: if (decrypt)
1403: EVP_DecryptFinal_ex(&ctx, buf, &outl);
1404: else
1405: EVP_EncryptFinal_ex(&ctx, buf, &outl);
1406: d = Time_F(STOP);
1407: EVP_CIPHER_CTX_cleanup(&ctx);
1408: }
1409: if (evp_md) {
1410: names[D_EVP] = OBJ_nid2ln(evp_md->type);
1411: print_message(names[D_EVP], save_count,
1412: lengths[j]);
1413:
1414: Time_F(START);
1415: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1416: EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1417:
1418: d = Time_F(STOP);
1419: }
1420: print_result(D_EVP, j, count, d);
1421: }
1422: }
1.2 jsing 1423: arc4random_buf(buf, 36);
1.1 jsing 1424: for (j = 0; j < RSA_NUM; j++) {
1425: int ret;
1426: if (!rsa_doit[j])
1427: continue;
1428: ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1429: if (ret == 0) {
1430: BIO_printf(bio_err, "RSA sign failure. No RSA sign will be done.\n");
1431: ERR_print_errors(bio_err);
1432: rsa_count = 1;
1433: } else {
1434: pkey_print_message("private", "rsa",
1435: rsa_c[j][0], rsa_bits[j],
1436: RSA_SECONDS);
1437: /* RSA_blinding_on(rsa_key[j],NULL); */
1438: Time_F(START);
1439: for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1440: ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1441: &rsa_num, rsa_key[j]);
1442: if (ret == 0) {
1443: BIO_printf(bio_err,
1444: "RSA sign failure\n");
1445: ERR_print_errors(bio_err);
1446: count = 1;
1447: break;
1448: }
1449: }
1450: d = Time_F(STOP);
1451: BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
1452: : "%ld %d bit private RSA's in %.2fs\n",
1453: count, rsa_bits[j], d);
1454: rsa_results[j][0] = d / (double) count;
1455: rsa_count = count;
1456: }
1457:
1458: ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1459: if (ret <= 0) {
1460: BIO_printf(bio_err, "RSA verify failure. No RSA verify will be done.\n");
1461: ERR_print_errors(bio_err);
1462: rsa_doit[j] = 0;
1463: } else {
1464: pkey_print_message("public", "rsa",
1465: rsa_c[j][1], rsa_bits[j],
1466: RSA_SECONDS);
1467: Time_F(START);
1468: for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1469: ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1470: rsa_num, rsa_key[j]);
1471: if (ret <= 0) {
1472: BIO_printf(bio_err,
1473: "RSA verify failure\n");
1474: ERR_print_errors(bio_err);
1475: count = 1;
1476: break;
1477: }
1478: }
1479: d = Time_F(STOP);
1480: BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
1481: : "%ld %d bit public RSA's in %.2fs\n",
1482: count, rsa_bits[j], d);
1483: rsa_results[j][1] = d / (double) count;
1484: }
1485:
1486: if (rsa_count <= 1) {
1487: /* if longer than 10s, don't do any more */
1488: for (j++; j < RSA_NUM; j++)
1489: rsa_doit[j] = 0;
1490: }
1491: }
1492:
1.2 jsing 1493: arc4random_buf(buf, 20);
1.1 jsing 1494: for (j = 0; j < DSA_NUM; j++) {
1495: unsigned int kk;
1496: int ret;
1497:
1498: if (!dsa_doit[j])
1499: continue;
1500: /* DSA_generate_key(dsa_key[j]); */
1501: /* DSA_sign_setup(dsa_key[j],NULL); */
1502: ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1503: &kk, dsa_key[j]);
1504: if (ret == 0) {
1505: BIO_printf(bio_err, "DSA sign failure. No DSA sign will be done.\n");
1506: ERR_print_errors(bio_err);
1507: rsa_count = 1;
1508: } else {
1509: pkey_print_message("sign", "dsa",
1510: dsa_c[j][0], dsa_bits[j],
1511: DSA_SECONDS);
1512: Time_F(START);
1513: for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1514: ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1515: &kk, dsa_key[j]);
1516: if (ret == 0) {
1517: BIO_printf(bio_err,
1518: "DSA sign failure\n");
1519: ERR_print_errors(bio_err);
1520: count = 1;
1521: break;
1522: }
1523: }
1524: d = Time_F(STOP);
1525: BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n"
1526: : "%ld %d bit DSA signs in %.2fs\n",
1527: count, dsa_bits[j], d);
1528: dsa_results[j][0] = d / (double) count;
1529: rsa_count = count;
1530: }
1531:
1532: ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1533: kk, dsa_key[j]);
1534: if (ret <= 0) {
1535: BIO_printf(bio_err, "DSA verify failure. No DSA verify will be done.\n");
1536: ERR_print_errors(bio_err);
1537: dsa_doit[j] = 0;
1538: } else {
1539: pkey_print_message("verify", "dsa",
1540: dsa_c[j][1], dsa_bits[j],
1541: DSA_SECONDS);
1542: Time_F(START);
1543: for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1544: ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1545: kk, dsa_key[j]);
1546: if (ret <= 0) {
1547: BIO_printf(bio_err,
1548: "DSA verify failure\n");
1549: ERR_print_errors(bio_err);
1550: count = 1;
1551: break;
1552: }
1553: }
1554: d = Time_F(STOP);
1555: BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n"
1556: : "%ld %d bit DSA verify in %.2fs\n",
1557: count, dsa_bits[j], d);
1558: dsa_results[j][1] = d / (double) count;
1559: }
1560:
1561: if (rsa_count <= 1) {
1562: /* if longer than 10s, don't do any more */
1563: for (j++; j < DSA_NUM; j++)
1564: dsa_doit[j] = 0;
1565: }
1566: }
1567:
1568: for (j = 0; j < EC_NUM; j++) {
1569: int ret;
1570:
1571: if (!ecdsa_doit[j])
1572: continue; /* Ignore Curve */
1573: ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1574: if (ecdsa[j] == NULL) {
1575: BIO_printf(bio_err, "ECDSA failure.\n");
1576: ERR_print_errors(bio_err);
1577: rsa_count = 1;
1578: } else {
1579: EC_KEY_precompute_mult(ecdsa[j], NULL);
1.5 doug 1580:
1.1 jsing 1581: /* Perform ECDSA signature test */
1582: EC_KEY_generate_key(ecdsa[j]);
1583: ret = ECDSA_sign(0, buf, 20, ecdsasig,
1584: &ecdsasiglen, ecdsa[j]);
1585: if (ret == 0) {
1586: BIO_printf(bio_err, "ECDSA sign failure. No ECDSA sign will be done.\n");
1587: ERR_print_errors(bio_err);
1588: rsa_count = 1;
1589: } else {
1590: pkey_print_message("sign", "ecdsa",
1591: ecdsa_c[j][0],
1592: test_curves_bits[j],
1593: ECDSA_SECONDS);
1594:
1595: Time_F(START);
1596: for (count = 0, run = 1; COND(ecdsa_c[j][0]);
1597: count++) {
1598: ret = ECDSA_sign(0, buf, 20,
1599: ecdsasig, &ecdsasiglen,
1600: ecdsa[j]);
1601: if (ret == 0) {
1602: BIO_printf(bio_err, "ECDSA sign failure\n");
1603: ERR_print_errors(bio_err);
1604: count = 1;
1605: break;
1606: }
1607: }
1608: d = Time_F(STOP);
1609:
1610: BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
1611: "%ld %d bit ECDSA signs in %.2fs \n",
1612: count, test_curves_bits[j], d);
1613: ecdsa_results[j][0] = d / (double) count;
1614: rsa_count = count;
1615: }
1616:
1617: /* Perform ECDSA verification test */
1618: ret = ECDSA_verify(0, buf, 20, ecdsasig,
1619: ecdsasiglen, ecdsa[j]);
1620: if (ret != 1) {
1621: BIO_printf(bio_err, "ECDSA verify failure. No ECDSA verify will be done.\n");
1622: ERR_print_errors(bio_err);
1623: ecdsa_doit[j] = 0;
1624: } else {
1625: pkey_print_message("verify", "ecdsa",
1626: ecdsa_c[j][1],
1627: test_curves_bits[j],
1628: ECDSA_SECONDS);
1629: Time_F(START);
1630: for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1631: ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1632: if (ret != 1) {
1633: BIO_printf(bio_err, "ECDSA verify failure\n");
1634: ERR_print_errors(bio_err);
1635: count = 1;
1636: break;
1637: }
1638: }
1639: d = Time_F(STOP);
1640: BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n"
1641: : "%ld %d bit ECDSA verify in %.2fs\n",
1642: count, test_curves_bits[j], d);
1643: ecdsa_results[j][1] = d / (double) count;
1644: }
1645:
1646: if (rsa_count <= 1) {
1647: /* if longer than 10s, don't do any more */
1648: for (j++; j < EC_NUM; j++)
1649: ecdsa_doit[j] = 0;
1650: }
1651: }
1652: }
1653:
1654: for (j = 0; j < EC_NUM; j++) {
1655: if (!ecdh_doit[j])
1656: continue;
1657: ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1658: ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1659: if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1660: BIO_printf(bio_err, "ECDH failure.\n");
1661: ERR_print_errors(bio_err);
1662: rsa_count = 1;
1663: } else {
1664: /* generate two ECDH key pairs */
1665: if (!EC_KEY_generate_key(ecdh_a[j]) ||
1666: !EC_KEY_generate_key(ecdh_b[j])) {
1667: BIO_printf(bio_err, "ECDH key generation failure.\n");
1668: ERR_print_errors(bio_err);
1669: rsa_count = 1;
1670: } else {
1671: /*
1672: * If field size is not more than 24 octets,
1673: * then use SHA-1 hash of result; otherwise,
1674: * use result (see section 4.8 of
1675: * draft-ietf-tls-ecc-03.txt).
1676: */
1677: int field_size, outlen;
1678: void *(*kdf) (const void *in, size_t inlen, void *out, size_t * xoutlen);
1679: field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1680: if (field_size <= 24 * 8) {
1681: outlen = KDF1_SHA1_len;
1682: kdf = KDF1_SHA1;
1683: } else {
1684: outlen = (field_size + 7) / 8;
1685: kdf = NULL;
1686: }
1687: secret_size_a = ECDH_compute_key(secret_a, outlen,
1688: EC_KEY_get0_public_key(ecdh_b[j]),
1689: ecdh_a[j], kdf);
1690: secret_size_b = ECDH_compute_key(secret_b, outlen,
1691: EC_KEY_get0_public_key(ecdh_a[j]),
1692: ecdh_b[j], kdf);
1693: if (secret_size_a != secret_size_b)
1694: ecdh_checks = 0;
1695: else
1696: ecdh_checks = 1;
1697:
1698: for (secret_idx = 0;
1699: (secret_idx < secret_size_a)
1700: && (ecdh_checks == 1);
1701: secret_idx++) {
1702: if (secret_a[secret_idx] != secret_b[secret_idx])
1703: ecdh_checks = 0;
1704: }
1705:
1706: if (ecdh_checks == 0) {
1.8 doug 1707: BIO_printf(bio_err,
1708: "ECDH computations don't match.\n");
1.1 jsing 1709: ERR_print_errors(bio_err);
1710: rsa_count = 1;
1.8 doug 1711: } else {
1712: pkey_print_message("", "ecdh",
1713: ecdh_c[j][0],
1714: test_curves_bits[j],
1715: ECDH_SECONDS);
1716: Time_F(START);
1717: for (count = 0, run = 1;
1718: COND(ecdh_c[j][0]); count++) {
1719: ECDH_compute_key(secret_a,
1720: outlen,
1721: EC_KEY_get0_public_key(ecdh_b[j]),
1722: ecdh_a[j], kdf);
1723: }
1724: d = Time_F(STOP);
1725: BIO_printf(bio_err, mr
1726: ? "+R7:%ld:%d:%.2f\n"
1727: : "%ld %d-bit ECDH ops in %.2fs\n",
1728: count, test_curves_bits[j], d);
1729: ecdh_results[j][0] = d / (double) count;
1730: rsa_count = count;
1.1 jsing 1731: }
1732: }
1733: }
1734:
1735:
1736: if (rsa_count <= 1) {
1737: /* if longer than 10s, don't do any more */
1738: for (j++; j < EC_NUM; j++)
1739: ecdh_doit[j] = 0;
1740: }
1741: }
1742: show_res:
1743: if (!mr) {
1744: fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
1745: fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
1746: printf("options:");
1747: printf("%s ", BN_options());
1748: #ifndef OPENSSL_NO_RC4
1749: printf("%s ", RC4_options());
1750: #endif
1751: #ifndef OPENSSL_NO_DES
1752: printf("%s ", DES_options());
1753: #endif
1754: #ifndef OPENSSL_NO_AES
1755: printf("%s ", AES_options());
1756: #endif
1757: #ifndef OPENSSL_NO_IDEA
1758: printf("%s ", idea_options());
1759: #endif
1760: #ifndef OPENSSL_NO_BF
1761: printf("%s ", BF_options());
1762: #endif
1763: fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
1764: }
1765: if (pr_header) {
1766: if (mr)
1767: fprintf(stdout, "+H");
1768: else {
1769: fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n");
1770: fprintf(stdout, "type ");
1771: }
1772: for (j = 0; j < SIZE_NUM; j++)
1773: fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
1774: fprintf(stdout, "\n");
1775: }
1776: for (k = 0; k < ALGOR_NUM; k++) {
1777: if (!doit[k])
1778: continue;
1779: if (mr)
1780: fprintf(stdout, "+F:%d:%s", k, names[k]);
1781: else
1782: fprintf(stdout, "%-13s", names[k]);
1783: for (j = 0; j < SIZE_NUM; j++) {
1784: if (results[k][j] > 10000 && !mr)
1785: fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
1786: else
1787: fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
1788: }
1789: fprintf(stdout, "\n");
1790: }
1791: j = 1;
1792: for (k = 0; k < RSA_NUM; k++) {
1793: if (!rsa_doit[k])
1794: continue;
1795: if (j && !mr) {
1796: printf("%18ssign verify sign/s verify/s\n", " ");
1797: j = 0;
1798: }
1799: if (mr)
1800: fprintf(stdout, "+F2:%u:%u:%f:%f\n",
1801: k, rsa_bits[k], rsa_results[k][0],
1802: rsa_results[k][1]);
1803: else
1804: fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1805: rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1806: 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
1807: }
1808: j = 1;
1809: for (k = 0; k < DSA_NUM; k++) {
1810: if (!dsa_doit[k])
1811: continue;
1812: if (j && !mr) {
1813: printf("%18ssign verify sign/s verify/s\n", " ");
1814: j = 0;
1815: }
1816: if (mr)
1817: fprintf(stdout, "+F3:%u:%u:%f:%f\n",
1818: k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
1819: else
1820: fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1821: dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1822: 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
1823: }
1824: j = 1;
1825: for (k = 0; k < EC_NUM; k++) {
1826: if (!ecdsa_doit[k])
1827: continue;
1828: if (j && !mr) {
1829: printf("%30ssign verify sign/s verify/s\n", " ");
1830: j = 0;
1831: }
1832: if (mr)
1833: fprintf(stdout, "+F4:%u:%u:%f:%f\n",
1834: k, test_curves_bits[k],
1835: ecdsa_results[k][0], ecdsa_results[k][1]);
1836: else
1837: fprintf(stdout,
1838: "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
1839: test_curves_bits[k],
1840: test_curves_names[k],
1841: ecdsa_results[k][0], ecdsa_results[k][1],
1842: 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
1843: }
1844:
1845:
1846: j = 1;
1847: for (k = 0; k < EC_NUM; k++) {
1848: if (!ecdh_doit[k])
1849: continue;
1850: if (j && !mr) {
1851: printf("%30sop op/s\n", " ");
1852: j = 0;
1853: }
1854: if (mr)
1855: fprintf(stdout, "+F5:%u:%u:%f:%f\n",
1856: k, test_curves_bits[k],
1857: ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1858:
1859: else
1860: fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
1861: test_curves_bits[k],
1862: test_curves_names[k],
1863: ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1864: }
1865:
1866: mret = 0;
1867:
1868: end:
1869: ERR_print_errors(bio_err);
1870: free(buf);
1871: free(buf2);
1872: for (i = 0; i < RSA_NUM; i++)
1873: if (rsa_key[i] != NULL)
1874: RSA_free(rsa_key[i]);
1875: for (i = 0; i < DSA_NUM; i++)
1876: if (dsa_key[i] != NULL)
1877: DSA_free(dsa_key[i]);
1878:
1879: for (i = 0; i < EC_NUM; i++)
1880: if (ecdsa[i] != NULL)
1881: EC_KEY_free(ecdsa[i]);
1882: for (i = 0; i < EC_NUM; i++) {
1883: if (ecdh_a[i] != NULL)
1884: EC_KEY_free(ecdh_a[i]);
1885: if (ecdh_b[i] != NULL)
1886: EC_KEY_free(ecdh_b[i]);
1887: }
1888:
1889:
1890: return (mret);
1891: }
1892:
1893: static void
1894: print_message(const char *s, long num, int length)
1895: {
1896: BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
1897: : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
1898: (void) BIO_flush(bio_err);
1899: alarm(SECONDS);
1900: }
1901:
1902: static void
1903: pkey_print_message(const char *str, const char *str2, long num,
1904: int bits, int tm)
1905: {
1906: BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n"
1907: : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
1908: (void) BIO_flush(bio_err);
1909: alarm(tm);
1910: }
1911:
1912: static void
1913: print_result(int alg, int run_no, int count, double time_used)
1914: {
1915: BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
1916: : "%d %s's in %.2fs\n", count, names[alg], time_used);
1917: results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
1918: }
1919:
1920: static char *
1921: sstrsep(char **string, const char *delim)
1922: {
1923: char isdelim[256];
1924: char *token = *string;
1925:
1926: if (**string == 0)
1927: return NULL;
1928:
1929: memset(isdelim, 0, sizeof isdelim);
1930: isdelim[0] = 1;
1931:
1932: while (*delim) {
1933: isdelim[(unsigned char) (*delim)] = 1;
1934: delim++;
1935: }
1936:
1937: while (!isdelim[(unsigned char) (**string)]) {
1938: (*string)++;
1939: }
1940:
1941: if (**string) {
1942: **string = 0;
1943: (*string)++;
1944: }
1945: return token;
1946: }
1947:
1948: static int
1949: do_multi(int multi)
1950: {
1951: int n;
1952: int fd[2];
1953: int *fds;
1954: static char sep[] = ":";
1955: const char *errstr = NULL;
1956:
1957: fds = reallocarray(NULL, multi, sizeof *fds);
1.4 lteo 1958: if (fds == NULL) {
1959: fprintf(stderr, "reallocarray failure\n");
1960: exit(1);
1961: }
1.1 jsing 1962: for (n = 0; n < multi; ++n) {
1963: if (pipe(fd) == -1) {
1964: fprintf(stderr, "pipe failure\n");
1965: exit(1);
1966: }
1967: fflush(stdout);
1968: fflush(stderr);
1969: if (fork()) {
1970: close(fd[1]);
1971: fds[n] = fd[0];
1972: } else {
1973: close(fd[0]);
1974: close(1);
1975: if (dup(fd[1]) == -1) {
1976: fprintf(stderr, "dup failed\n");
1977: exit(1);
1978: }
1979: close(fd[1]);
1980: mr = 1;
1981: usertime = 0;
1982: free(fds);
1983: return 0;
1984: }
1985: printf("Forked child %d\n", n);
1986: }
1987:
1988: /* for now, assume the pipe is long enough to take all the output */
1989: for (n = 0; n < multi; ++n) {
1990: FILE *f;
1991: char buf[1024];
1992: char *p;
1993:
1994: f = fdopen(fds[n], "r");
1995: while (fgets(buf, sizeof buf, f)) {
1996: p = strchr(buf, '\n');
1997: if (p)
1998: *p = '\0';
1999: if (buf[0] != '+') {
2000: fprintf(stderr, "Don't understand line '%s' from child %d\n",
2001: buf, n);
2002: continue;
2003: }
2004: printf("Got: %s from %d\n", buf, n);
2005: if (!strncmp(buf, "+F:", 3)) {
2006: int alg;
2007: int j;
2008:
2009: p = buf + 3;
2010: alg = strtonum(sstrsep(&p, sep),
2011: 0, ALGOR_NUM - 1, &errstr);
2012: sstrsep(&p, sep);
2013: for (j = 0; j < SIZE_NUM; ++j)
2014: results[alg][j] += atof(sstrsep(&p, sep));
2015: } else if (!strncmp(buf, "+F2:", 4)) {
2016: int k;
2017: double d;
2018:
2019: p = buf + 4;
2020: k = strtonum(sstrsep(&p, sep),
2021: 0, ALGOR_NUM - 1, &errstr);
2022: sstrsep(&p, sep);
2023:
2024: d = atof(sstrsep(&p, sep));
2025: if (n)
2026: rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2027: else
2028: rsa_results[k][0] = d;
2029:
2030: d = atof(sstrsep(&p, sep));
2031: if (n)
2032: rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2033: else
2034: rsa_results[k][1] = d;
2035: } else if (!strncmp(buf, "+F2:", 4)) {
2036: int k;
2037: double d;
2038:
2039: p = buf + 4;
2040: k = strtonum(sstrsep(&p, sep),
2041: 0, ALGOR_NUM - 1, &errstr);
2042: sstrsep(&p, sep);
2043:
2044: d = atof(sstrsep(&p, sep));
2045: if (n)
2046: rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2047: else
2048: rsa_results[k][0] = d;
2049:
2050: d = atof(sstrsep(&p, sep));
2051: if (n)
2052: rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2053: else
2054: rsa_results[k][1] = d;
2055: }
2056: else if (!strncmp(buf, "+F3:", 4)) {
2057: int k;
2058: double d;
2059:
2060: p = buf + 4;
2061: k = strtonum(sstrsep(&p, sep),
2062: 0, ALGOR_NUM - 1, &errstr);
2063: sstrsep(&p, sep);
2064:
2065: d = atof(sstrsep(&p, sep));
2066: if (n)
2067: dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2068: else
2069: dsa_results[k][0] = d;
2070:
2071: d = atof(sstrsep(&p, sep));
2072: if (n)
2073: dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2074: else
2075: dsa_results[k][1] = d;
2076: }
2077: else if (!strncmp(buf, "+F4:", 4)) {
2078: int k;
2079: double d;
2080:
2081: p = buf + 4;
2082: k = strtonum(sstrsep(&p, sep),
2083: 0, ALGOR_NUM - 1, &errstr);
2084: sstrsep(&p, sep);
2085:
2086: d = atof(sstrsep(&p, sep));
2087: if (n)
2088: ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
2089: else
2090: ecdsa_results[k][0] = d;
2091:
2092: d = atof(sstrsep(&p, sep));
2093: if (n)
2094: ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
2095: else
2096: ecdsa_results[k][1] = d;
2097: }
2098:
2099: else if (!strncmp(buf, "+F5:", 4)) {
2100: int k;
2101: double d;
2102:
2103: p = buf + 4;
2104: k = strtonum(sstrsep(&p, sep),
2105: 0, ALGOR_NUM - 1, &errstr);
2106: sstrsep(&p, sep);
2107:
2108: d = atof(sstrsep(&p, sep));
2109: if (n)
2110: ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2111: else
2112: ecdh_results[k][0] = d;
2113:
2114: }
2115:
2116: else if (!strncmp(buf, "+H:", 3)) {
2117: } else
2118: fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2119: }
2120:
2121: fclose(f);
2122: }
2123: free(fds);
2124: return 1;
2125: }
2126: #endif