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