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