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

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