Annotation of src/usr.bin/openssl/speed.c, Revision 1.17
1.17 ! doug 1: /* $OpenBSD: speed.c,v 1.16 2015/09/20 13:39:13 miod Exp $ */
1.1 jsing 2: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3: * All rights reserved.
4: *
5: * This package is an SSL implementation written
6: * by Eric Young (eay@cryptsoft.com).
7: * The implementation was written so as to conform with Netscapes SSL.
8: *
9: * This library is free for commercial and non-commercial use as long as
10: * the following conditions are aheared to. The following conditions
11: * apply to all code found in this distribution, be it the RC4, RSA,
12: * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13: * included with this distribution is covered by the same copyright terms
14: * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15: *
16: * Copyright remains Eric Young's, and as such any Copyright notices in
17: * the code are not to be removed.
18: * If this package is used in a product, Eric Young should be given attribution
19: * as the author of the parts of the library used.
20: * This can be in the form of a textual message at program startup or
21: * in documentation (online or textual) provided with the package.
22: *
23: * Redistribution and use in source and binary forms, with or without
24: * modification, are permitted provided that the following conditions
25: * are met:
26: * 1. Redistributions of source code must retain the copyright
27: * notice, this list of conditions and the following disclaimer.
28: * 2. Redistributions in binary form must reproduce the above copyright
29: * notice, this list of conditions and the following disclaimer in the
30: * documentation and/or other materials provided with the distribution.
31: * 3. All advertising materials mentioning features or use of this software
32: * must display the following acknowledgement:
33: * "This product includes cryptographic software written by
34: * Eric Young (eay@cryptsoft.com)"
35: * The word 'cryptographic' can be left out if the rouines from the library
36: * being used are not cryptographic related :-).
37: * 4. If you include any Windows specific code (or a derivative thereof) from
38: * the apps directory (application code) you must include an acknowledgement:
39: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40: *
41: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51: * SUCH DAMAGE.
52: *
53: * The licence and distribution terms for any publically available version or
54: * derivative of this code cannot be changed. i.e. this code cannot simply be
55: * copied and put under another distribution licence
56: * [including the GNU Public Licence.]
57: */
58: /* ====================================================================
59: * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60: *
61: * Portions of the attached software ("Contribution") are developed by
62: * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63: *
64: * The Contribution is licensed pursuant to the OpenSSL open source
65: * license provided above.
66: *
67: * The ECDH and ECDSA speed test software is originally written by
68: * Sumit Gupta of Sun Microsystems Laboratories.
69: *
70: */
71:
72: /* most of this code has been pilfered from my libdes speed.c program */
73:
74: #ifndef OPENSSL_NO_SPEED
75:
76: #define SECONDS 3
77: #define RSA_SECONDS 10
78: #define DSA_SECONDS 10
79: #define ECDSA_SECONDS 10
80: #define ECDH_SECONDS 10
81:
82: /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
83: /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
84:
85: #include <math.h>
86: #include <signal.h>
87: #include <stdio.h>
88: #include <stdlib.h>
89: #include <limits.h>
90: #include <string.h>
91: #include <unistd.h>
92:
93: #include "apps.h"
94:
95: #include <openssl/bn.h>
96: #include <openssl/crypto.h>
97: #include <openssl/err.h>
98: #include <openssl/evp.h>
99: #include <openssl/modes.h>
100: #include <openssl/objects.h>
101: #include <openssl/x509.h>
102:
103: #ifndef OPENSSL_NO_AES
104: #include <openssl/aes.h>
105: #endif
106: #ifndef OPENSSL_NO_BF
107: #include <openssl/blowfish.h>
108: #endif
109: #ifndef OPENSSL_NO_CAST
110: #include <openssl/cast.h>
111: #endif
112: #ifndef OPENSSL_NO_CAMELLIA
113: #include <openssl/camellia.h>
114: #endif
115: #ifndef OPENSSL_NO_DES
116: #include <openssl/des.h>
117: #endif
118: #include <openssl/dsa.h>
119: #include <openssl/ecdh.h>
120: #include <openssl/ecdsa.h>
121: #ifndef OPENSSL_NO_HMAC
122: #include <openssl/hmac.h>
123: #endif
124: #ifndef OPENSSL_NO_IDEA
125: #include <openssl/idea.h>
126: #endif
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;
1.17 ! doug 471:
! 472: if (single_execution) {
! 473: if (pledge("stdio proc", NULL) == -1)
! 474: perror("pledge");
! 475: }
1.1 jsing 476:
477: usertime = -1;
478:
479: memset(results, 0, sizeof(results));
480: memset(dsa_key, 0, sizeof(dsa_key));
481: for (i = 0; i < EC_NUM; i++)
482: ecdsa[i] = NULL;
483: for (i = 0; i < EC_NUM; i++) {
484: ecdh_a[i] = NULL;
485: ecdh_b[i] = NULL;
486: }
487:
488: memset(rsa_key, 0, sizeof(rsa_key));
489: for (i = 0; i < RSA_NUM; i++)
490: rsa_key[i] = NULL;
491:
1.10 deraadt 492: if ((buf = malloc(BUFSIZE)) == NULL) {
1.1 jsing 493: BIO_printf(bio_err, "out of memory\n");
494: goto end;
495: }
1.10 deraadt 496: if ((buf2 = malloc(BUFSIZE)) == NULL) {
1.1 jsing 497: BIO_printf(bio_err, "out of memory\n");
498: goto end;
499: }
500: memset(c, 0, sizeof(c));
501: memset(DES_iv, 0, sizeof(DES_iv));
502: memset(iv, 0, sizeof(iv));
503:
504: for (i = 0; i < ALGOR_NUM; i++)
505: doit[i] = 0;
506: for (i = 0; i < RSA_NUM; i++)
507: rsa_doit[i] = 0;
508: for (i = 0; i < DSA_NUM; i++)
509: dsa_doit[i] = 0;
510: for (i = 0; i < EC_NUM; i++)
511: ecdsa_doit[i] = 0;
512: for (i = 0; i < EC_NUM; i++)
513: ecdh_doit[i] = 0;
514:
515:
516: j = 0;
517: argc--;
518: argv++;
519: while (argc) {
520: if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
521: usertime = 0;
522: j--; /* Otherwise, -elapsed gets confused with an
523: * algorithm. */
524: } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
525: argc--;
526: argv++;
527: if (argc == 0) {
528: BIO_printf(bio_err, "no EVP given\n");
529: goto end;
530: }
531: evp_cipher = EVP_get_cipherbyname(*argv);
532: if (!evp_cipher) {
533: evp_md = EVP_get_digestbyname(*argv);
534: }
535: if (!evp_cipher && !evp_md) {
536: BIO_printf(bio_err, "%s is an unknown cipher or digest\n", *argv);
537: goto end;
538: }
539: doit[D_EVP] = 1;
540: } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
541: decrypt = 1;
542: j--; /* Otherwise, -elapsed gets confused with an
543: * algorithm. */
544: }
545: else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
546: argc--;
547: argv++;
548: if (argc == 0) {
549: BIO_printf(bio_err, "no multi count given\n");
550: goto end;
551: }
552: multi = strtonum(argv[0], 1, INT_MAX, &errstr);
553: if (errstr) {
554: BIO_printf(bio_err, "bad multi count: %s", errstr);
555: goto end;
556: }
557: j--; /* Otherwise, -mr gets confused with an
558: * algorithm. */
559: }
560: else if (argc > 0 && !strcmp(*argv, "-mr")) {
561: mr = 1;
562: j--; /* Otherwise, -mr gets confused with an
563: * algorithm. */
564: } else
1.15 doug 565: #ifndef OPENSSL_NO_MD4
566: if (strcmp(*argv, "md4") == 0)
567: doit[D_MD4] = 1;
568: else
569: #endif
1.1 jsing 570: #ifndef OPENSSL_NO_MD5
571: if (strcmp(*argv, "md5") == 0)
572: doit[D_MD5] = 1;
573: else
574: #endif
575: #ifndef OPENSSL_NO_MD5
576: if (strcmp(*argv, "hmac") == 0)
577: doit[D_HMAC] = 1;
578: else
579: #endif
580: #ifndef OPENSSL_NO_SHA
581: if (strcmp(*argv, "sha1") == 0)
582: doit[D_SHA1] = 1;
583: else if (strcmp(*argv, "sha") == 0)
584: doit[D_SHA1] = 1,
585: doit[D_SHA256] = 1,
586: doit[D_SHA512] = 1;
587: else
588: #ifndef OPENSSL_NO_SHA256
589: if (strcmp(*argv, "sha256") == 0)
590: doit[D_SHA256] = 1;
591: else
592: #endif
593: #ifndef OPENSSL_NO_SHA512
594: if (strcmp(*argv, "sha512") == 0)
595: doit[D_SHA512] = 1;
596: else
597: #endif
598: #endif
599: #ifndef OPENSSL_NO_WHIRLPOOL
600: if (strcmp(*argv, "whirlpool") == 0)
601: doit[D_WHIRLPOOL] = 1;
602: else
603: #endif
604: #ifndef OPENSSL_NO_RIPEMD
605: if (strcmp(*argv, "ripemd") == 0)
606: doit[D_RMD160] = 1;
607: else if (strcmp(*argv, "rmd160") == 0)
608: doit[D_RMD160] = 1;
609: else if (strcmp(*argv, "ripemd160") == 0)
610: doit[D_RMD160] = 1;
611: else
612: #endif
613: #ifndef OPENSSL_NO_RC4
614: if (strcmp(*argv, "rc4") == 0)
615: doit[D_RC4] = 1;
616: else
617: #endif
618: #ifndef OPENSSL_NO_DES
619: if (strcmp(*argv, "des-cbc") == 0)
620: doit[D_CBC_DES] = 1;
621: else if (strcmp(*argv, "des-ede3") == 0)
622: doit[D_EDE3_DES] = 1;
623: else
624: #endif
625: #ifndef OPENSSL_NO_AES
626: if (strcmp(*argv, "aes-128-cbc") == 0)
627: doit[D_CBC_128_AES] = 1;
628: else if (strcmp(*argv, "aes-192-cbc") == 0)
629: doit[D_CBC_192_AES] = 1;
630: else if (strcmp(*argv, "aes-256-cbc") == 0)
631: doit[D_CBC_256_AES] = 1;
632: else if (strcmp(*argv, "aes-128-ige") == 0)
633: doit[D_IGE_128_AES] = 1;
634: else if (strcmp(*argv, "aes-192-ige") == 0)
635: doit[D_IGE_192_AES] = 1;
636: else if (strcmp(*argv, "aes-256-ige") == 0)
637: doit[D_IGE_256_AES] = 1;
638: else
639: #endif
640: #ifndef OPENSSL_NO_CAMELLIA
641: if (strcmp(*argv, "camellia-128-cbc") == 0)
642: doit[D_CBC_128_CML] = 1;
643: else if (strcmp(*argv, "camellia-192-cbc") == 0)
644: doit[D_CBC_192_CML] = 1;
645: else if (strcmp(*argv, "camellia-256-cbc") == 0)
646: doit[D_CBC_256_CML] = 1;
647: else
648: #endif
649: #ifndef RSA_NULL
650: if (strcmp(*argv, "openssl") == 0) {
651: RSA_set_default_method(RSA_PKCS1_SSLeay());
652: j--;
653: } else
654: #endif
655: if (strcmp(*argv, "dsa512") == 0)
656: dsa_doit[R_DSA_512] = 2;
657: else if (strcmp(*argv, "dsa1024") == 0)
658: dsa_doit[R_DSA_1024] = 2;
659: else if (strcmp(*argv, "dsa2048") == 0)
660: dsa_doit[R_DSA_2048] = 2;
661: else if (strcmp(*argv, "rsa512") == 0)
662: rsa_doit[R_RSA_512] = 2;
663: else if (strcmp(*argv, "rsa1024") == 0)
664: rsa_doit[R_RSA_1024] = 2;
665: else if (strcmp(*argv, "rsa2048") == 0)
666: rsa_doit[R_RSA_2048] = 2;
667: else if (strcmp(*argv, "rsa4096") == 0)
668: rsa_doit[R_RSA_4096] = 2;
669: else
670: #ifndef OPENSSL_NO_RC2
671: if (strcmp(*argv, "rc2-cbc") == 0)
672: doit[D_CBC_RC2] = 1;
673: else if (strcmp(*argv, "rc2") == 0)
674: doit[D_CBC_RC2] = 1;
675: else
676: #endif
677: #ifndef OPENSSL_NO_IDEA
678: if (strcmp(*argv, "idea-cbc") == 0)
679: doit[D_CBC_IDEA] = 1;
680: else if (strcmp(*argv, "idea") == 0)
681: doit[D_CBC_IDEA] = 1;
682: else
683: #endif
684: #ifndef OPENSSL_NO_BF
685: if (strcmp(*argv, "bf-cbc") == 0)
686: doit[D_CBC_BF] = 1;
687: else if (strcmp(*argv, "blowfish") == 0)
688: doit[D_CBC_BF] = 1;
689: else if (strcmp(*argv, "bf") == 0)
690: doit[D_CBC_BF] = 1;
691: else
692: #endif
693: #ifndef OPENSSL_NO_CAST
694: if (strcmp(*argv, "cast-cbc") == 0)
695: doit[D_CBC_CAST] = 1;
696: else if (strcmp(*argv, "cast") == 0)
697: doit[D_CBC_CAST] = 1;
698: else if (strcmp(*argv, "cast5") == 0)
699: doit[D_CBC_CAST] = 1;
700: else
701: #endif
702: #ifndef OPENSSL_NO_DES
703: if (strcmp(*argv, "des") == 0) {
704: doit[D_CBC_DES] = 1;
705: doit[D_EDE3_DES] = 1;
706: } else
707: #endif
708: #ifndef OPENSSL_NO_AES
709: if (strcmp(*argv, "aes") == 0) {
710: doit[D_CBC_128_AES] = 1;
711: doit[D_CBC_192_AES] = 1;
712: doit[D_CBC_256_AES] = 1;
1.13 bcook 713: } else if (strcmp(*argv, "ghash") == 0)
1.1 jsing 714: doit[D_GHASH] = 1;
1.13 bcook 715: else if (strcmp(*argv,"aes-128-gcm") == 0)
716: doit[D_AES_128_GCM]=1;
717: else if (strcmp(*argv,"aes-256-gcm") == 0)
718: doit[D_AES_256_GCM]=1;
719: else
1.1 jsing 720: #endif
721: #ifndef OPENSSL_NO_CAMELLIA
722: if (strcmp(*argv, "camellia") == 0) {
723: doit[D_CBC_128_CML] = 1;
724: doit[D_CBC_192_CML] = 1;
725: doit[D_CBC_256_CML] = 1;
726: } else
727: #endif
1.13 bcook 728: #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
729: if (strcmp(*argv,"chacha20-poly1305") == 0)
730: doit[D_CHACHA20_POLY1305]=1;
731: else
732: #endif
1.1 jsing 733: if (strcmp(*argv, "rsa") == 0) {
734: rsa_doit[R_RSA_512] = 1;
735: rsa_doit[R_RSA_1024] = 1;
736: rsa_doit[R_RSA_2048] = 1;
737: rsa_doit[R_RSA_4096] = 1;
738: } else
739: if (strcmp(*argv, "dsa") == 0) {
740: dsa_doit[R_DSA_512] = 1;
741: dsa_doit[R_DSA_1024] = 1;
742: dsa_doit[R_DSA_2048] = 1;
743: } else
744: if (strcmp(*argv, "ecdsap160") == 0)
745: ecdsa_doit[R_EC_P160] = 2;
746: else if (strcmp(*argv, "ecdsap192") == 0)
747: ecdsa_doit[R_EC_P192] = 2;
748: else if (strcmp(*argv, "ecdsap224") == 0)
749: ecdsa_doit[R_EC_P224] = 2;
750: else if (strcmp(*argv, "ecdsap256") == 0)
751: ecdsa_doit[R_EC_P256] = 2;
752: else if (strcmp(*argv, "ecdsap384") == 0)
753: ecdsa_doit[R_EC_P384] = 2;
754: else if (strcmp(*argv, "ecdsap521") == 0)
755: ecdsa_doit[R_EC_P521] = 2;
756: else if (strcmp(*argv, "ecdsak163") == 0)
757: ecdsa_doit[R_EC_K163] = 2;
758: else if (strcmp(*argv, "ecdsak233") == 0)
759: ecdsa_doit[R_EC_K233] = 2;
760: else if (strcmp(*argv, "ecdsak283") == 0)
761: ecdsa_doit[R_EC_K283] = 2;
762: else if (strcmp(*argv, "ecdsak409") == 0)
763: ecdsa_doit[R_EC_K409] = 2;
764: else if (strcmp(*argv, "ecdsak571") == 0)
765: ecdsa_doit[R_EC_K571] = 2;
766: else if (strcmp(*argv, "ecdsab163") == 0)
767: ecdsa_doit[R_EC_B163] = 2;
768: else if (strcmp(*argv, "ecdsab233") == 0)
769: ecdsa_doit[R_EC_B233] = 2;
770: else if (strcmp(*argv, "ecdsab283") == 0)
771: ecdsa_doit[R_EC_B283] = 2;
772: else if (strcmp(*argv, "ecdsab409") == 0)
773: ecdsa_doit[R_EC_B409] = 2;
774: else if (strcmp(*argv, "ecdsab571") == 0)
775: ecdsa_doit[R_EC_B571] = 2;
776: else if (strcmp(*argv, "ecdsa") == 0) {
777: for (i = 0; i < EC_NUM; i++)
778: ecdsa_doit[i] = 1;
779: } else
780: if (strcmp(*argv, "ecdhp160") == 0)
781: ecdh_doit[R_EC_P160] = 2;
782: else if (strcmp(*argv, "ecdhp192") == 0)
783: ecdh_doit[R_EC_P192] = 2;
784: else if (strcmp(*argv, "ecdhp224") == 0)
785: ecdh_doit[R_EC_P224] = 2;
786: else if (strcmp(*argv, "ecdhp256") == 0)
787: ecdh_doit[R_EC_P256] = 2;
788: else if (strcmp(*argv, "ecdhp384") == 0)
789: ecdh_doit[R_EC_P384] = 2;
790: else if (strcmp(*argv, "ecdhp521") == 0)
791: ecdh_doit[R_EC_P521] = 2;
792: else if (strcmp(*argv, "ecdhk163") == 0)
793: ecdh_doit[R_EC_K163] = 2;
794: else if (strcmp(*argv, "ecdhk233") == 0)
795: ecdh_doit[R_EC_K233] = 2;
796: else if (strcmp(*argv, "ecdhk283") == 0)
797: ecdh_doit[R_EC_K283] = 2;
798: else if (strcmp(*argv, "ecdhk409") == 0)
799: ecdh_doit[R_EC_K409] = 2;
800: else if (strcmp(*argv, "ecdhk571") == 0)
801: ecdh_doit[R_EC_K571] = 2;
802: else if (strcmp(*argv, "ecdhb163") == 0)
803: ecdh_doit[R_EC_B163] = 2;
804: else if (strcmp(*argv, "ecdhb233") == 0)
805: ecdh_doit[R_EC_B233] = 2;
806: else if (strcmp(*argv, "ecdhb283") == 0)
807: ecdh_doit[R_EC_B283] = 2;
808: else if (strcmp(*argv, "ecdhb409") == 0)
809: ecdh_doit[R_EC_B409] = 2;
810: else if (strcmp(*argv, "ecdhb571") == 0)
811: ecdh_doit[R_EC_B571] = 2;
812: else if (strcmp(*argv, "ecdh") == 0) {
813: for (i = 0; i < EC_NUM; i++)
814: ecdh_doit[i] = 1;
815: } else
816: {
817: BIO_printf(bio_err, "Error: bad option or value\n");
818: BIO_printf(bio_err, "\n");
819: BIO_printf(bio_err, "Available values:\n");
1.15 doug 820: #ifndef OPENSSL_NO_MD4
821: BIO_printf(bio_err, "md4 ");
822: #endif
1.1 jsing 823: #ifndef OPENSSL_NO_MD5
824: BIO_printf(bio_err, "md5 ");
825: #ifndef OPENSSL_NO_HMAC
826: BIO_printf(bio_err, "hmac ");
827: #endif
828: #endif
829: #ifndef OPENSSL_NO_SHA1
830: BIO_printf(bio_err, "sha1 ");
831: #endif
832: #ifndef OPENSSL_NO_SHA256
833: BIO_printf(bio_err, "sha256 ");
834: #endif
835: #ifndef OPENSSL_NO_SHA512
836: BIO_printf(bio_err, "sha512 ");
837: #endif
838: #ifndef OPENSSL_NO_WHIRLPOOL
839: BIO_printf(bio_err, "whirlpool");
840: #endif
841: #ifndef OPENSSL_NO_RIPEMD160
842: BIO_printf(bio_err, "rmd160");
843: #endif
1.6 doug 844: #if !defined(OPENSSL_NO_MD2) || \
1.15 doug 845: !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1.1 jsing 846: !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
847: !defined(OPENSSL_NO_WHIRLPOOL)
848: BIO_printf(bio_err, "\n");
849: #endif
850:
851: #ifndef OPENSSL_NO_IDEA
852: BIO_printf(bio_err, "idea-cbc ");
853: #endif
854: #ifndef OPENSSL_NO_RC2
855: BIO_printf(bio_err, "rc2-cbc ");
856: #endif
857: #ifndef OPENSSL_NO_BF
1.13 bcook 858: BIO_printf(bio_err, "bf-cbc ");
1.1 jsing 859: #endif
860: #ifndef OPENSSL_NO_DES
1.13 bcook 861: BIO_printf(bio_err, "des-cbc des-ede3\n");
1.1 jsing 862: #endif
863: #ifndef OPENSSL_NO_AES
864: BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
1.13 bcook 865: BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige\n");
866: BIO_printf(bio_err, "aes-128-gcm aes-256-gcm ");
1.1 jsing 867: #endif
868: #ifndef OPENSSL_NO_CAMELLIA
869: BIO_printf(bio_err, "\n");
870: BIO_printf(bio_err, "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
871: #endif
872: #ifndef OPENSSL_NO_RC4
873: BIO_printf(bio_err, "rc4");
874: #endif
1.13 bcook 875: #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
876: BIO_printf(bio_err," chacha20-poly1305");
877: #endif
1.1 jsing 878: BIO_printf(bio_err, "\n");
879:
880: BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa4096\n");
881:
882: BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
883: BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
884: BIO_printf(bio_err, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1.13 bcook 885: BIO_printf(bio_err, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571 ecdsa\n");
1.1 jsing 886: BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
887: BIO_printf(bio_err, "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1.13 bcook 888: BIO_printf(bio_err, "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571 ecdh\n");
1.1 jsing 889:
890: #ifndef OPENSSL_NO_IDEA
891: BIO_printf(bio_err, "idea ");
892: #endif
893: #ifndef OPENSSL_NO_RC2
894: BIO_printf(bio_err, "rc2 ");
895: #endif
896: #ifndef OPENSSL_NO_DES
897: BIO_printf(bio_err, "des ");
898: #endif
899: #ifndef OPENSSL_NO_AES
900: BIO_printf(bio_err, "aes ");
901: #endif
902: #ifndef OPENSSL_NO_CAMELLIA
903: BIO_printf(bio_err, "camellia ");
904: #endif
905: BIO_printf(bio_err, "rsa ");
906: #ifndef OPENSSL_NO_BF
907: BIO_printf(bio_err, "blowfish");
908: #endif
909: #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
910: !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
911: !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
912: !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
913: BIO_printf(bio_err, "\n");
914: #endif
915:
916: BIO_printf(bio_err, "\n");
917: BIO_printf(bio_err, "Available options:\n");
918: BIO_printf(bio_err, "-elapsed measure time in real time instead of CPU user time.\n");
919: BIO_printf(bio_err, "-evp e use EVP e.\n");
920: BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n");
921: BIO_printf(bio_err, "-mr produce machine readable output.\n");
922: BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n");
923: goto end;
924: }
925: argc--;
926: argv++;
927: j++;
928: }
929:
930: if (multi && do_multi(multi))
931: goto show_res;
932:
933: if (j == 0) {
934: for (i = 0; i < ALGOR_NUM; i++) {
935: if (i != D_EVP)
936: doit[i] = 1;
937: }
938: for (i = 0; i < RSA_NUM; i++)
939: rsa_doit[i] = 1;
940: for (i = 0; i < DSA_NUM; i++)
941: dsa_doit[i] = 1;
942: for (i = 0; i < EC_NUM; i++)
943: ecdsa_doit[i] = 1;
944: for (i = 0; i < EC_NUM; i++)
945: ecdh_doit[i] = 1;
946: }
947: for (i = 0; i < ALGOR_NUM; i++)
948: if (doit[i])
949: pr_header++;
950:
951: if (usertime == 0 && !mr)
952: BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
953:
954: for (i = 0; i < RSA_NUM; i++) {
955: const unsigned char *p;
956:
957: p = rsa_data[i];
958: rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
959: if (rsa_key[i] == NULL) {
960: BIO_printf(bio_err, "internal error loading RSA key number %d\n", i);
961: goto end;
962: }
963: }
964:
965: dsa_key[0] = get_dsa512();
966: dsa_key[1] = get_dsa1024();
967: dsa_key[2] = get_dsa2048();
968:
969: #ifndef OPENSSL_NO_DES
970: DES_set_key_unchecked(&key, &sch);
971: DES_set_key_unchecked(&key2, &sch2);
972: DES_set_key_unchecked(&key3, &sch3);
973: #endif
974: #ifndef OPENSSL_NO_AES
975: AES_set_encrypt_key(key16, 128, &aes_ks1);
976: AES_set_encrypt_key(key24, 192, &aes_ks2);
977: AES_set_encrypt_key(key32, 256, &aes_ks3);
978: #endif
979: #ifndef OPENSSL_NO_CAMELLIA
980: Camellia_set_key(key16, 128, &camellia_ks1);
981: Camellia_set_key(ckey24, 192, &camellia_ks2);
982: Camellia_set_key(ckey32, 256, &camellia_ks3);
983: #endif
984: #ifndef OPENSSL_NO_IDEA
985: idea_set_encrypt_key(key16, &idea_ks);
986: #endif
987: #ifndef OPENSSL_NO_RC4
988: RC4_set_key(&rc4_ks, 16, key16);
989: #endif
990: #ifndef OPENSSL_NO_RC2
991: RC2_set_key(&rc2_ks, 16, key16, 128);
992: #endif
993: #ifndef OPENSSL_NO_BF
994: BF_set_key(&bf_ks, 16, key16);
995: #endif
996: #ifndef OPENSSL_NO_CAST
997: CAST_set_key(&cast_ks, 16, key16);
998: #endif
999: memset(rsa_c, 0, sizeof(rsa_c));
1000: #define COND(c) (run && count<0x7fffffff)
1001: #define COUNT(d) (count)
1002: signal(SIGALRM, sig_done);
1.15 doug 1003:
1004: #ifndef OPENSSL_NO_MD4
1005: if (doit[D_MD4]) {
1006: for (j = 0; j < SIZE_NUM; j++) {
1007: print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
1008: Time_F(START);
1009: for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
1010: EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md4[0]), NULL, EVP_md4(), NULL);
1011: d = Time_F(STOP);
1012: print_result(D_MD4, j, count, d);
1013: }
1014: }
1015: #endif
1.1 jsing 1016:
1017: #ifndef OPENSSL_NO_MD5
1018: if (doit[D_MD5]) {
1019: for (j = 0; j < SIZE_NUM; j++) {
1020: print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
1021: Time_F(START);
1022: for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
1023: EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md5[0]), NULL, EVP_get_digestbyname("md5"), NULL);
1024: d = Time_F(STOP);
1025: print_result(D_MD5, j, count, d);
1026: }
1027: }
1028: #endif
1029:
1030: #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1031: if (doit[D_HMAC]) {
1032: HMAC_CTX hctx;
1033:
1034: HMAC_CTX_init(&hctx);
1035: HMAC_Init_ex(&hctx, (unsigned char *) "This is a key...",
1036: 16, EVP_md5(), NULL);
1037:
1038: for (j = 0; j < SIZE_NUM; j++) {
1039: print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
1040: Time_F(START);
1041: for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
1042: HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
1043: HMAC_Update(&hctx, buf, lengths[j]);
1044: HMAC_Final(&hctx, &(hmac[0]), NULL);
1045: }
1046: d = Time_F(STOP);
1047: print_result(D_HMAC, j, count, d);
1048: }
1049: HMAC_CTX_cleanup(&hctx);
1050: }
1051: #endif
1052: #ifndef OPENSSL_NO_SHA
1053: if (doit[D_SHA1]) {
1054: for (j = 0; j < SIZE_NUM; j++) {
1055: print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
1056: Time_F(START);
1057: for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
1058: EVP_Digest(buf, (unsigned long) lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL);
1059: d = Time_F(STOP);
1060: print_result(D_SHA1, j, count, d);
1061: }
1062: }
1063: #ifndef OPENSSL_NO_SHA256
1064: if (doit[D_SHA256]) {
1065: for (j = 0; j < SIZE_NUM; j++) {
1066: print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
1067: Time_F(START);
1068: for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
1069: SHA256(buf, lengths[j], sha256);
1070: d = Time_F(STOP);
1071: print_result(D_SHA256, j, count, d);
1072: }
1073: }
1074: #endif
1075:
1076: #ifndef OPENSSL_NO_SHA512
1077: if (doit[D_SHA512]) {
1078: for (j = 0; j < SIZE_NUM; j++) {
1079: print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
1080: Time_F(START);
1081: for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
1082: SHA512(buf, lengths[j], sha512);
1083: d = Time_F(STOP);
1084: print_result(D_SHA512, j, count, d);
1085: }
1086: }
1087: #endif
1088: #endif
1089:
1090: #ifndef OPENSSL_NO_WHIRLPOOL
1091: if (doit[D_WHIRLPOOL]) {
1092: for (j = 0; j < SIZE_NUM; j++) {
1093: print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
1094: Time_F(START);
1095: for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
1096: WHIRLPOOL(buf, lengths[j], whirlpool);
1097: d = Time_F(STOP);
1098: print_result(D_WHIRLPOOL, j, count, d);
1099: }
1100: }
1101: #endif
1102:
1103: #ifndef OPENSSL_NO_RIPEMD
1104: if (doit[D_RMD160]) {
1105: for (j = 0; j < SIZE_NUM; j++) {
1106: print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
1107: Time_F(START);
1108: for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
1109: EVP_Digest(buf, (unsigned long) lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL);
1110: d = Time_F(STOP);
1111: print_result(D_RMD160, j, count, d);
1112: }
1113: }
1114: #endif
1115: #ifndef OPENSSL_NO_RC4
1116: if (doit[D_RC4]) {
1117: for (j = 0; j < SIZE_NUM; j++) {
1118: print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
1119: Time_F(START);
1120: for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
1121: RC4(&rc4_ks, (unsigned int) lengths[j],
1122: buf, buf);
1123: d = Time_F(STOP);
1124: print_result(D_RC4, j, count, d);
1125: }
1126: }
1127: #endif
1128: #ifndef OPENSSL_NO_DES
1129: if (doit[D_CBC_DES]) {
1130: for (j = 0; j < SIZE_NUM; j++) {
1131: print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
1132: Time_F(START);
1133: for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
1134: DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
1135: &DES_iv, DES_ENCRYPT);
1136: d = Time_F(STOP);
1137: print_result(D_CBC_DES, j, count, d);
1138: }
1139: }
1140: if (doit[D_EDE3_DES]) {
1141: for (j = 0; j < SIZE_NUM; j++) {
1142: print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
1143: Time_F(START);
1144: for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
1145: DES_ede3_cbc_encrypt(buf, buf, lengths[j],
1146: &sch, &sch2, &sch3,
1147: &DES_iv, DES_ENCRYPT);
1148: d = Time_F(STOP);
1149: print_result(D_EDE3_DES, j, count, d);
1150: }
1151: }
1152: #endif
1153: #ifndef OPENSSL_NO_AES
1154: if (doit[D_CBC_128_AES]) {
1155: for (j = 0; j < SIZE_NUM; j++) {
1156: print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]);
1157: Time_F(START);
1158: for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
1159: AES_cbc_encrypt(buf, buf,
1160: (unsigned long) lengths[j], &aes_ks1,
1161: iv, AES_ENCRYPT);
1162: d = Time_F(STOP);
1163: print_result(D_CBC_128_AES, j, count, d);
1164: }
1165: }
1166: if (doit[D_CBC_192_AES]) {
1167: for (j = 0; j < SIZE_NUM; j++) {
1168: print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]);
1169: Time_F(START);
1170: for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
1171: AES_cbc_encrypt(buf, buf,
1172: (unsigned long) lengths[j], &aes_ks2,
1173: iv, AES_ENCRYPT);
1174: d = Time_F(STOP);
1175: print_result(D_CBC_192_AES, j, count, d);
1176: }
1177: }
1178: if (doit[D_CBC_256_AES]) {
1179: for (j = 0; j < SIZE_NUM; j++) {
1180: print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]);
1181: Time_F(START);
1182: for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
1183: AES_cbc_encrypt(buf, buf,
1184: (unsigned long) lengths[j], &aes_ks3,
1185: iv, AES_ENCRYPT);
1186: d = Time_F(STOP);
1187: print_result(D_CBC_256_AES, j, count, d);
1188: }
1189: }
1190: if (doit[D_IGE_128_AES]) {
1191: for (j = 0; j < SIZE_NUM; j++) {
1192: print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]);
1193: Time_F(START);
1194: for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
1195: AES_ige_encrypt(buf, buf2,
1196: (unsigned long) lengths[j], &aes_ks1,
1197: iv, AES_ENCRYPT);
1198: d = Time_F(STOP);
1199: print_result(D_IGE_128_AES, j, count, d);
1200: }
1201: }
1202: if (doit[D_IGE_192_AES]) {
1203: for (j = 0; j < SIZE_NUM; j++) {
1204: print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]);
1205: Time_F(START);
1206: for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
1207: AES_ige_encrypt(buf, buf2,
1208: (unsigned long) lengths[j], &aes_ks2,
1209: iv, AES_ENCRYPT);
1210: d = Time_F(STOP);
1211: print_result(D_IGE_192_AES, j, count, d);
1212: }
1213: }
1214: if (doit[D_IGE_256_AES]) {
1215: for (j = 0; j < SIZE_NUM; j++) {
1216: print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]);
1217: Time_F(START);
1218: for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
1219: AES_ige_encrypt(buf, buf2,
1220: (unsigned long) lengths[j], &aes_ks3,
1221: iv, AES_ENCRYPT);
1222: d = Time_F(STOP);
1223: print_result(D_IGE_256_AES, j, count, d);
1224: }
1225: }
1226: if (doit[D_GHASH]) {
1227: GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
1228: CRYPTO_gcm128_setiv(ctx, (unsigned char *) "0123456789ab", 12);
1229:
1230: for (j = 0; j < SIZE_NUM; j++) {
1231: print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
1232: Time_F(START);
1233: for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
1234: CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
1235: d = Time_F(STOP);
1236: print_result(D_GHASH, j, count, d);
1237: }
1238: CRYPTO_gcm128_release(ctx);
1.13 bcook 1239: }
1240: if (doit[D_AES_128_GCM]) {
1241: const EVP_AEAD *aead = EVP_aead_aes_128_gcm();
1242: static const unsigned char nonce[32] = {0};
1243: size_t buf_len, nonce_len;
1244: EVP_AEAD_CTX ctx;
1245:
1246: EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1247: EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1248: nonce_len = EVP_AEAD_nonce_length(aead);
1249:
1250: for (j = 0; j < SIZE_NUM; j++) {
1251: print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
1252: Time_F(START);
1253: for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++)
1254: EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1255: nonce_len, buf, lengths[j], NULL, 0);
1256: d=Time_F(STOP);
1257: print_result(D_AES_128_GCM,j,count,d);
1258: }
1259: EVP_AEAD_CTX_cleanup(&ctx);
1260: }
1261:
1262: if (doit[D_AES_256_GCM]) {
1263: const EVP_AEAD *aead = EVP_aead_aes_256_gcm();
1264: static const unsigned char nonce[32] = {0};
1265: size_t buf_len, nonce_len;
1266: EVP_AEAD_CTX ctx;
1267:
1268: EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1269: EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1270: nonce_len = EVP_AEAD_nonce_length(aead);
1271:
1272: for (j = 0; j < SIZE_NUM; j++) {
1273: print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
1274: Time_F(START);
1275: for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++)
1276: EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1277: nonce_len, buf, lengths[j], NULL, 0);
1278: d=Time_F(STOP);
1279: print_result(D_AES_256_GCM, j, count, d);
1280: }
1281: EVP_AEAD_CTX_cleanup(&ctx);
1282: }
1283: #endif
1284: #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1285: if (doit[D_CHACHA20_POLY1305]) {
1286: const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
1287: static const unsigned char nonce[32] = {0};
1288: size_t buf_len, nonce_len;
1289: EVP_AEAD_CTX ctx;
1290:
1291: EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1292: EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1293: nonce_len = EVP_AEAD_nonce_length(aead);
1294:
1295: for (j = 0; j < SIZE_NUM; j++) {
1296: print_message(names[D_CHACHA20_POLY1305],
1297: c[D_CHACHA20_POLY1305][j], lengths[j]);
1298: Time_F(START);
1299: for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++)
1300: EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
1301: nonce_len, buf, lengths[j], NULL, 0);
1302: d=Time_F(STOP);
1303: print_result(D_CHACHA20_POLY1305, j, count, d);
1304: }
1305: EVP_AEAD_CTX_cleanup(&ctx);
1.1 jsing 1306: }
1307: #endif
1308: #ifndef OPENSSL_NO_CAMELLIA
1309: if (doit[D_CBC_128_CML]) {
1310: for (j = 0; j < SIZE_NUM; j++) {
1311: print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]);
1312: Time_F(START);
1313: for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
1314: Camellia_cbc_encrypt(buf, buf,
1315: (unsigned long) lengths[j], &camellia_ks1,
1316: iv, CAMELLIA_ENCRYPT);
1317: d = Time_F(STOP);
1318: print_result(D_CBC_128_CML, j, count, d);
1319: }
1320: }
1321: if (doit[D_CBC_192_CML]) {
1322: for (j = 0; j < SIZE_NUM; j++) {
1323: print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]);
1324: Time_F(START);
1325: for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
1326: Camellia_cbc_encrypt(buf, buf,
1327: (unsigned long) lengths[j], &camellia_ks2,
1328: iv, CAMELLIA_ENCRYPT);
1329: d = Time_F(STOP);
1330: print_result(D_CBC_192_CML, j, count, d);
1331: }
1332: }
1333: if (doit[D_CBC_256_CML]) {
1334: for (j = 0; j < SIZE_NUM; j++) {
1335: print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]);
1336: Time_F(START);
1337: for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
1338: Camellia_cbc_encrypt(buf, buf,
1339: (unsigned long) lengths[j], &camellia_ks3,
1340: iv, CAMELLIA_ENCRYPT);
1341: d = Time_F(STOP);
1342: print_result(D_CBC_256_CML, j, count, d);
1343: }
1344: }
1345: #endif
1346: #ifndef OPENSSL_NO_IDEA
1347: if (doit[D_CBC_IDEA]) {
1348: for (j = 0; j < SIZE_NUM; j++) {
1349: print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
1350: Time_F(START);
1351: for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
1352: idea_cbc_encrypt(buf, buf,
1353: (unsigned long) lengths[j], &idea_ks,
1354: iv, IDEA_ENCRYPT);
1355: d = Time_F(STOP);
1356: print_result(D_CBC_IDEA, j, count, d);
1357: }
1358: }
1359: #endif
1360: #ifndef OPENSSL_NO_RC2
1361: if (doit[D_CBC_RC2]) {
1362: for (j = 0; j < SIZE_NUM; j++) {
1363: print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
1364: Time_F(START);
1365: for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
1366: RC2_cbc_encrypt(buf, buf,
1367: (unsigned long) lengths[j], &rc2_ks,
1368: iv, RC2_ENCRYPT);
1369: d = Time_F(STOP);
1370: print_result(D_CBC_RC2, j, count, d);
1371: }
1372: }
1373: #endif
1374: #ifndef OPENSSL_NO_BF
1375: if (doit[D_CBC_BF]) {
1376: for (j = 0; j < SIZE_NUM; j++) {
1377: print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
1378: Time_F(START);
1379: for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
1380: BF_cbc_encrypt(buf, buf,
1381: (unsigned long) lengths[j], &bf_ks,
1382: iv, BF_ENCRYPT);
1383: d = Time_F(STOP);
1384: print_result(D_CBC_BF, j, count, d);
1385: }
1386: }
1387: #endif
1388: #ifndef OPENSSL_NO_CAST
1389: if (doit[D_CBC_CAST]) {
1390: for (j = 0; j < SIZE_NUM; j++) {
1391: print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
1392: Time_F(START);
1393: for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
1394: CAST_cbc_encrypt(buf, buf,
1395: (unsigned long) lengths[j], &cast_ks,
1396: iv, CAST_ENCRYPT);
1397: d = Time_F(STOP);
1398: print_result(D_CBC_CAST, j, count, d);
1399: }
1400: }
1401: #endif
1402:
1403: if (doit[D_EVP]) {
1404: for (j = 0; j < SIZE_NUM; j++) {
1405: if (evp_cipher) {
1406: EVP_CIPHER_CTX ctx;
1407: int outl;
1408:
1409: names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
1410: /*
1411: * -O3 -fschedule-insns messes up an
1412: * optimization here! names[D_EVP] somehow
1413: * becomes NULL
1414: */
1415: print_message(names[D_EVP], save_count,
1416: lengths[j]);
1417:
1418: EVP_CIPHER_CTX_init(&ctx);
1419: if (decrypt)
1420: EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1421: else
1422: EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
1423: EVP_CIPHER_CTX_set_padding(&ctx, 0);
1424:
1425: Time_F(START);
1426: if (decrypt)
1427: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1428: EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1429: else
1430: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1431: EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
1432: if (decrypt)
1433: EVP_DecryptFinal_ex(&ctx, buf, &outl);
1434: else
1435: EVP_EncryptFinal_ex(&ctx, buf, &outl);
1436: d = Time_F(STOP);
1437: EVP_CIPHER_CTX_cleanup(&ctx);
1438: }
1439: if (evp_md) {
1440: names[D_EVP] = OBJ_nid2ln(evp_md->type);
1441: print_message(names[D_EVP], save_count,
1442: lengths[j]);
1443:
1444: Time_F(START);
1445: for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1446: EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
1447:
1448: d = Time_F(STOP);
1449: }
1450: print_result(D_EVP, j, count, d);
1451: }
1452: }
1.2 jsing 1453: arc4random_buf(buf, 36);
1.1 jsing 1454: for (j = 0; j < RSA_NUM; j++) {
1455: int ret;
1456: if (!rsa_doit[j])
1457: continue;
1458: ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
1459: if (ret == 0) {
1460: BIO_printf(bio_err, "RSA sign failure. No RSA sign will be done.\n");
1461: ERR_print_errors(bio_err);
1462: rsa_count = 1;
1463: } else {
1464: pkey_print_message("private", "rsa",
1465: rsa_c[j][0], rsa_bits[j],
1466: RSA_SECONDS);
1467: /* RSA_blinding_on(rsa_key[j],NULL); */
1468: Time_F(START);
1469: for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
1470: ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
1471: &rsa_num, rsa_key[j]);
1472: if (ret == 0) {
1473: BIO_printf(bio_err,
1474: "RSA sign failure\n");
1475: ERR_print_errors(bio_err);
1476: count = 1;
1477: break;
1478: }
1479: }
1480: d = Time_F(STOP);
1481: BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
1482: : "%ld %d bit private RSA's in %.2fs\n",
1483: count, rsa_bits[j], d);
1484: rsa_results[j][0] = d / (double) count;
1485: rsa_count = count;
1486: }
1487:
1488: ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
1489: if (ret <= 0) {
1490: BIO_printf(bio_err, "RSA verify failure. No RSA verify will be done.\n");
1491: ERR_print_errors(bio_err);
1492: rsa_doit[j] = 0;
1493: } else {
1494: pkey_print_message("public", "rsa",
1495: rsa_c[j][1], rsa_bits[j],
1496: RSA_SECONDS);
1497: Time_F(START);
1498: for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
1499: ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
1500: rsa_num, rsa_key[j]);
1501: if (ret <= 0) {
1502: BIO_printf(bio_err,
1503: "RSA verify failure\n");
1504: ERR_print_errors(bio_err);
1505: count = 1;
1506: break;
1507: }
1508: }
1509: d = Time_F(STOP);
1510: BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
1511: : "%ld %d bit public RSA's in %.2fs\n",
1512: count, rsa_bits[j], d);
1513: rsa_results[j][1] = d / (double) count;
1514: }
1515:
1516: if (rsa_count <= 1) {
1517: /* if longer than 10s, don't do any more */
1518: for (j++; j < RSA_NUM; j++)
1519: rsa_doit[j] = 0;
1520: }
1521: }
1522:
1.2 jsing 1523: arc4random_buf(buf, 20);
1.1 jsing 1524: for (j = 0; j < DSA_NUM; j++) {
1525: unsigned int kk;
1526: int ret;
1527:
1528: if (!dsa_doit[j])
1529: continue;
1530: /* DSA_generate_key(dsa_key[j]); */
1531: /* DSA_sign_setup(dsa_key[j],NULL); */
1532: ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1533: &kk, dsa_key[j]);
1534: if (ret == 0) {
1535: BIO_printf(bio_err, "DSA sign failure. No DSA sign will be done.\n");
1536: ERR_print_errors(bio_err);
1537: rsa_count = 1;
1538: } else {
1539: pkey_print_message("sign", "dsa",
1540: dsa_c[j][0], dsa_bits[j],
1541: DSA_SECONDS);
1542: Time_F(START);
1543: for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
1544: ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
1545: &kk, dsa_key[j]);
1546: if (ret == 0) {
1547: BIO_printf(bio_err,
1548: "DSA sign failure\n");
1549: ERR_print_errors(bio_err);
1550: count = 1;
1551: break;
1552: }
1553: }
1554: d = Time_F(STOP);
1555: BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n"
1556: : "%ld %d bit DSA signs in %.2fs\n",
1557: count, dsa_bits[j], d);
1558: dsa_results[j][0] = d / (double) count;
1559: rsa_count = count;
1560: }
1561:
1562: ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1563: kk, dsa_key[j]);
1564: if (ret <= 0) {
1565: BIO_printf(bio_err, "DSA verify failure. No DSA verify will be done.\n");
1566: ERR_print_errors(bio_err);
1567: dsa_doit[j] = 0;
1568: } else {
1569: pkey_print_message("verify", "dsa",
1570: dsa_c[j][1], dsa_bits[j],
1571: DSA_SECONDS);
1572: Time_F(START);
1573: for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
1574: ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
1575: kk, dsa_key[j]);
1576: if (ret <= 0) {
1577: BIO_printf(bio_err,
1578: "DSA verify failure\n");
1579: ERR_print_errors(bio_err);
1580: count = 1;
1581: break;
1582: }
1583: }
1584: d = Time_F(STOP);
1585: BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n"
1586: : "%ld %d bit DSA verify in %.2fs\n",
1587: count, dsa_bits[j], d);
1588: dsa_results[j][1] = d / (double) count;
1589: }
1590:
1591: if (rsa_count <= 1) {
1592: /* if longer than 10s, don't do any more */
1593: for (j++; j < DSA_NUM; j++)
1594: dsa_doit[j] = 0;
1595: }
1596: }
1597:
1598: for (j = 0; j < EC_NUM; j++) {
1599: int ret;
1600:
1601: if (!ecdsa_doit[j])
1602: continue; /* Ignore Curve */
1603: ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1604: if (ecdsa[j] == NULL) {
1605: BIO_printf(bio_err, "ECDSA failure.\n");
1606: ERR_print_errors(bio_err);
1607: rsa_count = 1;
1608: } else {
1609: EC_KEY_precompute_mult(ecdsa[j], NULL);
1.5 doug 1610:
1.1 jsing 1611: /* Perform ECDSA signature test */
1612: EC_KEY_generate_key(ecdsa[j]);
1613: ret = ECDSA_sign(0, buf, 20, ecdsasig,
1614: &ecdsasiglen, ecdsa[j]);
1615: if (ret == 0) {
1616: BIO_printf(bio_err, "ECDSA sign failure. No ECDSA sign will be done.\n");
1617: ERR_print_errors(bio_err);
1618: rsa_count = 1;
1619: } else {
1620: pkey_print_message("sign", "ecdsa",
1621: ecdsa_c[j][0],
1622: test_curves_bits[j],
1623: ECDSA_SECONDS);
1624:
1625: Time_F(START);
1626: for (count = 0, run = 1; COND(ecdsa_c[j][0]);
1627: count++) {
1628: ret = ECDSA_sign(0, buf, 20,
1629: ecdsasig, &ecdsasiglen,
1630: ecdsa[j]);
1631: if (ret == 0) {
1632: BIO_printf(bio_err, "ECDSA sign failure\n");
1633: ERR_print_errors(bio_err);
1634: count = 1;
1635: break;
1636: }
1637: }
1638: d = Time_F(STOP);
1639:
1640: BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
1641: "%ld %d bit ECDSA signs in %.2fs \n",
1642: count, test_curves_bits[j], d);
1643: ecdsa_results[j][0] = d / (double) count;
1644: rsa_count = count;
1645: }
1646:
1647: /* Perform ECDSA verification test */
1648: ret = ECDSA_verify(0, buf, 20, ecdsasig,
1649: ecdsasiglen, ecdsa[j]);
1650: if (ret != 1) {
1651: BIO_printf(bio_err, "ECDSA verify failure. No ECDSA verify will be done.\n");
1652: ERR_print_errors(bio_err);
1653: ecdsa_doit[j] = 0;
1654: } else {
1655: pkey_print_message("verify", "ecdsa",
1656: ecdsa_c[j][1],
1657: test_curves_bits[j],
1658: ECDSA_SECONDS);
1659: Time_F(START);
1660: for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
1661: ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
1662: if (ret != 1) {
1663: BIO_printf(bio_err, "ECDSA verify failure\n");
1664: ERR_print_errors(bio_err);
1665: count = 1;
1666: break;
1667: }
1668: }
1669: d = Time_F(STOP);
1670: BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n"
1671: : "%ld %d bit ECDSA verify in %.2fs\n",
1672: count, test_curves_bits[j], d);
1673: ecdsa_results[j][1] = d / (double) count;
1674: }
1675:
1676: if (rsa_count <= 1) {
1677: /* if longer than 10s, don't do any more */
1678: for (j++; j < EC_NUM; j++)
1679: ecdsa_doit[j] = 0;
1680: }
1681: }
1682: }
1683:
1684: for (j = 0; j < EC_NUM; j++) {
1685: if (!ecdh_doit[j])
1686: continue;
1687: ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1688: ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
1689: if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
1690: BIO_printf(bio_err, "ECDH failure.\n");
1691: ERR_print_errors(bio_err);
1692: rsa_count = 1;
1693: } else {
1694: /* generate two ECDH key pairs */
1695: if (!EC_KEY_generate_key(ecdh_a[j]) ||
1696: !EC_KEY_generate_key(ecdh_b[j])) {
1697: BIO_printf(bio_err, "ECDH key generation failure.\n");
1698: ERR_print_errors(bio_err);
1699: rsa_count = 1;
1700: } else {
1701: /*
1702: * If field size is not more than 24 octets,
1703: * then use SHA-1 hash of result; otherwise,
1704: * use result (see section 4.8 of
1705: * draft-ietf-tls-ecc-03.txt).
1706: */
1707: int field_size, outlen;
1708: void *(*kdf) (const void *in, size_t inlen, void *out, size_t * xoutlen);
1709: field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
1710: if (field_size <= 24 * 8) {
1711: outlen = KDF1_SHA1_len;
1712: kdf = KDF1_SHA1;
1713: } else {
1714: outlen = (field_size + 7) / 8;
1715: kdf = NULL;
1716: }
1717: secret_size_a = ECDH_compute_key(secret_a, outlen,
1718: EC_KEY_get0_public_key(ecdh_b[j]),
1719: ecdh_a[j], kdf);
1720: secret_size_b = ECDH_compute_key(secret_b, outlen,
1721: EC_KEY_get0_public_key(ecdh_a[j]),
1722: ecdh_b[j], kdf);
1723: if (secret_size_a != secret_size_b)
1724: ecdh_checks = 0;
1725: else
1726: ecdh_checks = 1;
1727:
1728: for (secret_idx = 0;
1729: (secret_idx < secret_size_a)
1730: && (ecdh_checks == 1);
1731: secret_idx++) {
1732: if (secret_a[secret_idx] != secret_b[secret_idx])
1733: ecdh_checks = 0;
1734: }
1735:
1736: if (ecdh_checks == 0) {
1.8 doug 1737: BIO_printf(bio_err,
1738: "ECDH computations don't match.\n");
1.1 jsing 1739: ERR_print_errors(bio_err);
1740: rsa_count = 1;
1.8 doug 1741: } else {
1742: pkey_print_message("", "ecdh",
1743: ecdh_c[j][0],
1744: test_curves_bits[j],
1745: ECDH_SECONDS);
1746: Time_F(START);
1747: for (count = 0, run = 1;
1748: COND(ecdh_c[j][0]); count++) {
1749: ECDH_compute_key(secret_a,
1750: outlen,
1751: EC_KEY_get0_public_key(ecdh_b[j]),
1752: ecdh_a[j], kdf);
1753: }
1754: d = Time_F(STOP);
1755: BIO_printf(bio_err, mr
1756: ? "+R7:%ld:%d:%.2f\n"
1757: : "%ld %d-bit ECDH ops in %.2fs\n",
1758: count, test_curves_bits[j], d);
1759: ecdh_results[j][0] = d / (double) count;
1760: rsa_count = count;
1.1 jsing 1761: }
1762: }
1763: }
1764:
1765:
1766: if (rsa_count <= 1) {
1767: /* if longer than 10s, don't do any more */
1768: for (j++; j < EC_NUM; j++)
1769: ecdh_doit[j] = 0;
1770: }
1771: }
1772: show_res:
1773: if (!mr) {
1774: fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
1775: fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
1776: printf("options:");
1777: printf("%s ", BN_options());
1778: #ifndef OPENSSL_NO_RC4
1779: printf("%s ", RC4_options());
1780: #endif
1781: #ifndef OPENSSL_NO_DES
1782: printf("%s ", DES_options());
1783: #endif
1784: #ifndef OPENSSL_NO_AES
1785: printf("%s ", AES_options());
1786: #endif
1787: #ifndef OPENSSL_NO_IDEA
1788: printf("%s ", idea_options());
1789: #endif
1790: #ifndef OPENSSL_NO_BF
1791: printf("%s ", BF_options());
1792: #endif
1793: fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
1794: }
1795: if (pr_header) {
1796: if (mr)
1797: fprintf(stdout, "+H");
1798: else {
1799: fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n");
1800: fprintf(stdout, "type ");
1801: }
1802: for (j = 0; j < SIZE_NUM; j++)
1803: fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
1804: fprintf(stdout, "\n");
1805: }
1806: for (k = 0; k < ALGOR_NUM; k++) {
1807: if (!doit[k])
1808: continue;
1809: if (mr)
1810: fprintf(stdout, "+F:%d:%s", k, names[k]);
1811: else
1812: fprintf(stdout, "%-13s", names[k]);
1813: for (j = 0; j < SIZE_NUM; j++) {
1814: if (results[k][j] > 10000 && !mr)
1815: fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
1816: else
1817: fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
1818: }
1819: fprintf(stdout, "\n");
1820: }
1821: j = 1;
1822: for (k = 0; k < RSA_NUM; k++) {
1823: if (!rsa_doit[k])
1824: continue;
1825: if (j && !mr) {
1826: printf("%18ssign verify sign/s verify/s\n", " ");
1827: j = 0;
1828: }
1829: if (mr)
1830: fprintf(stdout, "+F2:%u:%u:%f:%f\n",
1831: k, rsa_bits[k], rsa_results[k][0],
1832: rsa_results[k][1]);
1833: else
1834: fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1835: rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1836: 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
1837: }
1838: j = 1;
1839: for (k = 0; k < DSA_NUM; k++) {
1840: if (!dsa_doit[k])
1841: continue;
1842: if (j && !mr) {
1843: printf("%18ssign verify sign/s verify/s\n", " ");
1844: j = 0;
1845: }
1846: if (mr)
1847: fprintf(stdout, "+F3:%u:%u:%f:%f\n",
1848: k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
1849: else
1850: fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
1851: dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1852: 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
1853: }
1854: j = 1;
1855: for (k = 0; k < EC_NUM; k++) {
1856: if (!ecdsa_doit[k])
1857: continue;
1858: if (j && !mr) {
1859: printf("%30ssign verify sign/s verify/s\n", " ");
1860: j = 0;
1861: }
1862: if (mr)
1863: fprintf(stdout, "+F4:%u:%u:%f:%f\n",
1864: k, test_curves_bits[k],
1865: ecdsa_results[k][0], ecdsa_results[k][1]);
1866: else
1867: fprintf(stdout,
1868: "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
1869: test_curves_bits[k],
1870: test_curves_names[k],
1871: ecdsa_results[k][0], ecdsa_results[k][1],
1872: 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
1873: }
1874:
1875:
1876: j = 1;
1877: for (k = 0; k < EC_NUM; k++) {
1878: if (!ecdh_doit[k])
1879: continue;
1880: if (j && !mr) {
1881: printf("%30sop op/s\n", " ");
1882: j = 0;
1883: }
1884: if (mr)
1885: fprintf(stdout, "+F5:%u:%u:%f:%f\n",
1886: k, test_curves_bits[k],
1887: ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1888:
1889: else
1890: fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
1891: test_curves_bits[k],
1892: test_curves_names[k],
1893: ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
1894: }
1895:
1896: mret = 0;
1897:
1898: end:
1899: ERR_print_errors(bio_err);
1900: free(buf);
1901: free(buf2);
1902: for (i = 0; i < RSA_NUM; i++)
1903: if (rsa_key[i] != NULL)
1904: RSA_free(rsa_key[i]);
1905: for (i = 0; i < DSA_NUM; i++)
1906: if (dsa_key[i] != NULL)
1907: DSA_free(dsa_key[i]);
1908:
1909: for (i = 0; i < EC_NUM; i++)
1910: if (ecdsa[i] != NULL)
1911: EC_KEY_free(ecdsa[i]);
1912: for (i = 0; i < EC_NUM; i++) {
1913: if (ecdh_a[i] != NULL)
1914: EC_KEY_free(ecdh_a[i]);
1915: if (ecdh_b[i] != NULL)
1916: EC_KEY_free(ecdh_b[i]);
1917: }
1918:
1919:
1920: return (mret);
1921: }
1922:
1923: static void
1924: print_message(const char *s, long num, int length)
1925: {
1926: BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
1927: : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
1928: (void) BIO_flush(bio_err);
1929: alarm(SECONDS);
1930: }
1931:
1932: static void
1933: pkey_print_message(const char *str, const char *str2, long num,
1934: int bits, int tm)
1935: {
1936: BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n"
1937: : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
1938: (void) BIO_flush(bio_err);
1939: alarm(tm);
1940: }
1941:
1942: static void
1943: print_result(int alg, int run_no, int count, double time_used)
1944: {
1945: BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
1946: : "%d %s's in %.2fs\n", count, names[alg], time_used);
1947: results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
1948: }
1949:
1950: static char *
1951: sstrsep(char **string, const char *delim)
1952: {
1953: char isdelim[256];
1954: char *token = *string;
1955:
1956: if (**string == 0)
1957: return NULL;
1958:
1959: memset(isdelim, 0, sizeof isdelim);
1960: isdelim[0] = 1;
1961:
1962: while (*delim) {
1963: isdelim[(unsigned char) (*delim)] = 1;
1964: delim++;
1965: }
1966:
1967: while (!isdelim[(unsigned char) (**string)]) {
1968: (*string)++;
1969: }
1970:
1971: if (**string) {
1972: **string = 0;
1973: (*string)++;
1974: }
1975: return token;
1976: }
1977:
1978: static int
1979: do_multi(int multi)
1980: {
1981: int n;
1982: int fd[2];
1983: int *fds;
1984: static char sep[] = ":";
1985: const char *errstr = NULL;
1986:
1987: fds = reallocarray(NULL, multi, sizeof *fds);
1.4 lteo 1988: if (fds == NULL) {
1989: fprintf(stderr, "reallocarray failure\n");
1990: exit(1);
1991: }
1.1 jsing 1992: for (n = 0; n < multi; ++n) {
1993: if (pipe(fd) == -1) {
1994: fprintf(stderr, "pipe failure\n");
1995: exit(1);
1996: }
1997: fflush(stdout);
1998: fflush(stderr);
1999: if (fork()) {
2000: close(fd[1]);
2001: fds[n] = fd[0];
2002: } else {
2003: close(fd[0]);
2004: close(1);
2005: if (dup(fd[1]) == -1) {
2006: fprintf(stderr, "dup failed\n");
2007: exit(1);
2008: }
2009: close(fd[1]);
2010: mr = 1;
2011: usertime = 0;
2012: free(fds);
2013: return 0;
2014: }
2015: printf("Forked child %d\n", n);
2016: }
2017:
2018: /* for now, assume the pipe is long enough to take all the output */
2019: for (n = 0; n < multi; ++n) {
2020: FILE *f;
2021: char buf[1024];
2022: char *p;
2023:
2024: f = fdopen(fds[n], "r");
2025: while (fgets(buf, sizeof buf, f)) {
2026: p = strchr(buf, '\n');
2027: if (p)
2028: *p = '\0';
2029: if (buf[0] != '+') {
2030: fprintf(stderr, "Don't understand line '%s' from child %d\n",
2031: buf, n);
2032: continue;
2033: }
2034: printf("Got: %s from %d\n", buf, n);
2035: if (!strncmp(buf, "+F:", 3)) {
2036: int alg;
2037: int j;
2038:
2039: p = buf + 3;
2040: alg = strtonum(sstrsep(&p, sep),
2041: 0, ALGOR_NUM - 1, &errstr);
2042: sstrsep(&p, sep);
2043: for (j = 0; j < SIZE_NUM; ++j)
2044: results[alg][j] += atof(sstrsep(&p, sep));
2045: } else if (!strncmp(buf, "+F2:", 4)) {
2046: int k;
2047: double d;
2048:
2049: p = buf + 4;
2050: k = strtonum(sstrsep(&p, sep),
2051: 0, ALGOR_NUM - 1, &errstr);
2052: sstrsep(&p, sep);
2053:
2054: d = atof(sstrsep(&p, sep));
2055: if (n)
2056: rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2057: else
2058: rsa_results[k][0] = d;
2059:
2060: d = atof(sstrsep(&p, sep));
2061: if (n)
2062: rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2063: else
2064: rsa_results[k][1] = d;
2065: } else if (!strncmp(buf, "+F2:", 4)) {
2066: int k;
2067: double d;
2068:
2069: p = buf + 4;
2070: k = strtonum(sstrsep(&p, sep),
2071: 0, ALGOR_NUM - 1, &errstr);
2072: sstrsep(&p, sep);
2073:
2074: d = atof(sstrsep(&p, sep));
2075: if (n)
2076: rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
2077: else
2078: rsa_results[k][0] = d;
2079:
2080: d = atof(sstrsep(&p, sep));
2081: if (n)
2082: rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
2083: else
2084: rsa_results[k][1] = d;
2085: }
2086: else if (!strncmp(buf, "+F3:", 4)) {
2087: int k;
2088: double d;
2089:
2090: p = buf + 4;
2091: k = strtonum(sstrsep(&p, sep),
2092: 0, ALGOR_NUM - 1, &errstr);
2093: sstrsep(&p, sep);
2094:
2095: d = atof(sstrsep(&p, sep));
2096: if (n)
2097: dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
2098: else
2099: dsa_results[k][0] = d;
2100:
2101: d = atof(sstrsep(&p, sep));
2102: if (n)
2103: dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
2104: else
2105: dsa_results[k][1] = d;
2106: }
2107: else if (!strncmp(buf, "+F4:", 4)) {
2108: int k;
2109: double d;
2110:
2111: p = buf + 4;
2112: k = strtonum(sstrsep(&p, sep),
2113: 0, ALGOR_NUM - 1, &errstr);
2114: sstrsep(&p, sep);
2115:
2116: d = atof(sstrsep(&p, sep));
2117: if (n)
2118: ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
2119: else
2120: ecdsa_results[k][0] = d;
2121:
2122: d = atof(sstrsep(&p, sep));
2123: if (n)
2124: ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
2125: else
2126: ecdsa_results[k][1] = d;
2127: }
2128:
2129: else if (!strncmp(buf, "+F5:", 4)) {
2130: int k;
2131: double d;
2132:
2133: p = buf + 4;
2134: k = strtonum(sstrsep(&p, sep),
2135: 0, ALGOR_NUM - 1, &errstr);
2136: sstrsep(&p, sep);
2137:
2138: d = atof(sstrsep(&p, sep));
2139: if (n)
2140: ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
2141: else
2142: ecdh_results[k][0] = d;
2143:
2144: }
2145:
2146: else if (!strncmp(buf, "+H:", 3)) {
2147: } else
2148: fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
2149: }
2150:
2151: fclose(f);
2152: }
2153: free(fds);
2154: return 1;
2155: }
2156: #endif