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

1.26    ! tb          1: /* $OpenBSD: speed.c,v 1.25 2021/12/26 15:28:37 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.24      tb       1048:                                HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
                   1049:                                HMAC_Update(hctx, buf, lengths[j]);
                   1050:                                HMAC_Final(hctx, &(hmac[0]), NULL);
1.1       jsing    1051:                        }
                   1052:                        d = Time_F(STOP);
                   1053:                        print_result(D_HMAC, j, count, d);
                   1054:                }
1.24      tb       1055:                HMAC_CTX_free(hctx);
1.1       jsing    1056:        }
                   1057: #endif
                   1058: #ifndef OPENSSL_NO_SHA
                   1059:        if (doit[D_SHA1]) {
                   1060:                for (j = 0; j < SIZE_NUM; j++) {
                   1061:                        print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
                   1062:                        Time_F(START);
                   1063:                        for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
                   1064:                                EVP_Digest(buf, (unsigned long) lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL);
                   1065:                        d = Time_F(STOP);
                   1066:                        print_result(D_SHA1, j, count, d);
                   1067:                }
                   1068:        }
                   1069: #ifndef OPENSSL_NO_SHA256
                   1070:        if (doit[D_SHA256]) {
                   1071:                for (j = 0; j < SIZE_NUM; j++) {
                   1072:                        print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
                   1073:                        Time_F(START);
                   1074:                        for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
                   1075:                                SHA256(buf, lengths[j], sha256);
                   1076:                        d = Time_F(STOP);
                   1077:                        print_result(D_SHA256, j, count, d);
                   1078:                }
                   1079:        }
                   1080: #endif
                   1081:
                   1082: #ifndef OPENSSL_NO_SHA512
                   1083:        if (doit[D_SHA512]) {
                   1084:                for (j = 0; j < SIZE_NUM; j++) {
                   1085:                        print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
                   1086:                        Time_F(START);
                   1087:                        for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
                   1088:                                SHA512(buf, lengths[j], sha512);
                   1089:                        d = Time_F(STOP);
                   1090:                        print_result(D_SHA512, j, count, d);
                   1091:                }
                   1092:        }
                   1093: #endif
                   1094: #endif
                   1095:
                   1096: #ifndef OPENSSL_NO_WHIRLPOOL
                   1097:        if (doit[D_WHIRLPOOL]) {
                   1098:                for (j = 0; j < SIZE_NUM; j++) {
                   1099:                        print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
                   1100:                        Time_F(START);
                   1101:                        for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
                   1102:                                WHIRLPOOL(buf, lengths[j], whirlpool);
                   1103:                        d = Time_F(STOP);
                   1104:                        print_result(D_WHIRLPOOL, j, count, d);
                   1105:                }
                   1106:        }
                   1107: #endif
                   1108:
                   1109: #ifndef OPENSSL_NO_RIPEMD
                   1110:        if (doit[D_RMD160]) {
                   1111:                for (j = 0; j < SIZE_NUM; j++) {
                   1112:                        print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
                   1113:                        Time_F(START);
                   1114:                        for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
                   1115:                                EVP_Digest(buf, (unsigned long) lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL);
                   1116:                        d = Time_F(STOP);
                   1117:                        print_result(D_RMD160, j, count, d);
                   1118:                }
                   1119:        }
                   1120: #endif
                   1121: #ifndef OPENSSL_NO_RC4
                   1122:        if (doit[D_RC4]) {
                   1123:                for (j = 0; j < SIZE_NUM; j++) {
                   1124:                        print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
                   1125:                        Time_F(START);
                   1126:                        for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
                   1127:                                RC4(&rc4_ks, (unsigned int) lengths[j],
                   1128:                                    buf, buf);
                   1129:                        d = Time_F(STOP);
                   1130:                        print_result(D_RC4, j, count, d);
                   1131:                }
                   1132:        }
                   1133: #endif
                   1134: #ifndef OPENSSL_NO_DES
                   1135:        if (doit[D_CBC_DES]) {
                   1136:                for (j = 0; j < SIZE_NUM; j++) {
                   1137:                        print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
                   1138:                        Time_F(START);
                   1139:                        for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
                   1140:                                DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
                   1141:                                    &DES_iv, DES_ENCRYPT);
                   1142:                        d = Time_F(STOP);
                   1143:                        print_result(D_CBC_DES, j, count, d);
                   1144:                }
                   1145:        }
                   1146:        if (doit[D_EDE3_DES]) {
                   1147:                for (j = 0; j < SIZE_NUM; j++) {
                   1148:                        print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
                   1149:                        Time_F(START);
                   1150:                        for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
                   1151:                                DES_ede3_cbc_encrypt(buf, buf, lengths[j],
                   1152:                                    &sch, &sch2, &sch3,
                   1153:                                    &DES_iv, DES_ENCRYPT);
                   1154:                        d = Time_F(STOP);
                   1155:                        print_result(D_EDE3_DES, j, count, d);
                   1156:                }
                   1157:        }
                   1158: #endif
                   1159: #ifndef OPENSSL_NO_AES
                   1160:        if (doit[D_CBC_128_AES]) {
                   1161:                for (j = 0; j < SIZE_NUM; j++) {
                   1162:                        print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]);
                   1163:                        Time_F(START);
                   1164:                        for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
                   1165:                                AES_cbc_encrypt(buf, buf,
                   1166:                                    (unsigned long) lengths[j], &aes_ks1,
                   1167:                                    iv, AES_ENCRYPT);
                   1168:                        d = Time_F(STOP);
                   1169:                        print_result(D_CBC_128_AES, j, count, d);
                   1170:                }
                   1171:        }
                   1172:        if (doit[D_CBC_192_AES]) {
                   1173:                for (j = 0; j < SIZE_NUM; j++) {
                   1174:                        print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]);
                   1175:                        Time_F(START);
                   1176:                        for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
                   1177:                                AES_cbc_encrypt(buf, buf,
                   1178:                                    (unsigned long) lengths[j], &aes_ks2,
                   1179:                                    iv, AES_ENCRYPT);
                   1180:                        d = Time_F(STOP);
                   1181:                        print_result(D_CBC_192_AES, j, count, d);
                   1182:                }
                   1183:        }
                   1184:        if (doit[D_CBC_256_AES]) {
                   1185:                for (j = 0; j < SIZE_NUM; j++) {
                   1186:                        print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]);
                   1187:                        Time_F(START);
                   1188:                        for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
                   1189:                                AES_cbc_encrypt(buf, buf,
                   1190:                                    (unsigned long) lengths[j], &aes_ks3,
                   1191:                                    iv, AES_ENCRYPT);
                   1192:                        d = Time_F(STOP);
                   1193:                        print_result(D_CBC_256_AES, j, count, d);
                   1194:                }
                   1195:        }
                   1196:        if (doit[D_IGE_128_AES]) {
                   1197:                for (j = 0; j < SIZE_NUM; j++) {
                   1198:                        print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]);
                   1199:                        Time_F(START);
                   1200:                        for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
                   1201:                                AES_ige_encrypt(buf, buf2,
                   1202:                                    (unsigned long) lengths[j], &aes_ks1,
                   1203:                                    iv, AES_ENCRYPT);
                   1204:                        d = Time_F(STOP);
                   1205:                        print_result(D_IGE_128_AES, j, count, d);
                   1206:                }
                   1207:        }
                   1208:        if (doit[D_IGE_192_AES]) {
                   1209:                for (j = 0; j < SIZE_NUM; j++) {
                   1210:                        print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]);
                   1211:                        Time_F(START);
                   1212:                        for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
                   1213:                                AES_ige_encrypt(buf, buf2,
                   1214:                                    (unsigned long) lengths[j], &aes_ks2,
                   1215:                                    iv, AES_ENCRYPT);
                   1216:                        d = Time_F(STOP);
                   1217:                        print_result(D_IGE_192_AES, j, count, d);
                   1218:                }
                   1219:        }
                   1220:        if (doit[D_IGE_256_AES]) {
                   1221:                for (j = 0; j < SIZE_NUM; j++) {
                   1222:                        print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]);
                   1223:                        Time_F(START);
                   1224:                        for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
                   1225:                                AES_ige_encrypt(buf, buf2,
                   1226:                                    (unsigned long) lengths[j], &aes_ks3,
                   1227:                                    iv, AES_ENCRYPT);
                   1228:                        d = Time_F(STOP);
                   1229:                        print_result(D_IGE_256_AES, j, count, d);
                   1230:                }
                   1231:        }
                   1232:        if (doit[D_GHASH]) {
                   1233:                GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
                   1234:                CRYPTO_gcm128_setiv(ctx, (unsigned char *) "0123456789ab", 12);
                   1235:
                   1236:                for (j = 0; j < SIZE_NUM; j++) {
                   1237:                        print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
                   1238:                        Time_F(START);
                   1239:                        for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
                   1240:                                CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
                   1241:                        d = Time_F(STOP);
                   1242:                        print_result(D_GHASH, j, count, d);
                   1243:                }
                   1244:                CRYPTO_gcm128_release(ctx);
1.13      bcook    1245:        }
                   1246:        if (doit[D_AES_128_GCM]) {
                   1247:                const EVP_AEAD *aead = EVP_aead_aes_128_gcm();
                   1248:                static const unsigned char nonce[32] = {0};
                   1249:                size_t buf_len, nonce_len;
                   1250:                EVP_AEAD_CTX ctx;
                   1251:
                   1252:                EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
                   1253:                    EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
                   1254:                nonce_len = EVP_AEAD_nonce_length(aead);
                   1255:
                   1256:                for (j = 0; j < SIZE_NUM; j++) {
                   1257:                        print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
                   1258:                        Time_F(START);
                   1259:                        for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++)
                   1260:                                EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
                   1261:                                    nonce_len, buf, lengths[j], NULL, 0);
                   1262:                        d=Time_F(STOP);
                   1263:                        print_result(D_AES_128_GCM,j,count,d);
                   1264:                }
                   1265:                EVP_AEAD_CTX_cleanup(&ctx);
                   1266:        }
                   1267:
                   1268:        if (doit[D_AES_256_GCM]) {
                   1269:                const EVP_AEAD *aead = EVP_aead_aes_256_gcm();
                   1270:                static const unsigned char nonce[32] = {0};
                   1271:                size_t buf_len, nonce_len;
                   1272:                EVP_AEAD_CTX ctx;
                   1273:
                   1274:                EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
                   1275:                EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
                   1276:                nonce_len = EVP_AEAD_nonce_length(aead);
                   1277:
                   1278:                for (j = 0; j < SIZE_NUM; j++) {
                   1279:                        print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
                   1280:                        Time_F(START);
                   1281:                        for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++)
                   1282:                                EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
                   1283:                                    nonce_len, buf, lengths[j], NULL, 0);
                   1284:                        d=Time_F(STOP);
                   1285:                        print_result(D_AES_256_GCM, j, count, d);
                   1286:                }
                   1287:                EVP_AEAD_CTX_cleanup(&ctx);
                   1288:        }
                   1289: #endif
                   1290: #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
                   1291:        if (doit[D_CHACHA20_POLY1305]) {
                   1292:                const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
                   1293:                static const unsigned char nonce[32] = {0};
                   1294:                size_t buf_len, nonce_len;
                   1295:                EVP_AEAD_CTX ctx;
                   1296:
                   1297:                EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
                   1298:                    EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
                   1299:                nonce_len = EVP_AEAD_nonce_length(aead);
                   1300:
                   1301:                for (j = 0; j < SIZE_NUM; j++) {
                   1302:                        print_message(names[D_CHACHA20_POLY1305],
                   1303:                            c[D_CHACHA20_POLY1305][j], lengths[j]);
                   1304:                        Time_F(START);
                   1305:                        for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++)
                   1306:                                EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
                   1307:                                    nonce_len, buf, lengths[j], NULL, 0);
                   1308:                        d=Time_F(STOP);
                   1309:                        print_result(D_CHACHA20_POLY1305, j, count, d);
                   1310:                }
                   1311:                EVP_AEAD_CTX_cleanup(&ctx);
1.1       jsing    1312:        }
                   1313: #endif
                   1314: #ifndef OPENSSL_NO_CAMELLIA
                   1315:        if (doit[D_CBC_128_CML]) {
                   1316:                for (j = 0; j < SIZE_NUM; j++) {
                   1317:                        print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]);
                   1318:                        Time_F(START);
                   1319:                        for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
                   1320:                                Camellia_cbc_encrypt(buf, buf,
                   1321:                                    (unsigned long) lengths[j], &camellia_ks1,
                   1322:                                    iv, CAMELLIA_ENCRYPT);
                   1323:                        d = Time_F(STOP);
                   1324:                        print_result(D_CBC_128_CML, j, count, d);
                   1325:                }
                   1326:        }
                   1327:        if (doit[D_CBC_192_CML]) {
                   1328:                for (j = 0; j < SIZE_NUM; j++) {
                   1329:                        print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]);
                   1330:                        Time_F(START);
                   1331:                        for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
                   1332:                                Camellia_cbc_encrypt(buf, buf,
                   1333:                                    (unsigned long) lengths[j], &camellia_ks2,
                   1334:                                    iv, CAMELLIA_ENCRYPT);
                   1335:                        d = Time_F(STOP);
                   1336:                        print_result(D_CBC_192_CML, j, count, d);
                   1337:                }
                   1338:        }
                   1339:        if (doit[D_CBC_256_CML]) {
                   1340:                for (j = 0; j < SIZE_NUM; j++) {
                   1341:                        print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]);
                   1342:                        Time_F(START);
                   1343:                        for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
                   1344:                                Camellia_cbc_encrypt(buf, buf,
                   1345:                                    (unsigned long) lengths[j], &camellia_ks3,
                   1346:                                    iv, CAMELLIA_ENCRYPT);
                   1347:                        d = Time_F(STOP);
                   1348:                        print_result(D_CBC_256_CML, j, count, d);
                   1349:                }
                   1350:        }
                   1351: #endif
                   1352: #ifndef OPENSSL_NO_IDEA
                   1353:        if (doit[D_CBC_IDEA]) {
                   1354:                for (j = 0; j < SIZE_NUM; j++) {
                   1355:                        print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
                   1356:                        Time_F(START);
                   1357:                        for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
                   1358:                                idea_cbc_encrypt(buf, buf,
                   1359:                                    (unsigned long) lengths[j], &idea_ks,
                   1360:                                    iv, IDEA_ENCRYPT);
                   1361:                        d = Time_F(STOP);
                   1362:                        print_result(D_CBC_IDEA, j, count, d);
                   1363:                }
                   1364:        }
                   1365: #endif
                   1366: #ifndef OPENSSL_NO_RC2
                   1367:        if (doit[D_CBC_RC2]) {
                   1368:                for (j = 0; j < SIZE_NUM; j++) {
                   1369:                        print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
                   1370:                        Time_F(START);
                   1371:                        for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
                   1372:                                RC2_cbc_encrypt(buf, buf,
                   1373:                                    (unsigned long) lengths[j], &rc2_ks,
                   1374:                                    iv, RC2_ENCRYPT);
                   1375:                        d = Time_F(STOP);
                   1376:                        print_result(D_CBC_RC2, j, count, d);
                   1377:                }
                   1378:        }
                   1379: #endif
                   1380: #ifndef OPENSSL_NO_BF
                   1381:        if (doit[D_CBC_BF]) {
                   1382:                for (j = 0; j < SIZE_NUM; j++) {
                   1383:                        print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
                   1384:                        Time_F(START);
                   1385:                        for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
                   1386:                                BF_cbc_encrypt(buf, buf,
                   1387:                                    (unsigned long) lengths[j], &bf_ks,
                   1388:                                    iv, BF_ENCRYPT);
                   1389:                        d = Time_F(STOP);
                   1390:                        print_result(D_CBC_BF, j, count, d);
                   1391:                }
                   1392:        }
                   1393: #endif
                   1394: #ifndef OPENSSL_NO_CAST
                   1395:        if (doit[D_CBC_CAST]) {
                   1396:                for (j = 0; j < SIZE_NUM; j++) {
                   1397:                        print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
                   1398:                        Time_F(START);
                   1399:                        for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
                   1400:                                CAST_cbc_encrypt(buf, buf,
                   1401:                                    (unsigned long) lengths[j], &cast_ks,
                   1402:                                    iv, CAST_ENCRYPT);
                   1403:                        d = Time_F(STOP);
                   1404:                        print_result(D_CBC_CAST, j, count, d);
                   1405:                }
                   1406:        }
                   1407: #endif
                   1408:
                   1409:        if (doit[D_EVP]) {
                   1410:                for (j = 0; j < SIZE_NUM; j++) {
                   1411:                        if (evp_cipher) {
1.24      tb       1412:                                EVP_CIPHER_CTX *ctx;
1.1       jsing    1413:                                int outl;
                   1414:
1.24      tb       1415:                                names[D_EVP] =
                   1416:                                    OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
1.1       jsing    1417:                                /*
                   1418:                                 * -O3 -fschedule-insns messes up an
                   1419:                                 * optimization here!  names[D_EVP] somehow
                   1420:                                 * becomes NULL
                   1421:                                 */
                   1422:                                print_message(names[D_EVP], save_count,
                   1423:                                    lengths[j]);
                   1424:
1.24      tb       1425:                                if ((ctx = EVP_CIPHER_CTX_new()) == NULL) {
                   1426:                                        BIO_printf(bio_err, "Failed to "
                   1427:                                            "allocate cipher context.\n");
1.25      tb       1428:                                        goto end;
1.24      tb       1429:                                }
1.1       jsing    1430:                                if (decrypt)
1.24      tb       1431:                                        EVP_DecryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
1.1       jsing    1432:                                else
1.24      tb       1433:                                        EVP_EncryptInit_ex(ctx, evp_cipher, NULL, key16, iv);
                   1434:                                EVP_CIPHER_CTX_set_padding(ctx, 0);
1.1       jsing    1435:
                   1436:                                Time_F(START);
                   1437:                                if (decrypt)
                   1438:                                        for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1.24      tb       1439:                                                EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1.1       jsing    1440:                                else
                   1441:                                        for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
1.24      tb       1442:                                                EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[j]);
1.1       jsing    1443:                                if (decrypt)
1.24      tb       1444:                                        EVP_DecryptFinal_ex(ctx, buf, &outl);
1.1       jsing    1445:                                else
1.24      tb       1446:                                        EVP_EncryptFinal_ex(ctx, buf, &outl);
1.1       jsing    1447:                                d = Time_F(STOP);
1.24      tb       1448:                                EVP_CIPHER_CTX_free(ctx);
1.1       jsing    1449:                        }
                   1450:                        if (evp_md) {
1.24      tb       1451:                                names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
1.1       jsing    1452:                                print_message(names[D_EVP], save_count,
                   1453:                                    lengths[j]);
                   1454:
                   1455:                                Time_F(START);
                   1456:                                for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
                   1457:                                        EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
                   1458:
                   1459:                                d = Time_F(STOP);
                   1460:                        }
                   1461:                        print_result(D_EVP, j, count, d);
                   1462:                }
                   1463:        }
1.2       jsing    1464:        arc4random_buf(buf, 36);
1.1       jsing    1465:        for (j = 0; j < RSA_NUM; j++) {
                   1466:                int ret;
                   1467:                if (!rsa_doit[j])
                   1468:                        continue;
                   1469:                ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
                   1470:                if (ret == 0) {
                   1471:                        BIO_printf(bio_err, "RSA sign failure.  No RSA sign will be done.\n");
                   1472:                        ERR_print_errors(bio_err);
                   1473:                        rsa_count = 1;
                   1474:                } else {
                   1475:                        pkey_print_message("private", "rsa",
                   1476:                            rsa_c[j][0], rsa_bits[j],
                   1477:                            RSA_SECONDS);
                   1478: /*                     RSA_blinding_on(rsa_key[j],NULL); */
                   1479:                        Time_F(START);
                   1480:                        for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
                   1481:                                ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
                   1482:                                    &rsa_num, rsa_key[j]);
                   1483:                                if (ret == 0) {
                   1484:                                        BIO_printf(bio_err,
                   1485:                                            "RSA sign failure\n");
                   1486:                                        ERR_print_errors(bio_err);
                   1487:                                        count = 1;
                   1488:                                        break;
                   1489:                                }
                   1490:                        }
                   1491:                        d = Time_F(STOP);
                   1492:                        BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
                   1493:                            : "%ld %d bit private RSA's in %.2fs\n",
                   1494:                            count, rsa_bits[j], d);
                   1495:                        rsa_results[j][0] = d / (double) count;
                   1496:                        rsa_count = count;
                   1497:                }
                   1498:
                   1499:                ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
                   1500:                if (ret <= 0) {
                   1501:                        BIO_printf(bio_err, "RSA verify failure.  No RSA verify will be done.\n");
                   1502:                        ERR_print_errors(bio_err);
                   1503:                        rsa_doit[j] = 0;
                   1504:                } else {
                   1505:                        pkey_print_message("public", "rsa",
                   1506:                            rsa_c[j][1], rsa_bits[j],
                   1507:                            RSA_SECONDS);
                   1508:                        Time_F(START);
                   1509:                        for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
                   1510:                                ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
                   1511:                                    rsa_num, rsa_key[j]);
                   1512:                                if (ret <= 0) {
                   1513:                                        BIO_printf(bio_err,
                   1514:                                            "RSA verify failure\n");
                   1515:                                        ERR_print_errors(bio_err);
                   1516:                                        count = 1;
                   1517:                                        break;
                   1518:                                }
                   1519:                        }
                   1520:                        d = Time_F(STOP);
                   1521:                        BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
                   1522:                            : "%ld %d bit public RSA's in %.2fs\n",
                   1523:                            count, rsa_bits[j], d);
                   1524:                        rsa_results[j][1] = d / (double) count;
                   1525:                }
                   1526:
                   1527:                if (rsa_count <= 1) {
                   1528:                        /* if longer than 10s, don't do any more */
                   1529:                        for (j++; j < RSA_NUM; j++)
                   1530:                                rsa_doit[j] = 0;
                   1531:                }
                   1532:        }
                   1533:
1.2       jsing    1534:        arc4random_buf(buf, 20);
1.1       jsing    1535:        for (j = 0; j < DSA_NUM; j++) {
                   1536:                unsigned int kk;
                   1537:                int ret;
                   1538:
                   1539:                if (!dsa_doit[j])
                   1540:                        continue;
                   1541: /*             DSA_generate_key(dsa_key[j]); */
                   1542: /*             DSA_sign_setup(dsa_key[j],NULL); */
                   1543:                ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
                   1544:                    &kk, dsa_key[j]);
                   1545:                if (ret == 0) {
                   1546:                        BIO_printf(bio_err, "DSA sign failure.  No DSA sign will be done.\n");
                   1547:                        ERR_print_errors(bio_err);
                   1548:                        rsa_count = 1;
                   1549:                } else {
                   1550:                        pkey_print_message("sign", "dsa",
                   1551:                            dsa_c[j][0], dsa_bits[j],
                   1552:                            DSA_SECONDS);
                   1553:                        Time_F(START);
                   1554:                        for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
                   1555:                                ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
                   1556:                                    &kk, dsa_key[j]);
                   1557:                                if (ret == 0) {
                   1558:                                        BIO_printf(bio_err,
                   1559:                                            "DSA sign failure\n");
                   1560:                                        ERR_print_errors(bio_err);
                   1561:                                        count = 1;
                   1562:                                        break;
                   1563:                                }
                   1564:                        }
                   1565:                        d = Time_F(STOP);
                   1566:                        BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n"
                   1567:                            : "%ld %d bit DSA signs in %.2fs\n",
                   1568:                            count, dsa_bits[j], d);
                   1569:                        dsa_results[j][0] = d / (double) count;
                   1570:                        rsa_count = count;
                   1571:                }
                   1572:
                   1573:                ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
                   1574:                    kk, dsa_key[j]);
                   1575:                if (ret <= 0) {
                   1576:                        BIO_printf(bio_err, "DSA verify failure.  No DSA verify will be done.\n");
                   1577:                        ERR_print_errors(bio_err);
                   1578:                        dsa_doit[j] = 0;
                   1579:                } else {
                   1580:                        pkey_print_message("verify", "dsa",
                   1581:                            dsa_c[j][1], dsa_bits[j],
                   1582:                            DSA_SECONDS);
                   1583:                        Time_F(START);
                   1584:                        for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
                   1585:                                ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
                   1586:                                    kk, dsa_key[j]);
                   1587:                                if (ret <= 0) {
                   1588:                                        BIO_printf(bio_err,
                   1589:                                            "DSA verify failure\n");
                   1590:                                        ERR_print_errors(bio_err);
                   1591:                                        count = 1;
                   1592:                                        break;
                   1593:                                }
                   1594:                        }
                   1595:                        d = Time_F(STOP);
                   1596:                        BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n"
                   1597:                            : "%ld %d bit DSA verify in %.2fs\n",
                   1598:                            count, dsa_bits[j], d);
                   1599:                        dsa_results[j][1] = d / (double) count;
                   1600:                }
                   1601:
                   1602:                if (rsa_count <= 1) {
                   1603:                        /* if longer than 10s, don't do any more */
                   1604:                        for (j++; j < DSA_NUM; j++)
                   1605:                                dsa_doit[j] = 0;
                   1606:                }
                   1607:        }
                   1608:
                   1609:        for (j = 0; j < EC_NUM; j++) {
                   1610:                int ret;
                   1611:
                   1612:                if (!ecdsa_doit[j])
                   1613:                        continue;       /* Ignore Curve */
                   1614:                ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
                   1615:                if (ecdsa[j] == NULL) {
                   1616:                        BIO_printf(bio_err, "ECDSA failure.\n");
                   1617:                        ERR_print_errors(bio_err);
                   1618:                        rsa_count = 1;
                   1619:                } else {
                   1620:                        EC_KEY_precompute_mult(ecdsa[j], NULL);
1.5       doug     1621:
1.1       jsing    1622:                        /* Perform ECDSA signature test */
                   1623:                        EC_KEY_generate_key(ecdsa[j]);
                   1624:                        ret = ECDSA_sign(0, buf, 20, ecdsasig,
                   1625:                            &ecdsasiglen, ecdsa[j]);
                   1626:                        if (ret == 0) {
                   1627:                                BIO_printf(bio_err, "ECDSA sign failure.  No ECDSA sign will be done.\n");
                   1628:                                ERR_print_errors(bio_err);
                   1629:                                rsa_count = 1;
                   1630:                        } else {
                   1631:                                pkey_print_message("sign", "ecdsa",
                   1632:                                    ecdsa_c[j][0],
                   1633:                                    test_curves_bits[j],
                   1634:                                    ECDSA_SECONDS);
                   1635:
                   1636:                                Time_F(START);
                   1637:                                for (count = 0, run = 1; COND(ecdsa_c[j][0]);
                   1638:                                    count++) {
                   1639:                                        ret = ECDSA_sign(0, buf, 20,
                   1640:                                            ecdsasig, &ecdsasiglen,
                   1641:                                            ecdsa[j]);
                   1642:                                        if (ret == 0) {
                   1643:                                                BIO_printf(bio_err, "ECDSA sign failure\n");
                   1644:                                                ERR_print_errors(bio_err);
                   1645:                                                count = 1;
                   1646:                                                break;
                   1647:                                        }
                   1648:                                }
                   1649:                                d = Time_F(STOP);
                   1650:
                   1651:                                BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
                   1652:                                    "%ld %d bit ECDSA signs in %.2fs \n",
                   1653:                                    count, test_curves_bits[j], d);
                   1654:                                ecdsa_results[j][0] = d / (double) count;
                   1655:                                rsa_count = count;
                   1656:                        }
                   1657:
                   1658:                        /* Perform ECDSA verification test */
                   1659:                        ret = ECDSA_verify(0, buf, 20, ecdsasig,
                   1660:                            ecdsasiglen, ecdsa[j]);
                   1661:                        if (ret != 1) {
                   1662:                                BIO_printf(bio_err, "ECDSA verify failure.  No ECDSA verify will be done.\n");
                   1663:                                ERR_print_errors(bio_err);
                   1664:                                ecdsa_doit[j] = 0;
                   1665:                        } else {
                   1666:                                pkey_print_message("verify", "ecdsa",
                   1667:                                    ecdsa_c[j][1],
                   1668:                                    test_curves_bits[j],
                   1669:                                    ECDSA_SECONDS);
                   1670:                                Time_F(START);
                   1671:                                for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
                   1672:                                        ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
                   1673:                                        if (ret != 1) {
                   1674:                                                BIO_printf(bio_err, "ECDSA verify failure\n");
                   1675:                                                ERR_print_errors(bio_err);
                   1676:                                                count = 1;
                   1677:                                                break;
                   1678:                                        }
                   1679:                                }
                   1680:                                d = Time_F(STOP);
                   1681:                                BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n"
                   1682:                                    : "%ld %d bit ECDSA verify in %.2fs\n",
                   1683:                                    count, test_curves_bits[j], d);
                   1684:                                ecdsa_results[j][1] = d / (double) count;
                   1685:                        }
                   1686:
                   1687:                        if (rsa_count <= 1) {
                   1688:                                /* if longer than 10s, don't do any more */
                   1689:                                for (j++; j < EC_NUM; j++)
                   1690:                                        ecdsa_doit[j] = 0;
                   1691:                        }
                   1692:                }
                   1693:        }
                   1694:
                   1695:        for (j = 0; j < EC_NUM; j++) {
                   1696:                if (!ecdh_doit[j])
                   1697:                        continue;
                   1698:                ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
                   1699:                ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
                   1700:                if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
                   1701:                        BIO_printf(bio_err, "ECDH failure.\n");
                   1702:                        ERR_print_errors(bio_err);
                   1703:                        rsa_count = 1;
                   1704:                } else {
                   1705:                        /* generate two ECDH key pairs */
                   1706:                        if (!EC_KEY_generate_key(ecdh_a[j]) ||
                   1707:                            !EC_KEY_generate_key(ecdh_b[j])) {
                   1708:                                BIO_printf(bio_err, "ECDH key generation failure.\n");
                   1709:                                ERR_print_errors(bio_err);
                   1710:                                rsa_count = 1;
                   1711:                        } else {
                   1712:                                /*
                   1713:                                 * If field size is not more than 24 octets,
                   1714:                                 * then use SHA-1 hash of result; otherwise,
                   1715:                                 * use result (see section 4.8 of
                   1716:                                 * draft-ietf-tls-ecc-03.txt).
                   1717:                                 */
                   1718:                                int field_size, outlen;
                   1719:                                void *(*kdf) (const void *in, size_t inlen, void *out, size_t * xoutlen);
                   1720:                                field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
                   1721:                                if (field_size <= 24 * 8) {
                   1722:                                        outlen = KDF1_SHA1_len;
                   1723:                                        kdf = KDF1_SHA1;
                   1724:                                } else {
                   1725:                                        outlen = (field_size + 7) / 8;
                   1726:                                        kdf = NULL;
                   1727:                                }
                   1728:                                secret_size_a = ECDH_compute_key(secret_a, outlen,
                   1729:                                    EC_KEY_get0_public_key(ecdh_b[j]),
                   1730:                                    ecdh_a[j], kdf);
                   1731:                                secret_size_b = ECDH_compute_key(secret_b, outlen,
                   1732:                                    EC_KEY_get0_public_key(ecdh_a[j]),
                   1733:                                    ecdh_b[j], kdf);
                   1734:                                if (secret_size_a != secret_size_b)
                   1735:                                        ecdh_checks = 0;
                   1736:                                else
                   1737:                                        ecdh_checks = 1;
                   1738:
                   1739:                                for (secret_idx = 0;
                   1740:                                    (secret_idx < secret_size_a)
                   1741:                                    && (ecdh_checks == 1);
                   1742:                                    secret_idx++) {
                   1743:                                        if (secret_a[secret_idx] != secret_b[secret_idx])
                   1744:                                                ecdh_checks = 0;
                   1745:                                }
                   1746:
                   1747:                                if (ecdh_checks == 0) {
1.8       doug     1748:                                        BIO_printf(bio_err,
                   1749:                                            "ECDH computations don't match.\n");
1.1       jsing    1750:                                        ERR_print_errors(bio_err);
                   1751:                                        rsa_count = 1;
1.8       doug     1752:                                } else {
                   1753:                                        pkey_print_message("", "ecdh",
                   1754:                                            ecdh_c[j][0],
                   1755:                                            test_curves_bits[j],
                   1756:                                            ECDH_SECONDS);
                   1757:                                        Time_F(START);
                   1758:                                        for (count = 0, run = 1;
                   1759:                                             COND(ecdh_c[j][0]); count++) {
                   1760:                                                ECDH_compute_key(secret_a,
                   1761:                                                    outlen,
                   1762:                                                    EC_KEY_get0_public_key(ecdh_b[j]),
                   1763:                                                    ecdh_a[j], kdf);
                   1764:                                        }
                   1765:                                        d = Time_F(STOP);
                   1766:                                        BIO_printf(bio_err, mr
                   1767:                                            ? "+R7:%ld:%d:%.2f\n"
                   1768:                                            : "%ld %d-bit ECDH ops in %.2fs\n",
                   1769:                                            count, test_curves_bits[j], d);
                   1770:                                        ecdh_results[j][0] = d / (double) count;
                   1771:                                        rsa_count = count;
1.1       jsing    1772:                                }
                   1773:                        }
                   1774:                }
                   1775:
                   1776:
                   1777:                if (rsa_count <= 1) {
                   1778:                        /* if longer than 10s, don't do any more */
                   1779:                        for (j++; j < EC_NUM; j++)
                   1780:                                ecdh_doit[j] = 0;
                   1781:                }
                   1782:        }
                   1783: show_res:
                   1784:        if (!mr) {
                   1785:                fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
                   1786:                fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
                   1787:                printf("options:");
                   1788:                printf("%s ", BN_options());
                   1789: #ifndef OPENSSL_NO_RC4
                   1790:                printf("%s ", RC4_options());
                   1791: #endif
                   1792: #ifndef OPENSSL_NO_DES
                   1793:                printf("%s ", DES_options());
                   1794: #endif
                   1795: #ifndef OPENSSL_NO_AES
                   1796:                printf("%s ", AES_options());
                   1797: #endif
                   1798: #ifndef OPENSSL_NO_IDEA
                   1799:                printf("%s ", idea_options());
                   1800: #endif
                   1801: #ifndef OPENSSL_NO_BF
                   1802:                printf("%s ", BF_options());
                   1803: #endif
                   1804:                fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
                   1805:        }
                   1806:        if (pr_header) {
                   1807:                if (mr)
                   1808:                        fprintf(stdout, "+H");
                   1809:                else {
                   1810:                        fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n");
                   1811:                        fprintf(stdout, "type        ");
                   1812:                }
                   1813:                for (j = 0; j < SIZE_NUM; j++)
                   1814:                        fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
                   1815:                fprintf(stdout, "\n");
                   1816:        }
                   1817:        for (k = 0; k < ALGOR_NUM; k++) {
                   1818:                if (!doit[k])
                   1819:                        continue;
                   1820:                if (mr)
                   1821:                        fprintf(stdout, "+F:%d:%s", k, names[k]);
                   1822:                else
                   1823:                        fprintf(stdout, "%-13s", names[k]);
                   1824:                for (j = 0; j < SIZE_NUM; j++) {
                   1825:                        if (results[k][j] > 10000 && !mr)
                   1826:                                fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
                   1827:                        else
                   1828:                                fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
                   1829:                }
                   1830:                fprintf(stdout, "\n");
                   1831:        }
                   1832:        j = 1;
                   1833:        for (k = 0; k < RSA_NUM; k++) {
                   1834:                if (!rsa_doit[k])
                   1835:                        continue;
                   1836:                if (j && !mr) {
                   1837:                        printf("%18ssign    verify    sign/s verify/s\n", " ");
                   1838:                        j = 0;
                   1839:                }
                   1840:                if (mr)
                   1841:                        fprintf(stdout, "+F2:%u:%u:%f:%f\n",
                   1842:                            k, rsa_bits[k], rsa_results[k][0],
                   1843:                            rsa_results[k][1]);
                   1844:                else
                   1845:                        fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
                   1846:                            rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
                   1847:                            1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
                   1848:        }
                   1849:        j = 1;
                   1850:        for (k = 0; k < DSA_NUM; k++) {
                   1851:                if (!dsa_doit[k])
                   1852:                        continue;
                   1853:                if (j && !mr) {
                   1854:                        printf("%18ssign    verify    sign/s verify/s\n", " ");
                   1855:                        j = 0;
                   1856:                }
                   1857:                if (mr)
                   1858:                        fprintf(stdout, "+F3:%u:%u:%f:%f\n",
                   1859:                            k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
                   1860:                else
                   1861:                        fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
                   1862:                            dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
                   1863:                            1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
                   1864:        }
                   1865:        j = 1;
                   1866:        for (k = 0; k < EC_NUM; k++) {
                   1867:                if (!ecdsa_doit[k])
                   1868:                        continue;
                   1869:                if (j && !mr) {
                   1870:                        printf("%30ssign    verify    sign/s verify/s\n", " ");
                   1871:                        j = 0;
                   1872:                }
                   1873:                if (mr)
                   1874:                        fprintf(stdout, "+F4:%u:%u:%f:%f\n",
                   1875:                            k, test_curves_bits[k],
                   1876:                            ecdsa_results[k][0], ecdsa_results[k][1]);
                   1877:                else
                   1878:                        fprintf(stdout,
                   1879:                            "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
                   1880:                            test_curves_bits[k],
                   1881:                            test_curves_names[k],
                   1882:                            ecdsa_results[k][0], ecdsa_results[k][1],
                   1883:                            1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
                   1884:        }
                   1885:
                   1886:
                   1887:        j = 1;
                   1888:        for (k = 0; k < EC_NUM; k++) {
                   1889:                if (!ecdh_doit[k])
                   1890:                        continue;
                   1891:                if (j && !mr) {
                   1892:                        printf("%30sop      op/s\n", " ");
                   1893:                        j = 0;
                   1894:                }
                   1895:                if (mr)
                   1896:                        fprintf(stdout, "+F5:%u:%u:%f:%f\n",
                   1897:                            k, test_curves_bits[k],
                   1898:                            ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
                   1899:
                   1900:                else
                   1901:                        fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
                   1902:                            test_curves_bits[k],
                   1903:                            test_curves_names[k],
                   1904:                            ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
                   1905:        }
                   1906:
                   1907:        mret = 0;
                   1908:
1.22      jsing    1909:  end:
1.1       jsing    1910:        ERR_print_errors(bio_err);
                   1911:        free(buf);
                   1912:        free(buf2);
                   1913:        for (i = 0; i < RSA_NUM; i++)
                   1914:                if (rsa_key[i] != NULL)
                   1915:                        RSA_free(rsa_key[i]);
                   1916:        for (i = 0; i < DSA_NUM; i++)
                   1917:                if (dsa_key[i] != NULL)
                   1918:                        DSA_free(dsa_key[i]);
                   1919:
                   1920:        for (i = 0; i < EC_NUM; i++)
                   1921:                if (ecdsa[i] != NULL)
                   1922:                        EC_KEY_free(ecdsa[i]);
                   1923:        for (i = 0; i < EC_NUM; i++) {
                   1924:                if (ecdh_a[i] != NULL)
                   1925:                        EC_KEY_free(ecdh_a[i]);
                   1926:                if (ecdh_b[i] != NULL)
                   1927:                        EC_KEY_free(ecdh_b[i]);
                   1928:        }
                   1929:
                   1930:
                   1931:        return (mret);
                   1932: }
                   1933:
                   1934: static void
                   1935: print_message(const char *s, long num, int length)
                   1936: {
                   1937:        BIO_printf(bio_err, mr ? "+DT:%s:%d:%d\n"
                   1938:            : "Doing %s for %ds on %d size blocks: ", s, SECONDS, length);
                   1939:        (void) BIO_flush(bio_err);
                   1940:        alarm(SECONDS);
                   1941: }
                   1942:
                   1943: static void
                   1944: pkey_print_message(const char *str, const char *str2, long num,
                   1945:     int bits, int tm)
                   1946: {
                   1947:        BIO_printf(bio_err, mr ? "+DTP:%d:%s:%s:%d\n"
                   1948:            : "Doing %d bit %s %s's for %ds: ", bits, str, str2, tm);
                   1949:        (void) BIO_flush(bio_err);
                   1950:        alarm(tm);
                   1951: }
                   1952:
                   1953: static void
                   1954: print_result(int alg, int run_no, int count, double time_used)
                   1955: {
                   1956:        BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
                   1957:            : "%d %s's in %.2fs\n", count, names[alg], time_used);
                   1958:        results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
                   1959: }
                   1960:
                   1961: static char *
                   1962: sstrsep(char **string, const char *delim)
                   1963: {
                   1964:        char isdelim[256];
                   1965:        char *token = *string;
                   1966:
                   1967:        if (**string == 0)
                   1968:                return NULL;
                   1969:
                   1970:        memset(isdelim, 0, sizeof isdelim);
                   1971:        isdelim[0] = 1;
                   1972:
                   1973:        while (*delim) {
                   1974:                isdelim[(unsigned char) (*delim)] = 1;
                   1975:                delim++;
                   1976:        }
                   1977:
                   1978:        while (!isdelim[(unsigned char) (**string)]) {
                   1979:                (*string)++;
                   1980:        }
                   1981:
                   1982:        if (**string) {
                   1983:                **string = 0;
                   1984:                (*string)++;
                   1985:        }
                   1986:        return token;
                   1987: }
                   1988:
                   1989: static int
                   1990: do_multi(int multi)
                   1991: {
                   1992:        int n;
                   1993:        int fd[2];
                   1994:        int *fds;
                   1995:        static char sep[] = ":";
                   1996:        const char *errstr = NULL;
                   1997:
                   1998:        fds = reallocarray(NULL, multi, sizeof *fds);
1.4       lteo     1999:        if (fds == NULL) {
                   2000:                fprintf(stderr, "reallocarray failure\n");
                   2001:                exit(1);
                   2002:        }
1.1       jsing    2003:        for (n = 0; n < multi; ++n) {
                   2004:                if (pipe(fd) == -1) {
                   2005:                        fprintf(stderr, "pipe failure\n");
                   2006:                        exit(1);
                   2007:                }
                   2008:                fflush(stdout);
                   2009:                fflush(stderr);
                   2010:                if (fork()) {
                   2011:                        close(fd[1]);
                   2012:                        fds[n] = fd[0];
                   2013:                } else {
                   2014:                        close(fd[0]);
                   2015:                        close(1);
                   2016:                        if (dup(fd[1]) == -1) {
                   2017:                                fprintf(stderr, "dup failed\n");
                   2018:                                exit(1);
                   2019:                        }
                   2020:                        close(fd[1]);
                   2021:                        mr = 1;
                   2022:                        usertime = 0;
                   2023:                        free(fds);
                   2024:                        return 0;
                   2025:                }
                   2026:                printf("Forked child %d\n", n);
                   2027:        }
                   2028:
                   2029:        /* for now, assume the pipe is long enough to take all the output */
                   2030:        for (n = 0; n < multi; ++n) {
                   2031:                FILE *f;
                   2032:                char buf[1024];
                   2033:                char *p;
                   2034:
                   2035:                f = fdopen(fds[n], "r");
                   2036:                while (fgets(buf, sizeof buf, f)) {
                   2037:                        p = strchr(buf, '\n');
                   2038:                        if (p)
                   2039:                                *p = '\0';
                   2040:                        if (buf[0] != '+') {
                   2041:                                fprintf(stderr, "Don't understand line '%s' from child %d\n",
                   2042:                                    buf, n);
                   2043:                                continue;
                   2044:                        }
                   2045:                        printf("Got: %s from %d\n", buf, n);
                   2046:                        if (!strncmp(buf, "+F:", 3)) {
                   2047:                                int alg;
                   2048:                                int j;
                   2049:
                   2050:                                p = buf + 3;
                   2051:                                alg = strtonum(sstrsep(&p, sep),
                   2052:                                    0, ALGOR_NUM - 1, &errstr);
                   2053:                                sstrsep(&p, sep);
                   2054:                                for (j = 0; j < SIZE_NUM; ++j)
                   2055:                                        results[alg][j] += atof(sstrsep(&p, sep));
                   2056:                        } else if (!strncmp(buf, "+F2:", 4)) {
                   2057:                                int k;
                   2058:                                double d;
                   2059:
                   2060:                                p = buf + 4;
                   2061:                                k = strtonum(sstrsep(&p, sep),
                   2062:                                    0, ALGOR_NUM - 1, &errstr);
                   2063:                                sstrsep(&p, sep);
                   2064:
                   2065:                                d = atof(sstrsep(&p, sep));
                   2066:                                if (n)
                   2067:                                        rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
                   2068:                                else
                   2069:                                        rsa_results[k][0] = d;
                   2070:
                   2071:                                d = atof(sstrsep(&p, sep));
                   2072:                                if (n)
                   2073:                                        rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
                   2074:                                else
                   2075:                                        rsa_results[k][1] = d;
                   2076:                        } else if (!strncmp(buf, "+F2:", 4)) {
                   2077:                                int k;
                   2078:                                double d;
                   2079:
                   2080:                                p = buf + 4;
                   2081:                                k = strtonum(sstrsep(&p, sep),
                   2082:                                    0, ALGOR_NUM - 1, &errstr);
                   2083:                                sstrsep(&p, sep);
                   2084:
                   2085:                                d = atof(sstrsep(&p, sep));
                   2086:                                if (n)
                   2087:                                        rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
                   2088:                                else
                   2089:                                        rsa_results[k][0] = d;
                   2090:
                   2091:                                d = atof(sstrsep(&p, sep));
                   2092:                                if (n)
                   2093:                                        rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
                   2094:                                else
                   2095:                                        rsa_results[k][1] = d;
                   2096:                        }
                   2097:                        else if (!strncmp(buf, "+F3:", 4)) {
                   2098:                                int k;
                   2099:                                double d;
                   2100:
                   2101:                                p = buf + 4;
                   2102:                                k = strtonum(sstrsep(&p, sep),
                   2103:                                    0, ALGOR_NUM - 1, &errstr);
                   2104:                                sstrsep(&p, sep);
                   2105:
                   2106:                                d = atof(sstrsep(&p, sep));
                   2107:                                if (n)
                   2108:                                        dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
                   2109:                                else
                   2110:                                        dsa_results[k][0] = d;
                   2111:
                   2112:                                d = atof(sstrsep(&p, sep));
                   2113:                                if (n)
                   2114:                                        dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
                   2115:                                else
                   2116:                                        dsa_results[k][1] = d;
                   2117:                        }
                   2118:                        else if (!strncmp(buf, "+F4:", 4)) {
                   2119:                                int k;
                   2120:                                double d;
                   2121:
                   2122:                                p = buf + 4;
                   2123:                                k = strtonum(sstrsep(&p, sep),
                   2124:                                    0, ALGOR_NUM - 1, &errstr);
                   2125:                                sstrsep(&p, sep);
                   2126:
                   2127:                                d = atof(sstrsep(&p, sep));
                   2128:                                if (n)
                   2129:                                        ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d);
                   2130:                                else
                   2131:                                        ecdsa_results[k][0] = d;
                   2132:
                   2133:                                d = atof(sstrsep(&p, sep));
                   2134:                                if (n)
                   2135:                                        ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d);
                   2136:                                else
                   2137:                                        ecdsa_results[k][1] = d;
                   2138:                        }
                   2139:
                   2140:                        else if (!strncmp(buf, "+F5:", 4)) {
                   2141:                                int k;
                   2142:                                double d;
                   2143:
                   2144:                                p = buf + 4;
                   2145:                                k = strtonum(sstrsep(&p, sep),
                   2146:                                    0, ALGOR_NUM - 1, &errstr);
                   2147:                                sstrsep(&p, sep);
                   2148:
                   2149:                                d = atof(sstrsep(&p, sep));
                   2150:                                if (n)
                   2151:                                        ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
                   2152:                                else
                   2153:                                        ecdh_results[k][0] = d;
                   2154:
                   2155:                        }
                   2156:
                   2157:                        else if (!strncmp(buf, "+H:", 3)) {
                   2158:                        } else
                   2159:                                fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
                   2160:                }
                   2161:
                   2162:                fclose(f);
                   2163:        }
                   2164:        free(fds);
                   2165:        return 1;
                   2166: }
                   2167: #endif