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