[BACK]Return to speed.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / openssl

Annotation of src/usr.bin/openssl/speed.c, Revision 1.5

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