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