[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.11

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