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

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