Blame apps/speed.c

Packit c4476c
/*
Packit c4476c
 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
Packit c4476c
 *
Packit c4476c
 * Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
 * this file except in compliance with the License.  You can obtain a copy
Packit c4476c
 * in the file LICENSE in the source distribution or at
Packit c4476c
 * https://www.openssl.org/source/license.html
Packit c4476c
 */
Packit c4476c
Packit c4476c
#undef SECONDS
Packit c4476c
#define SECONDS                 3
Packit c4476c
#define RSA_SECONDS             10
Packit c4476c
#define DSA_SECONDS             10
Packit c4476c
#define ECDSA_SECONDS   10
Packit c4476c
#define ECDH_SECONDS    10
Packit c4476c
#define EdDSA_SECONDS   10
Packit c4476c
Packit c4476c
#include <stdio.h>
Packit c4476c
#include <stdlib.h>
Packit c4476c
#include <string.h>
Packit c4476c
#include <math.h>
Packit c4476c
#include "apps.h"
Packit c4476c
#include "progs.h"
Packit c4476c
#include <openssl/crypto.h>
Packit c4476c
#include <openssl/rand.h>
Packit c4476c
#include <openssl/err.h>
Packit c4476c
#include <openssl/evp.h>
Packit c4476c
#include <openssl/objects.h>
Packit c4476c
#include <openssl/async.h>
Packit c4476c
#if !defined(OPENSSL_SYS_MSDOS)
Packit c4476c
# include OPENSSL_UNISTD
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#if defined(_WIN32)
Packit c4476c
# include <windows.h>
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#include <openssl/bn.h>
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
# include <openssl/des.h>
Packit c4476c
#endif
Packit c4476c
#include <openssl/aes.h>
Packit c4476c
#ifndef OPENSSL_NO_CAMELLIA
Packit c4476c
# include <openssl/camellia.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
# include <openssl/md2.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MDC2
Packit c4476c
# include <openssl/mdc2.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD4
Packit c4476c
# include <openssl/md4.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD5
Packit c4476c
# include <openssl/md5.h>
Packit c4476c
#endif
Packit c4476c
#include <openssl/hmac.h>
Packit c4476c
#include <openssl/sha.h>
Packit c4476c
#ifndef OPENSSL_NO_RMD160
Packit c4476c
# include <openssl/ripemd.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_WHIRLPOOL
Packit c4476c
# include <openssl/whrlpool.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
# include <openssl/rc4.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC5
Packit c4476c
# include <openssl/rc5.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC2
Packit c4476c
# include <openssl/rc2.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
# include <openssl/idea.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_SEED
Packit c4476c
# include <openssl/seed.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
# include <openssl/blowfish.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_CAST
Packit c4476c
# include <openssl/cast.h>
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
# include <openssl/rsa.h>
Packit c4476c
# include "./testrsa.h"
Packit c4476c
#endif
Packit c4476c
#include <openssl/x509.h>
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
# include <openssl/dsa.h>
Packit c4476c
# include "./testdsa.h"
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
# include <openssl/ec.h>
Packit c4476c
#endif
Packit c4476c
#include <openssl/modes.h>
Packit c4476c
Packit c4476c
#ifndef HAVE_FORK
Packit c4476c
# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
Packit c4476c
#  define HAVE_FORK 0
Packit c4476c
# else
Packit c4476c
#  define HAVE_FORK 1
Packit c4476c
# endif
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#if HAVE_FORK
Packit c4476c
# undef NO_FORK
Packit c4476c
#else
Packit c4476c
# define NO_FORK
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#define MAX_MISALIGNMENT 63
Packit c4476c
#define MAX_ECDH_SIZE   256
Packit c4476c
#define MISALIGN        64
Packit c4476c
Packit c4476c
typedef struct openssl_speed_sec_st {
Packit c4476c
    int sym;
Packit c4476c
    int rsa;
Packit c4476c
    int dsa;
Packit c4476c
    int ecdsa;
Packit c4476c
    int ecdh;
Packit c4476c
    int eddsa;
Packit c4476c
} openssl_speed_sec_t;
Packit c4476c
Packit c4476c
static volatile int run = 0;
Packit c4476c
Packit c4476c
static int mr = 0;
Packit c4476c
static int usertime = 1;
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
static int EVP_Digest_MD2_loop(void *args);
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MDC2
Packit c4476c
static int EVP_Digest_MDC2_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD4
Packit c4476c
static int EVP_Digest_MD4_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD5
Packit c4476c
static int MD5_loop(void *args);
Packit c4476c
static int HMAC_loop(void *args);
Packit c4476c
#endif
Packit c4476c
static int SHA1_loop(void *args);
Packit c4476c
static int SHA256_loop(void *args);
Packit c4476c
static int SHA512_loop(void *args);
Packit c4476c
#ifndef OPENSSL_NO_WHIRLPOOL
Packit c4476c
static int WHIRLPOOL_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RMD160
Packit c4476c
static int EVP_Digest_RMD160_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
static int RC4_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
static int DES_ncbc_encrypt_loop(void *args);
Packit c4476c
static int DES_ede3_cbc_encrypt_loop(void *args);
Packit c4476c
#endif
Packit c4476c
static int AES_cbc_128_encrypt_loop(void *args);
Packit c4476c
static int AES_cbc_192_encrypt_loop(void *args);
Packit c4476c
static int AES_ige_128_encrypt_loop(void *args);
Packit c4476c
static int AES_cbc_256_encrypt_loop(void *args);
Packit c4476c
static int AES_ige_192_encrypt_loop(void *args);
Packit c4476c
static int AES_ige_256_encrypt_loop(void *args);
Packit c4476c
static int CRYPTO_gcm128_aad_loop(void *args);
Packit c4476c
static int RAND_bytes_loop(void *args);
Packit c4476c
static int EVP_Update_loop(void *args);
Packit c4476c
static int EVP_Update_loop_ccm(void *args);
Packit c4476c
static int EVP_Update_loop_aead(void *args);
Packit c4476c
static int EVP_Digest_loop(void *args);
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
static int RSA_sign_loop(void *args);
Packit c4476c
static int RSA_verify_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
static int DSA_sign_loop(void *args);
Packit c4476c
static int DSA_verify_loop(void *args);
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
static int ECDSA_sign_loop(void *args);
Packit c4476c
static int ECDSA_verify_loop(void *args);
Packit c4476c
static int EdDSA_sign_loop(void *args);
Packit c4476c
static int EdDSA_verify_loop(void *args);
Packit c4476c
#endif
Packit c4476c
Packit c4476c
static double Time_F(int s);
Packit c4476c
static void print_message(const char *s, long num, int length, int tm);
Packit c4476c
static void pkey_print_message(const char *str, const char *str2,
Packit c4476c
                               long num, unsigned int bits, int sec);
Packit c4476c
static void print_result(int alg, int run_no, int count, double time_used);
Packit c4476c
#ifndef NO_FORK
Packit c4476c
static int do_multi(int multi, int size_num);
Packit c4476c
#endif
Packit c4476c
Packit c4476c
static const int lengths_list[] = {
Packit c4476c
    16, 64, 256, 1024, 8 * 1024, 16 * 1024
Packit c4476c
};
Packit c4476c
static const int *lengths = lengths_list;
Packit c4476c
Packit c4476c
static const int aead_lengths_list[] = {
Packit c4476c
    2, 31, 136, 1024, 8 * 1024, 16 * 1024
Packit c4476c
};
Packit c4476c
Packit c4476c
#define START   0
Packit c4476c
#define STOP    1
Packit c4476c
Packit c4476c
#ifdef SIGALRM
Packit c4476c
Packit c4476c
static void alarmed(int sig)
Packit c4476c
{
Packit c4476c
    signal(SIGALRM, alarmed);
Packit c4476c
    run = 0;
Packit c4476c
}
Packit c4476c
Packit c4476c
static double Time_F(int s)
Packit c4476c
{
Packit c4476c
    double ret = app_tminterval(s, usertime);
Packit c4476c
    if (s == STOP)
Packit c4476c
        alarm(0);
Packit c4476c
    return ret;
Packit c4476c
}
Packit c4476c
Packit c4476c
#elif defined(_WIN32)
Packit c4476c
Packit c4476c
# define SIGALRM -1
Packit c4476c
Packit c4476c
static unsigned int lapse;
Packit c4476c
static volatile unsigned int schlock;
Packit c4476c
static void alarm_win32(unsigned int secs)
Packit c4476c
{
Packit c4476c
    lapse = secs * 1000;
Packit c4476c
}
Packit c4476c
Packit c4476c
# define alarm alarm_win32
Packit c4476c
Packit c4476c
static DWORD WINAPI sleepy(VOID * arg)
Packit c4476c
{
Packit c4476c
    schlock = 1;
Packit c4476c
    Sleep(lapse);
Packit c4476c
    run = 0;
Packit c4476c
    return 0;
Packit c4476c
}
Packit c4476c
Packit c4476c
static double Time_F(int s)
Packit c4476c
{
Packit c4476c
    double ret;
Packit c4476c
    static HANDLE thr;
Packit c4476c
Packit c4476c
    if (s == START) {
Packit c4476c
        schlock = 0;
Packit c4476c
        thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL);
Packit c4476c
        if (thr == NULL) {
Packit c4476c
            DWORD err = GetLastError();
Packit c4476c
            BIO_printf(bio_err, "unable to CreateThread (%lu)", err);
Packit c4476c
            ExitProcess(err);
Packit c4476c
        }
Packit c4476c
        while (!schlock)
Packit c4476c
            Sleep(0);           /* scheduler spinlock */
Packit c4476c
        ret = app_tminterval(s, usertime);
Packit c4476c
    } else {
Packit c4476c
        ret = app_tminterval(s, usertime);
Packit c4476c
        if (run)
Packit c4476c
            TerminateThread(thr, 0);
Packit c4476c
        CloseHandle(thr);
Packit c4476c
    }
Packit c4476c
Packit c4476c
    return ret;
Packit c4476c
}
Packit c4476c
#else
Packit c4476c
static double Time_F(int s)
Packit c4476c
{
Packit c4476c
    return app_tminterval(s, usertime);
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single,
Packit c4476c
                             const openssl_speed_sec_t *seconds);
Packit c4476c
Packit c4476c
#define found(value, pairs, result)\
Packit c4476c
    opt_found(value, result, pairs, OSSL_NELEM(pairs))
Packit c4476c
static int opt_found(const char *name, unsigned int *result,
Packit c4476c
                     const OPT_PAIR pairs[], unsigned int nbelem)
Packit c4476c
{
Packit c4476c
    unsigned int idx;
Packit c4476c
Packit c4476c
    for (idx = 0; idx < nbelem; ++idx, pairs++)
Packit c4476c
        if (strcmp(name, pairs->name) == 0) {
Packit c4476c
            *result = pairs->retval;
Packit c4476c
            return 1;
Packit c4476c
        }
Packit c4476c
    return 0;
Packit c4476c
}
Packit c4476c
Packit c4476c
typedef enum OPTION_choice {
Packit c4476c
    OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
Packit c4476c
    OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
Packit c4476c
    OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
Packit c4476c
    OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD
Packit c4476c
} OPTION_CHOICE;
Packit c4476c
Packit c4476c
const OPTIONS speed_options[] = {
Packit c4476c
    {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
Packit c4476c
    {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
Packit c4476c
    {"help", OPT_HELP, '-', "Display this summary"},
Packit c4476c
    {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
Packit c4476c
    {"decrypt", OPT_DECRYPT, '-',
Packit c4476c
     "Time decryption instead of encryption (only EVP)"},
Packit c4476c
    {"aead", OPT_AEAD, '-',
Packit c4476c
     "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
Packit c4476c
    {"mb", OPT_MB, '-',
Packit c4476c
     "Enable (tls1>=1) multi-block mode on EVP-named cipher"},
Packit c4476c
    {"mr", OPT_MR, '-', "Produce machine readable output"},
Packit c4476c
#ifndef NO_FORK
Packit c4476c
    {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_ASYNC
Packit c4476c
    {"async_jobs", OPT_ASYNCJOBS, 'p',
Packit c4476c
     "Enable async mode and start specified number of jobs"},
Packit c4476c
#endif
Packit c4476c
    OPT_R_OPTIONS,
Packit c4476c
#ifndef OPENSSL_NO_ENGINE
Packit c4476c
    {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
Packit c4476c
#endif
Packit c4476c
    {"elapsed", OPT_ELAPSED, '-',
Packit c4476c
     "Use wall-clock time instead of CPU user time as divisor"},
Packit c4476c
    {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
Packit c4476c
    {"seconds", OPT_SECONDS, 'p',
Packit c4476c
     "Run benchmarks for specified amount of seconds"},
Packit c4476c
    {"bytes", OPT_BYTES, 'p',
Packit c4476c
     "Run [non-PKI] benchmarks on custom-sized buffer"},
Packit c4476c
    {"misalign", OPT_MISALIGN, 'p',
Packit c4476c
     "Use specified offset to mis-align buffers"},
Packit c4476c
    {NULL}
Packit c4476c
};
Packit c4476c
Packit c4476c
#define D_MD2           0
Packit c4476c
#define D_MDC2          1
Packit c4476c
#define D_MD4           2
Packit c4476c
#define D_MD5           3
Packit c4476c
#define D_HMAC          4
Packit c4476c
#define D_SHA1          5
Packit c4476c
#define D_RMD160        6
Packit c4476c
#define D_RC4           7
Packit c4476c
#define D_CBC_DES       8
Packit c4476c
#define D_EDE3_DES      9
Packit c4476c
#define D_CBC_IDEA      10
Packit c4476c
#define D_CBC_SEED      11
Packit c4476c
#define D_CBC_RC2       12
Packit c4476c
#define D_CBC_RC5       13
Packit c4476c
#define D_CBC_BF        14
Packit c4476c
#define D_CBC_CAST      15
Packit c4476c
#define D_CBC_128_AES   16
Packit c4476c
#define D_CBC_192_AES   17
Packit c4476c
#define D_CBC_256_AES   18
Packit c4476c
#define D_CBC_128_CML   19
Packit c4476c
#define D_CBC_192_CML   20
Packit c4476c
#define D_CBC_256_CML   21
Packit c4476c
#define D_EVP           22
Packit c4476c
#define D_SHA256        23
Packit c4476c
#define D_SHA512        24
Packit c4476c
#define D_WHIRLPOOL     25
Packit c4476c
#define D_IGE_128_AES   26
Packit c4476c
#define D_IGE_192_AES   27
Packit c4476c
#define D_IGE_256_AES   28
Packit c4476c
#define D_GHASH         29
Packit c4476c
#define D_RAND          30
Packit c4476c
/* name of algorithms to test */
Packit c4476c
static const char *names[] = {
Packit c4476c
    "md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
Packit c4476c
    "des cbc", "des ede3", "idea cbc", "seed cbc",
Packit c4476c
    "rc2 cbc", "rc5-32/12 cbc", "blowfish cbc", "cast cbc",
Packit c4476c
    "aes-128 cbc", "aes-192 cbc", "aes-256 cbc",
Packit c4476c
    "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
Packit c4476c
    "evp", "sha256", "sha512", "whirlpool",
Packit c4476c
    "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
Packit c4476c
    "rand"
Packit c4476c
};
Packit c4476c
#define ALGOR_NUM       OSSL_NELEM(names)
Packit c4476c
Packit c4476c
/* list of configured algorithm (remaining) */
Packit c4476c
static const OPT_PAIR doit_choices[] = {
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
    {"md2", D_MD2},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MDC2
Packit c4476c
    {"mdc2", D_MDC2},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD4
Packit c4476c
    {"md4", D_MD4},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MD5
Packit c4476c
    {"md5", D_MD5},
Packit c4476c
    {"hmac", D_HMAC},
Packit c4476c
#endif
Packit c4476c
    {"sha1", D_SHA1},
Packit c4476c
    {"sha256", D_SHA256},
Packit c4476c
    {"sha512", D_SHA512},
Packit c4476c
#ifndef OPENSSL_NO_WHIRLPOOL
Packit c4476c
    {"whirlpool", D_WHIRLPOOL},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RMD160
Packit c4476c
    {"ripemd", D_RMD160},
Packit c4476c
    {"rmd160", D_RMD160},
Packit c4476c
    {"ripemd160", D_RMD160},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
    {"rc4", D_RC4},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
    {"des-cbc", D_CBC_DES},
Packit c4476c
    {"des-ede3", D_EDE3_DES},
Packit c4476c
#endif
Packit c4476c
    {"aes-128-cbc", D_CBC_128_AES},
Packit c4476c
    {"aes-192-cbc", D_CBC_192_AES},
Packit c4476c
    {"aes-256-cbc", D_CBC_256_AES},
Packit c4476c
    {"aes-128-ige", D_IGE_128_AES},
Packit c4476c
    {"aes-192-ige", D_IGE_192_AES},
Packit c4476c
    {"aes-256-ige", D_IGE_256_AES},
Packit c4476c
#ifndef OPENSSL_NO_RC2
Packit c4476c
    {"rc2-cbc", D_CBC_RC2},
Packit c4476c
    {"rc2", D_CBC_RC2},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC5
Packit c4476c
    {"rc5-cbc", D_CBC_RC5},
Packit c4476c
    {"rc5", D_CBC_RC5},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
    {"idea-cbc", D_CBC_IDEA},
Packit c4476c
    {"idea", D_CBC_IDEA},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_SEED
Packit c4476c
    {"seed-cbc", D_CBC_SEED},
Packit c4476c
    {"seed", D_CBC_SEED},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
    {"bf-cbc", D_CBC_BF},
Packit c4476c
    {"blowfish", D_CBC_BF},
Packit c4476c
    {"bf", D_CBC_BF},
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_CAST
Packit c4476c
    {"cast-cbc", D_CBC_CAST},
Packit c4476c
    {"cast", D_CBC_CAST},
Packit c4476c
    {"cast5", D_CBC_CAST},
Packit c4476c
#endif
Packit c4476c
    {"ghash", D_GHASH},
Packit c4476c
    {"rand", D_RAND}
Packit c4476c
};
Packit c4476c
Packit c4476c
static double results[ALGOR_NUM][OSSL_NELEM(lengths_list)];
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
# define R_DSA_512       0
Packit c4476c
# define R_DSA_1024      1
Packit c4476c
# define R_DSA_2048      2
Packit c4476c
static const OPT_PAIR dsa_choices[] = {
Packit c4476c
    {"dsa512", R_DSA_512},
Packit c4476c
    {"dsa1024", R_DSA_1024},
Packit c4476c
    {"dsa2048", R_DSA_2048}
Packit c4476c
};
Packit c4476c
# define DSA_NUM         OSSL_NELEM(dsa_choices)
Packit c4476c
Packit c4476c
static double dsa_results[DSA_NUM][2];  /* 2 ops: sign then verify */
Packit c4476c
#endif  /* OPENSSL_NO_DSA */
Packit c4476c
Packit c4476c
#define R_RSA_512       0
Packit c4476c
#define R_RSA_1024      1
Packit c4476c
#define R_RSA_2048      2
Packit c4476c
#define R_RSA_3072      3
Packit c4476c
#define R_RSA_4096      4
Packit c4476c
#define R_RSA_7680      5
Packit c4476c
#define R_RSA_15360     6
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
static const OPT_PAIR rsa_choices[] = {
Packit c4476c
    {"rsa512", R_RSA_512},
Packit c4476c
    {"rsa1024", R_RSA_1024},
Packit c4476c
    {"rsa2048", R_RSA_2048},
Packit c4476c
    {"rsa3072", R_RSA_3072},
Packit c4476c
    {"rsa4096", R_RSA_4096},
Packit c4476c
    {"rsa7680", R_RSA_7680},
Packit c4476c
    {"rsa15360", R_RSA_15360}
Packit c4476c
};
Packit c4476c
# define RSA_NUM OSSL_NELEM(rsa_choices)
Packit c4476c
Packit c4476c
static double rsa_results[RSA_NUM][2];  /* 2 ops: sign then verify */
Packit c4476c
#endif /* OPENSSL_NO_RSA */
Packit c4476c
Packit c4476c
enum {
Packit c4476c
    R_EC_P224,
Packit c4476c
    R_EC_P256,
Packit c4476c
    R_EC_P384,
Packit c4476c
    R_EC_P521,
Packit c4476c
    R_EC_X25519,
Packit c4476c
    R_EC_X448
Packit c4476c
};
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
static OPT_PAIR ecdsa_choices[] = {
Packit c4476c
    {"ecdsap224", R_EC_P224},
Packit c4476c
    {"ecdsap256", R_EC_P256},
Packit c4476c
    {"ecdsap384", R_EC_P384},
Packit c4476c
    {"ecdsap521", R_EC_P521},
Packit c4476c
};
Packit c4476c
# define ECDSA_NUM       OSSL_NELEM(ecdsa_choices)
Packit c4476c
Packit c4476c
static double ecdsa_results[ECDSA_NUM][2];    /* 2 ops: sign then verify */
Packit c4476c
Packit c4476c
static const OPT_PAIR ecdh_choices[] = {
Packit c4476c
    {"ecdhp224", R_EC_P224},
Packit c4476c
    {"ecdhp256", R_EC_P256},
Packit c4476c
    {"ecdhp384", R_EC_P384},
Packit c4476c
    {"ecdhp521", R_EC_P521},
Packit c4476c
    {"ecdhx25519", R_EC_X25519},
Packit c4476c
    {"ecdhx448", R_EC_X448}
Packit c4476c
};
Packit c4476c
# define EC_NUM       OSSL_NELEM(ecdh_choices)
Packit c4476c
Packit c4476c
static double ecdh_results[EC_NUM][1];  /* 1 op: derivation */
Packit c4476c
Packit c4476c
#define R_EC_Ed25519    0
Packit c4476c
#define R_EC_Ed448      1
Packit c4476c
static OPT_PAIR eddsa_choices[] = {
Packit c4476c
    {"ed25519", R_EC_Ed25519},
Packit c4476c
    {"ed448", R_EC_Ed448}
Packit c4476c
};
Packit c4476c
# define EdDSA_NUM       OSSL_NELEM(eddsa_choices)
Packit c4476c
Packit c4476c
static double eddsa_results[EdDSA_NUM][2];    /* 2 ops: sign then verify */
Packit c4476c
#endif /* OPENSSL_NO_EC */
Packit c4476c
Packit c4476c
#ifndef SIGALRM
Packit c4476c
# define COND(d) (count < (d))
Packit c4476c
# define COUNT(d) (d)
Packit c4476c
#else
Packit c4476c
# define COND(unused_cond) (run && count<0x7fffffff)
Packit c4476c
# define COUNT(d) (count)
Packit c4476c
#endif                          /* SIGALRM */
Packit c4476c
Packit c4476c
typedef struct loopargs_st {
Packit c4476c
    ASYNC_JOB *inprogress_job;
Packit c4476c
    ASYNC_WAIT_CTX *wait_ctx;
Packit c4476c
    unsigned char *buf;
Packit c4476c
    unsigned char *buf2;
Packit c4476c
    unsigned char *buf_malloc;
Packit c4476c
    unsigned char *buf2_malloc;
Packit c4476c
    unsigned char *key;
Packit c4476c
    unsigned int siglen;
Packit c4476c
    size_t sigsize;
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
    RSA *rsa_key[RSA_NUM];
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
    DSA *dsa_key[DSA_NUM];
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
    EC_KEY *ecdsa[ECDSA_NUM];
Packit c4476c
    EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
Packit c4476c
    EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
Packit c4476c
    unsigned char *secret_a;
Packit c4476c
    unsigned char *secret_b;
Packit c4476c
    size_t outlen[EC_NUM];
Packit c4476c
#endif
Packit c4476c
    EVP_CIPHER_CTX *ctx;
Packit c4476c
    HMAC_CTX *hctx;
Packit c4476c
    GCM128_CONTEXT *gcm_ctx;
Packit c4476c
} loopargs_t;
Packit c4476c
static int run_benchmark(int async_jobs, int (*loop_function) (void *),
Packit c4476c
                         loopargs_t * loopargs);
Packit c4476c
Packit c4476c
static unsigned int testnum;
Packit c4476c
Packit c4476c
/* Nb of iterations to do per algorithm and key-size */
Packit c4476c
static long c[ALGOR_NUM][OSSL_NELEM(lengths_list)];
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
static int EVP_Digest_MD2_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char md2[MD2_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(c[D_MD2][testnum]); count++) {
Packit c4476c
        if (!EVP_Digest(buf, (size_t)lengths[testnum], md2, NULL, EVP_md2(),
Packit c4476c
                        NULL))
Packit c4476c
            return -1;
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MDC2
Packit c4476c
static int EVP_Digest_MDC2_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char mdc2[MDC2_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(c[D_MDC2][testnum]); count++) {
Packit c4476c
        if (!EVP_Digest(buf, (size_t)lengths[testnum], mdc2, NULL, EVP_mdc2(),
Packit c4476c
                        NULL))
Packit c4476c
            return -1;
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD4
Packit c4476c
static int EVP_Digest_MD4_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char md4[MD4_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(c[D_MD4][testnum]); count++) {
Packit c4476c
        if (!EVP_Digest(buf, (size_t)lengths[testnum], md4, NULL, EVP_md4(),
Packit c4476c
                        NULL))
Packit c4476c
            return -1;
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD5
Packit c4476c
static int MD5_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char md5[MD5_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_MD5][testnum]); count++)
Packit c4476c
        MD5(buf, lengths[testnum], md5);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int HMAC_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    HMAC_CTX *hctx = tempargs->hctx;
Packit c4476c
    unsigned char hmac[MD5_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(c[D_HMAC][testnum]); count++) {
Packit c4476c
        HMAC_Init_ex(hctx, NULL, 0, NULL, NULL);
Packit c4476c
        HMAC_Update(hctx, buf, lengths[testnum]);
Packit c4476c
        HMAC_Final(hctx, hmac, NULL);
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
static int SHA1_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char sha[SHA_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_SHA1][testnum]); count++)
Packit c4476c
        SHA1(buf, lengths[testnum], sha);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int SHA256_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char sha256[SHA256_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_SHA256][testnum]); count++)
Packit c4476c
        SHA256(buf, lengths[testnum], sha256);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int SHA512_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char sha512[SHA512_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_SHA512][testnum]); count++)
Packit c4476c
        SHA512(buf, lengths[testnum], sha512);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_WHIRLPOOL
Packit c4476c
static int WHIRLPOOL_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_WHIRLPOOL][testnum]); count++)
Packit c4476c
        WHIRLPOOL(buf, lengths[testnum], whirlpool);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RMD160
Packit c4476c
static int EVP_Digest_RMD160_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_RMD160][testnum]); count++) {
Packit c4476c
        if (!EVP_Digest(buf, (size_t)lengths[testnum], &(rmd160[0]),
Packit c4476c
                        NULL, EVP_ripemd160(), NULL))
Packit c4476c
            return -1;
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
static RC4_KEY rc4_ks;
Packit c4476c
static int RC4_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_RC4][testnum]); count++)
Packit c4476c
        RC4(&rc4_ks, (size_t)lengths[testnum], buf, buf);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
static unsigned char DES_iv[8];
Packit c4476c
static DES_key_schedule sch;
Packit c4476c
static DES_key_schedule sch2;
Packit c4476c
static DES_key_schedule sch3;
Packit c4476c
static int DES_ncbc_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_CBC_DES][testnum]); count++)
Packit c4476c
        DES_ncbc_encrypt(buf, buf, lengths[testnum], &sch,
Packit c4476c
                         &DES_iv, DES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int DES_ede3_cbc_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_EDE3_DES][testnum]); count++)
Packit c4476c
        DES_ede3_cbc_encrypt(buf, buf, lengths[testnum],
Packit c4476c
                             &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#define MAX_BLOCK_SIZE 128
Packit c4476c
Packit c4476c
static unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
Packit c4476c
static AES_KEY aes_ks1, aes_ks2, aes_ks3;
Packit c4476c
static int AES_cbc_128_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_CBC_128_AES][testnum]); count++)
Packit c4476c
        AES_cbc_encrypt(buf, buf,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int AES_cbc_192_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_CBC_192_AES][testnum]); count++)
Packit c4476c
        AES_cbc_encrypt(buf, buf,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int AES_cbc_256_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_CBC_256_AES][testnum]); count++)
Packit c4476c
        AES_cbc_encrypt(buf, buf,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int AES_ige_128_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_IGE_128_AES][testnum]); count++)
Packit c4476c
        AES_ige_encrypt(buf, buf2,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks1, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int AES_ige_192_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_IGE_192_AES][testnum]); count++)
Packit c4476c
        AES_ige_encrypt(buf, buf2,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks2, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int AES_ige_256_encrypt_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_IGE_256_AES][testnum]); count++)
Packit c4476c
        AES_ige_encrypt(buf, buf2,
Packit c4476c
                        (size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int CRYPTO_gcm128_aad_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    GCM128_CONTEXT *gcm_ctx = tempargs->gcm_ctx;
Packit c4476c
    int count;
Packit c4476c
    for (count = 0; COND(c[D_GHASH][testnum]); count++)
Packit c4476c
        CRYPTO_gcm128_aad(gcm_ctx, buf, lengths[testnum]);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int RAND_bytes_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    int count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(c[D_RAND][testnum]); count++)
Packit c4476c
        RAND_bytes(buf, lengths[testnum]);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static long save_count = 0;
Packit c4476c
static int decrypt = 0;
Packit c4476c
static int EVP_Update_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EVP_CIPHER_CTX *ctx = tempargs->ctx;
Packit c4476c
    int outl, count, rc;
Packit c4476c
#ifndef SIGALRM
Packit c4476c
    int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
Packit c4476c
#endif
Packit c4476c
    if (decrypt) {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
            if (rc != 1) {
Packit c4476c
                /* reset iv in case of counter overflow */
Packit c4476c
                EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    } else {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
            if (rc != 1) {
Packit c4476c
                /* reset iv in case of counter overflow */
Packit c4476c
                EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (decrypt)
Packit c4476c
        EVP_DecryptFinal_ex(ctx, buf, &outl);
Packit c4476c
    else
Packit c4476c
        EVP_EncryptFinal_ex(ctx, buf, &outl);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * CCM does not support streaming. For the purpose of performance measurement,
Packit c4476c
 * each message is encrypted using the same (key,iv)-pair. Do not use this
Packit c4476c
 * code in your application.
Packit c4476c
 */
Packit c4476c
static int EVP_Update_loop_ccm(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EVP_CIPHER_CTX *ctx = tempargs->ctx;
Packit c4476c
    int outl, count;
Packit c4476c
    unsigned char tag[12];
Packit c4476c
#ifndef SIGALRM
Packit c4476c
    int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
Packit c4476c
#endif
Packit c4476c
    if (decrypt) {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
Packit c4476c
            /* reset iv */
Packit c4476c
            EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
Packit c4476c
            /* counter is reset on every update */
Packit c4476c
            EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
        }
Packit c4476c
    } else {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            /* restore iv length field */
Packit c4476c
            EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
Packit c4476c
            /* counter is reset on every update */
Packit c4476c
            EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (decrypt)
Packit c4476c
        EVP_DecryptFinal_ex(ctx, buf, &outl);
Packit c4476c
    else
Packit c4476c
        EVP_EncryptFinal_ex(ctx, buf, &outl);
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * To make AEAD benchmarking more relevant perform TLS-like operations,
Packit c4476c
 * 13-byte AAD followed by payload. But don't use TLS-formatted AAD, as
Packit c4476c
 * payload length is not actually limited by 16KB...
Packit c4476c
 */
Packit c4476c
static int EVP_Update_loop_aead(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EVP_CIPHER_CTX *ctx = tempargs->ctx;
Packit c4476c
    int outl, count;
Packit c4476c
    unsigned char aad[13] = { 0xcc };
Packit c4476c
    unsigned char faketag[16] = { 0xcc };
Packit c4476c
#ifndef SIGALRM
Packit c4476c
    int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
Packit c4476c
#endif
Packit c4476c
    if (decrypt) {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
Packit c4476c
            EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
Packit c4476c
                                sizeof(faketag), faketag);
Packit c4476c
            EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
Packit c4476c
            EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
            EVP_DecryptFinal_ex(ctx, buf + outl, &outl);
Packit c4476c
        }
Packit c4476c
    } else {
Packit c4476c
        for (count = 0; COND(nb_iter); count++) {
Packit c4476c
            EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
Packit c4476c
            EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad));
Packit c4476c
            EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
Packit c4476c
            EVP_EncryptFinal_ex(ctx, buf + outl, &outl);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static const EVP_MD *evp_md = NULL;
Packit c4476c
static int EVP_Digest_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char md[EVP_MAX_MD_SIZE];
Packit c4476c
    int count;
Packit c4476c
#ifndef SIGALRM
Packit c4476c
    int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
Packit c4476c
#endif
Packit c4476c
Packit c4476c
    for (count = 0; COND(nb_iter); count++) {
Packit c4476c
        if (!EVP_Digest(buf, lengths[testnum], md, NULL, evp_md, NULL))
Packit c4476c
            return -1;
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
static long rsa_c[RSA_NUM][2];  /* # RSA iteration test */
Packit c4476c
Packit c4476c
static int RSA_sign_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    unsigned int *rsa_num = &tempargs->siglen;
Packit c4476c
    RSA **rsa_key = tempargs->rsa_key;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(rsa_c[testnum][0]); count++) {
Packit c4476c
        ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
Packit c4476c
        if (ret == 0) {
Packit c4476c
            BIO_printf(bio_err, "RSA sign failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int RSA_verify_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    unsigned int rsa_num = tempargs->siglen;
Packit c4476c
    RSA **rsa_key = tempargs->rsa_key;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(rsa_c[testnum][1]); count++) {
Packit c4476c
        ret =
Packit c4476c
            RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[testnum]);
Packit c4476c
        if (ret <= 0) {
Packit c4476c
            BIO_printf(bio_err, "RSA verify failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
static long dsa_c[DSA_NUM][2];
Packit c4476c
static int DSA_sign_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    DSA **dsa_key = tempargs->dsa_key;
Packit c4476c
    unsigned int *siglen = &tempargs->siglen;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(dsa_c[testnum][0]); count++) {
Packit c4476c
        ret = DSA_sign(0, buf, 20, buf2, siglen, dsa_key[testnum]);
Packit c4476c
        if (ret == 0) {
Packit c4476c
            BIO_printf(bio_err, "DSA sign failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int DSA_verify_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    unsigned char *buf2 = tempargs->buf2;
Packit c4476c
    DSA **dsa_key = tempargs->dsa_key;
Packit c4476c
    unsigned int siglen = tempargs->siglen;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(dsa_c[testnum][1]); count++) {
Packit c4476c
        ret = DSA_verify(0, buf, 20, buf2, siglen, dsa_key[testnum]);
Packit c4476c
        if (ret <= 0) {
Packit c4476c
            BIO_printf(bio_err, "DSA verify failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
static long ecdsa_c[ECDSA_NUM][2];
Packit c4476c
static int ECDSA_sign_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EC_KEY **ecdsa = tempargs->ecdsa;
Packit c4476c
    unsigned char *ecdsasig = tempargs->buf2;
Packit c4476c
    unsigned int *ecdsasiglen = &tempargs->siglen;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(ecdsa_c[testnum][0]); count++) {
Packit c4476c
        ret = ECDSA_sign(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
Packit c4476c
        if (ret == 0) {
Packit c4476c
            BIO_printf(bio_err, "ECDSA sign failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int ECDSA_verify_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EC_KEY **ecdsa = tempargs->ecdsa;
Packit c4476c
    unsigned char *ecdsasig = tempargs->buf2;
Packit c4476c
    unsigned int ecdsasiglen = tempargs->siglen;
Packit c4476c
    int ret, count;
Packit c4476c
    for (count = 0; COND(ecdsa_c[testnum][1]); count++) {
Packit c4476c
        ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[testnum]);
Packit c4476c
        if (ret != 1) {
Packit c4476c
            BIO_printf(bio_err, "ECDSA verify failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
/* ******************************************************************** */
Packit c4476c
static long ecdh_c[EC_NUM][1];
Packit c4476c
Packit c4476c
static int ECDH_EVP_derive_key_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    EVP_PKEY_CTX *ctx = tempargs->ecdh_ctx[testnum];
Packit c4476c
    unsigned char *derived_secret = tempargs->secret_a;
Packit c4476c
    int count;
Packit c4476c
    size_t *outlen = &(tempargs->outlen[testnum]);
Packit c4476c
Packit c4476c
    for (count = 0; COND(ecdh_c[testnum][0]); count++)
Packit c4476c
        EVP_PKEY_derive(ctx, derived_secret, outlen);
Packit c4476c
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static long eddsa_c[EdDSA_NUM][2];
Packit c4476c
static int EdDSA_sign_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
Packit c4476c
    unsigned char *eddsasig = tempargs->buf2;
Packit c4476c
    size_t *eddsasigsize = &tempargs->sigsize;
Packit c4476c
    int ret, count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(eddsa_c[testnum][0]); count++) {
Packit c4476c
        ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
Packit c4476c
        if (ret == 0) {
Packit c4476c
            BIO_printf(bio_err, "EdDSA sign failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
Packit c4476c
static int EdDSA_verify_loop(void *args)
Packit c4476c
{
Packit c4476c
    loopargs_t *tempargs = *(loopargs_t **) args;
Packit c4476c
    unsigned char *buf = tempargs->buf;
Packit c4476c
    EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
Packit c4476c
    unsigned char *eddsasig = tempargs->buf2;
Packit c4476c
    size_t eddsasigsize = tempargs->sigsize;
Packit c4476c
    int ret, count;
Packit c4476c
Packit c4476c
    for (count = 0; COND(eddsa_c[testnum][1]); count++) {
Packit c4476c
        ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
Packit c4476c
        if (ret != 1) {
Packit c4476c
            BIO_printf(bio_err, "EdDSA verify failure\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            count = -1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    return count;
Packit c4476c
}
Packit c4476c
#endif                          /* OPENSSL_NO_EC */
Packit c4476c
Packit c4476c
static int run_benchmark(int async_jobs,
Packit c4476c
                         int (*loop_function) (void *), loopargs_t * loopargs)
Packit c4476c
{
Packit c4476c
    int job_op_count = 0;
Packit c4476c
    int total_op_count = 0;
Packit c4476c
    int num_inprogress = 0;
Packit c4476c
    int error = 0, i = 0, ret = 0;
Packit c4476c
    OSSL_ASYNC_FD job_fd = 0;
Packit c4476c
    size_t num_job_fds = 0;
Packit c4476c
Packit c4476c
    if (async_jobs == 0) {
Packit c4476c
        return loop_function((void *)&loopargs);
Packit c4476c
    }
Packit c4476c
Packit c4476c
    for (i = 0; i < async_jobs && !error; i++) {
Packit c4476c
        loopargs_t *looparg_item = loopargs + i;
Packit c4476c
Packit c4476c
        /* Copy pointer content (looparg_t item address) into async context */
Packit c4476c
        ret = ASYNC_start_job(&loopargs[i].inprogress_job, loopargs[i].wait_ctx,
Packit c4476c
                              &job_op_count, loop_function,
Packit c4476c
                              (void *)&looparg_item, sizeof(looparg_item));
Packit c4476c
        switch (ret) {
Packit c4476c
        case ASYNC_PAUSE:
Packit c4476c
            ++num_inprogress;
Packit c4476c
            break;
Packit c4476c
        case ASYNC_FINISH:
Packit c4476c
            if (job_op_count == -1) {
Packit c4476c
                error = 1;
Packit c4476c
            } else {
Packit c4476c
                total_op_count += job_op_count;
Packit c4476c
            }
Packit c4476c
            break;
Packit c4476c
        case ASYNC_NO_JOBS:
Packit c4476c
        case ASYNC_ERR:
Packit c4476c
            BIO_printf(bio_err, "Failure in the job\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            error = 1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    while (num_inprogress > 0) {
Packit c4476c
#if defined(OPENSSL_SYS_WINDOWS)
Packit c4476c
        DWORD avail = 0;
Packit c4476c
#elif defined(OPENSSL_SYS_UNIX)
Packit c4476c
        int select_result = 0;
Packit c4476c
        OSSL_ASYNC_FD max_fd = 0;
Packit c4476c
        fd_set waitfdset;
Packit c4476c
Packit c4476c
        FD_ZERO(&waitfdset);
Packit c4476c
Packit c4476c
        for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
Packit c4476c
            if (loopargs[i].inprogress_job == NULL)
Packit c4476c
                continue;
Packit c4476c
Packit c4476c
            if (!ASYNC_WAIT_CTX_get_all_fds
Packit c4476c
                (loopargs[i].wait_ctx, NULL, &num_job_fds)
Packit c4476c
                || num_job_fds > 1) {
Packit c4476c
                BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                error = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
            ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
Packit c4476c
                                       &num_job_fds);
Packit c4476c
            FD_SET(job_fd, &waitfdset);
Packit c4476c
            if (job_fd > max_fd)
Packit c4476c
                max_fd = job_fd;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (max_fd >= (OSSL_ASYNC_FD)FD_SETSIZE) {
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
Packit c4476c
                       "Decrease the value of async_jobs\n",
Packit c4476c
                       max_fd, FD_SETSIZE);
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            error = 1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);
Packit c4476c
        if (select_result == -1 && errno == EINTR)
Packit c4476c
            continue;
Packit c4476c
Packit c4476c
        if (select_result == -1) {
Packit c4476c
            BIO_printf(bio_err, "Failure in the select\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            error = 1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (select_result == 0)
Packit c4476c
            continue;
Packit c4476c
#endif
Packit c4476c
Packit c4476c
        for (i = 0; i < async_jobs; i++) {
Packit c4476c
            if (loopargs[i].inprogress_job == NULL)
Packit c4476c
                continue;
Packit c4476c
Packit c4476c
            if (!ASYNC_WAIT_CTX_get_all_fds
Packit c4476c
                (loopargs[i].wait_ctx, NULL, &num_job_fds)
Packit c4476c
                || num_job_fds > 1) {
Packit c4476c
                BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                error = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
            ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd,
Packit c4476c
                                       &num_job_fds);
Packit c4476c
Packit c4476c
#if defined(OPENSSL_SYS_UNIX)
Packit c4476c
            if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
Packit c4476c
                continue;
Packit c4476c
#elif defined(OPENSSL_SYS_WINDOWS)
Packit c4476c
            if (num_job_fds == 1
Packit c4476c
                && !PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL)
Packit c4476c
                && avail > 0)
Packit c4476c
                continue;
Packit c4476c
#endif
Packit c4476c
Packit c4476c
            ret = ASYNC_start_job(&loopargs[i].inprogress_job,
Packit c4476c
                                  loopargs[i].wait_ctx, &job_op_count,
Packit c4476c
                                  loop_function, (void *)(loopargs + i),
Packit c4476c
                                  sizeof(loopargs_t));
Packit c4476c
            switch (ret) {
Packit c4476c
            case ASYNC_PAUSE:
Packit c4476c
                break;
Packit c4476c
            case ASYNC_FINISH:
Packit c4476c
                if (job_op_count == -1) {
Packit c4476c
                    error = 1;
Packit c4476c
                } else {
Packit c4476c
                    total_op_count += job_op_count;
Packit c4476c
                }
Packit c4476c
                --num_inprogress;
Packit c4476c
                loopargs[i].inprogress_job = NULL;
Packit c4476c
                break;
Packit c4476c
            case ASYNC_NO_JOBS:
Packit c4476c
            case ASYNC_ERR:
Packit c4476c
                --num_inprogress;
Packit c4476c
                loopargs[i].inprogress_job = NULL;
Packit c4476c
                BIO_printf(bio_err, "Failure in the job\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                error = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    return error ? -1 : total_op_count;
Packit c4476c
}
Packit c4476c
Packit c4476c
int speed_main(int argc, char **argv)
Packit c4476c
{
Packit c4476c
    ENGINE *e = NULL;
Packit c4476c
    loopargs_t *loopargs = NULL;
Packit c4476c
    const char *prog;
Packit c4476c
    const char *engine_id = NULL;
Packit c4476c
    const EVP_CIPHER *evp_cipher = NULL;
Packit c4476c
    double d = 0.0;
Packit c4476c
    OPTION_CHOICE o;
Packit c4476c
    int async_init = 0, multiblock = 0, pr_header = 0;
Packit c4476c
    int doit[ALGOR_NUM] = { 0 };
Packit c4476c
    int ret = 1, misalign = 0, lengths_single = 0, aead = 0;
Packit c4476c
    long count = 0;
Packit c4476c
    unsigned int size_num = OSSL_NELEM(lengths_list);
Packit c4476c
    unsigned int i, k, loop, loopargs_len = 0, async_jobs = 0;
Packit c4476c
    int keylen;
Packit c4476c
    int buflen;
Packit c4476c
#ifndef NO_FORK
Packit c4476c
    int multi = 0;
Packit c4476c
#endif
Packit c4476c
#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) \
Packit c4476c
    || !defined(OPENSSL_NO_EC)
Packit c4476c
    long rsa_count = 1;
Packit c4476c
#endif
Packit c4476c
    openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
Packit c4476c
                                    ECDSA_SECONDS, ECDH_SECONDS,
Packit c4476c
                                    EdDSA_SECONDS };
Packit c4476c
Packit c4476c
    /* What follows are the buffers and key material. */
Packit c4476c
#ifndef OPENSSL_NO_RC5
Packit c4476c
    RC5_32_KEY rc5_ks;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC2
Packit c4476c
    RC2_KEY rc2_ks;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
    IDEA_KEY_SCHEDULE idea_ks;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_SEED
Packit c4476c
    SEED_KEY_SCHEDULE seed_ks;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
    BF_KEY bf_ks;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_CAST
Packit c4476c
    CAST_KEY cast_ks;
Packit c4476c
#endif
Packit c4476c
    static const unsigned char key16[16] = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
Packit c4476c
    };
Packit c4476c
    static const unsigned char key24[24] = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
Packit c4476c
        0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
Packit c4476c
    };
Packit c4476c
    static const unsigned char key32[32] = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
Packit c4476c
        0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
Packit c4476c
        0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
Packit c4476c
    };
Packit c4476c
#ifndef OPENSSL_NO_CAMELLIA
Packit c4476c
    static const unsigned char ckey24[24] = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
Packit c4476c
        0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
Packit c4476c
    };
Packit c4476c
    static const unsigned char ckey32[32] = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
Packit c4476c
        0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
Packit c4476c
        0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
Packit c4476c
    };
Packit c4476c
    CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
    static DES_cblock key = {
Packit c4476c
        0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
Packit c4476c
    };
Packit c4476c
    static DES_cblock key2 = {
Packit c4476c
        0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
Packit c4476c
    };
Packit c4476c
    static DES_cblock key3 = {
Packit c4476c
        0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
Packit c4476c
    };
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
    static const unsigned int rsa_bits[RSA_NUM] = {
Packit c4476c
        512, 1024, 2048, 3072, 4096, 7680, 15360
Packit c4476c
    };
Packit c4476c
    static const unsigned char *rsa_data[RSA_NUM] = {
Packit c4476c
        test512, test1024, test2048, test3072, test4096, test7680, test15360
Packit c4476c
    };
Packit c4476c
    static const int rsa_data_length[RSA_NUM] = {
Packit c4476c
        sizeof(test512), sizeof(test1024),
Packit c4476c
        sizeof(test2048), sizeof(test3072),
Packit c4476c
        sizeof(test4096), sizeof(test7680),
Packit c4476c
        sizeof(test15360)
Packit c4476c
    };
Packit c4476c
    int rsa_doit[RSA_NUM] = { 0 };
Packit c4476c
    int primes = RSA_DEFAULT_PRIME_NUM;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
    static const unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
Packit c4476c
    int dsa_doit[DSA_NUM] = { 0 };
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
    /*
Packit c4476c
     * We only test over the following curves as they are representative, To
Packit c4476c
     * add tests over more curves, simply add the curve NID and curve name to
Packit c4476c
     * the following arrays and increase the |ecdh_choices| list accordingly.
Packit c4476c
     */
Packit c4476c
    static const struct {
Packit c4476c
        const char *name;
Packit c4476c
        unsigned int nid;
Packit c4476c
        unsigned int bits;
Packit c4476c
    } test_curves[] = {
Packit c4476c
        /* Prime Curves */
Packit c4476c
        {"nistp224", NID_secp224r1, 224},
Packit c4476c
        {"nistp256", NID_X9_62_prime256v1, 256},
Packit c4476c
        {"nistp384", NID_secp384r1, 384},
Packit c4476c
        {"nistp521", NID_secp521r1, 521},
Packit c4476c
        /* Other and ECDH only ones */
Packit c4476c
        {"X25519", NID_X25519, 253},
Packit c4476c
        {"X448", NID_X448, 448}
Packit c4476c
    };
Packit c4476c
    static const struct {
Packit c4476c
        const char *name;
Packit c4476c
        unsigned int nid;
Packit c4476c
        unsigned int bits;
Packit c4476c
        size_t sigsize;
Packit c4476c
    } test_ed_curves[] = {
Packit c4476c
        /* EdDSA */
Packit c4476c
        {"Ed25519", NID_ED25519, 253, 64},
Packit c4476c
        {"Ed448", NID_ED448, 456, 114}
Packit c4476c
    };
Packit c4476c
    int ecdsa_doit[ECDSA_NUM] = { 0 };
Packit c4476c
    int ecdh_doit[EC_NUM] = { 0 };
Packit c4476c
    int eddsa_doit[EdDSA_NUM] = { 0 };
Packit c4476c
    OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
Packit c4476c
    OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
Packit c4476c
#endif                          /* ndef OPENSSL_NO_EC */
Packit c4476c
Packit c4476c
    prog = opt_init(argc, argv, speed_options);
Packit c4476c
    while ((o = opt_next()) != OPT_EOF) {
Packit c4476c
        switch (o) {
Packit c4476c
        case OPT_EOF:
Packit c4476c
        case OPT_ERR:
Packit c4476c
 opterr:
Packit c4476c
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
Packit c4476c
            goto end;
Packit c4476c
        case OPT_HELP:
Packit c4476c
            opt_help(speed_options);
Packit c4476c
            ret = 0;
Packit c4476c
            goto end;
Packit c4476c
        case OPT_ELAPSED:
Packit c4476c
            usertime = 0;
Packit c4476c
            break;
Packit c4476c
        case OPT_EVP:
Packit c4476c
            evp_md = NULL;
Packit c4476c
            evp_cipher = EVP_get_cipherbyname(opt_arg());
Packit c4476c
            if (evp_cipher == NULL)
Packit c4476c
                evp_md = EVP_get_digestbyname(opt_arg());
Packit c4476c
            if (evp_cipher == NULL && evp_md == NULL) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "%s: %s is an unknown cipher or digest\n",
Packit c4476c
                           prog, opt_arg());
Packit c4476c
                goto end;
Packit c4476c
            }
Packit c4476c
            doit[D_EVP] = 1;
Packit c4476c
            break;
Packit c4476c
        case OPT_DECRYPT:
Packit c4476c
            decrypt = 1;
Packit c4476c
            break;
Packit c4476c
        case OPT_ENGINE:
Packit c4476c
            /*
Packit c4476c
             * In a forked execution, an engine might need to be
Packit c4476c
             * initialised by each child process, not by the parent.
Packit c4476c
             * So store the name here and run setup_engine() later on.
Packit c4476c
             */
Packit c4476c
            engine_id = opt_arg();
Packit c4476c
            break;
Packit c4476c
        case OPT_MULTI:
Packit c4476c
#ifndef NO_FORK
Packit c4476c
            multi = atoi(opt_arg());
Packit c4476c
#endif
Packit c4476c
            break;
Packit c4476c
        case OPT_ASYNCJOBS:
Packit c4476c
#ifndef OPENSSL_NO_ASYNC
Packit c4476c
            async_jobs = atoi(opt_arg());
Packit c4476c
            if (!ASYNC_is_capable()) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "%s: async_jobs specified but async not supported\n",
Packit c4476c
                           prog);
Packit c4476c
                goto opterr;
Packit c4476c
            }
Packit c4476c
            if (async_jobs > 99999) {
Packit c4476c
                BIO_printf(bio_err, "%s: too many async_jobs\n", prog);
Packit c4476c
                goto opterr;
Packit c4476c
            }
Packit c4476c
#endif
Packit c4476c
            break;
Packit c4476c
        case OPT_MISALIGN:
Packit c4476c
            if (!opt_int(opt_arg(), &misalign))
Packit c4476c
                goto end;
Packit c4476c
            if (misalign > MISALIGN) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "%s: Maximum offset is %d\n", prog, MISALIGN);
Packit c4476c
                goto opterr;
Packit c4476c
            }
Packit c4476c
            break;
Packit c4476c
        case OPT_MR:
Packit c4476c
            mr = 1;
Packit c4476c
            break;
Packit c4476c
        case OPT_MB:
Packit c4476c
            multiblock = 1;
Packit c4476c
#ifdef OPENSSL_NO_MULTIBLOCK
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "%s: -mb specified but multi-block support is disabled\n",
Packit c4476c
                       prog);
Packit c4476c
            goto end;
Packit c4476c
#endif
Packit c4476c
            break;
Packit c4476c
        case OPT_R_CASES:
Packit c4476c
            if (!opt_rand(o))
Packit c4476c
                goto end;
Packit c4476c
            break;
Packit c4476c
        case OPT_PRIMES:
Packit c4476c
            if (!opt_int(opt_arg(), &primes))
Packit c4476c
                goto end;
Packit c4476c
            break;
Packit c4476c
        case OPT_SECONDS:
Packit c4476c
            seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
Packit c4476c
                        = seconds.ecdh = seconds.eddsa = atoi(opt_arg());
Packit c4476c
            break;
Packit c4476c
        case OPT_BYTES:
Packit c4476c
            lengths_single = atoi(opt_arg());
Packit c4476c
            lengths = &lengths_single;
Packit c4476c
            size_num = 1;
Packit c4476c
            break;
Packit c4476c
        case OPT_AEAD:
Packit c4476c
            aead = 1;
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    argc = opt_num_rest();
Packit c4476c
    argv = opt_rest();
Packit c4476c
Packit c4476c
    /* Remaining arguments are algorithms. */
Packit c4476c
    for (; *argv; argv++) {
Packit c4476c
        if (found(*argv, doit_choices, &i)) {
Packit c4476c
            doit[i] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
        if (strcmp(*argv, "des") == 0) {
Packit c4476c
            doit[D_CBC_DES] = doit[D_EDE3_DES] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#endif
Packit c4476c
        if (strcmp(*argv, "sha") == 0) {
Packit c4476c
            doit[D_SHA1] = doit[D_SHA256] = doit[D_SHA512] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
        if (strcmp(*argv, "openssl") == 0)
Packit c4476c
            continue;
Packit c4476c
        if (strcmp(*argv, "rsa") == 0) {
Packit c4476c
            for (loop = 0; loop < OSSL_NELEM(rsa_doit); loop++)
Packit c4476c
		if (!FIPS_mode() || loop != R_RSA_512)
Packit c4476c
                    rsa_doit[loop] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (found(*argv, rsa_choices, &i)) {
Packit c4476c
            rsa_doit[i] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
        if (strcmp(*argv, "dsa") == 0) {
Packit c4476c
            if (!FIPS_mode())
Packit c4476c
                dsa_doit[R_DSA_512] = 1;
Packit c4476c
            dsa_doit[R_DSA_1024] =
Packit c4476c
                dsa_doit[R_DSA_2048] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (found(*argv, dsa_choices, &i)) {
Packit c4476c
            dsa_doit[i] = 2;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#endif
Packit c4476c
        if (strcmp(*argv, "aes") == 0) {
Packit c4476c
            doit[D_CBC_128_AES] = doit[D_CBC_192_AES] = doit[D_CBC_256_AES] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#ifndef OPENSSL_NO_CAMELLIA
Packit c4476c
        if (strcmp(*argv, "camellia") == 0) {
Packit c4476c
            doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
        if (strcmp(*argv, "ecdsa") == 0) {
Packit c4476c
            for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
Packit c4476c
                ecdsa_doit[loop] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (found(*argv, ecdsa_choices, &i)) {
Packit c4476c
            ecdsa_doit[i] = 2;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (strcmp(*argv, "ecdh") == 0) {
Packit c4476c
            for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
Packit c4476c
                if(!FIPS_mode() || (loop != R_EC_X25519 && loop != R_EC_X448))
Packit c4476c
                    ecdh_doit[loop] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (found(*argv, ecdh_choices, &i)) {
Packit c4476c
            if(!FIPS_mode() || (i != R_EC_X25519 && i != R_EC_X448))
Packit c4476c
                ecdh_doit[i] = 2;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (!FIPS_mode() && strcmp(*argv, "eddsa") == 0) {
Packit c4476c
            for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
Packit c4476c
                eddsa_doit[loop] = 1;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
        if (!FIPS_mode() && found(*argv, eddsa_choices, &i)) {
Packit c4476c
            eddsa_doit[i] = 2;
Packit c4476c
            continue;
Packit c4476c
        }
Packit c4476c
#endif
Packit c4476c
        BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
Packit c4476c
        goto end;
Packit c4476c
    }
Packit c4476c
Packit c4476c
    /* Sanity checks */
Packit c4476c
    if (aead) {
Packit c4476c
        if (evp_cipher == NULL) {
Packit c4476c
            BIO_printf(bio_err, "-aead can be used only with an AEAD cipher\n");
Packit c4476c
            goto end;
Packit c4476c
        } else if (!(EVP_CIPHER_flags(evp_cipher) &
Packit c4476c
                     EVP_CIPH_FLAG_AEAD_CIPHER)) {
Packit c4476c
            BIO_printf(bio_err, "%s is not an AEAD cipher\n",
Packit c4476c
                       OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
Packit c4476c
            goto end;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (multiblock) {
Packit c4476c
        if (evp_cipher == NULL) {
Packit c4476c
            BIO_printf(bio_err,"-mb can be used only with a multi-block"
Packit c4476c
                               " capable cipher\n");
Packit c4476c
            goto end;
Packit c4476c
        } else if (!(EVP_CIPHER_flags(evp_cipher) &
Packit c4476c
                     EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
Packit c4476c
            BIO_printf(bio_err, "%s is not a multi-block capable\n",
Packit c4476c
                       OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)));
Packit c4476c
            goto end;
Packit c4476c
        } else if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with -mb");
Packit c4476c
            goto end;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    /* Initialize the job pool if async mode is enabled */
Packit c4476c
    if (async_jobs > 0) {
Packit c4476c
        async_init = ASYNC_init_thread(async_jobs, async_jobs);
Packit c4476c
        if (!async_init) {
Packit c4476c
            BIO_printf(bio_err, "Error creating the ASYNC job pool\n");
Packit c4476c
            goto end;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
Packit c4476c
    loopargs =
Packit c4476c
        app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
Packit c4476c
    memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
Packit c4476c
Packit c4476c
    for (i = 0; i < loopargs_len; i++) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            loopargs[i].wait_ctx = ASYNC_WAIT_CTX_new();
Packit c4476c
            if (loopargs[i].wait_ctx == NULL) {
Packit c4476c
                BIO_printf(bio_err, "Error creating the ASYNC_WAIT_CTX\n");
Packit c4476c
                goto end;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
Packit c4476c
        buflen = lengths[size_num - 1];
Packit c4476c
        if (buflen < 36)    /* size of random vector in RSA benchmark */
Packit c4476c
            buflen = 36;
Packit c4476c
        buflen += MAX_MISALIGNMENT + 1;
Packit c4476c
        loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
Packit c4476c
        loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
Packit c4476c
        memset(loopargs[i].buf_malloc, 0, buflen);
Packit c4476c
        memset(loopargs[i].buf2_malloc, 0, buflen);
Packit c4476c
Packit c4476c
        /* Align the start of buffers on a 64 byte boundary */
Packit c4476c
        loopargs[i].buf = loopargs[i].buf_malloc + misalign;
Packit c4476c
        loopargs[i].buf2 = loopargs[i].buf2_malloc + misalign;
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
        loopargs[i].secret_a = app_malloc(MAX_ECDH_SIZE, "ECDH secret a");
Packit c4476c
        loopargs[i].secret_b = app_malloc(MAX_ECDH_SIZE, "ECDH secret b");
Packit c4476c
#endif
Packit c4476c
    }
Packit c4476c
Packit c4476c
#ifndef NO_FORK
Packit c4476c
    if (multi && do_multi(multi, size_num))
Packit c4476c
        goto show_res;
Packit c4476c
#endif
Packit c4476c
Packit c4476c
    /* Initialize the engine after the fork */
Packit c4476c
    e = setup_engine(engine_id, 0);
Packit c4476c
Packit c4476c
    /* No parameters; turn on everything. */
Packit c4476c
    if ((argc == 0) && !doit[D_EVP]) {
Packit c4476c
        for (i = 0; i < ALGOR_NUM; i++)
Packit c4476c
            if (i != D_EVP &&
Packit c4476c
                (!FIPS_mode() || (i != D_WHIRLPOOL &&
Packit c4476c
                                  i != D_MD2 && i != D_MD4 &&
Packit c4476c
                                  i != D_MD5 && i != D_MDC2 &&
Packit c4476c
                                  i != D_RMD160)))
Packit c4476c
                doit[i] = 1;
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
        for (i = 0; i < RSA_NUM; i++)
Packit c4476c
            if (!FIPS_mode() || i != R_RSA_512)
Packit c4476c
                rsa_doit[i] = 1;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
        for (i = 0; i < DSA_NUM; i++)
Packit c4476c
            if (!FIPS_mode() || i != R_DSA_512)
Packit c4476c
                dsa_doit[i] = 1;
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
        for (loop = 0; loop < OSSL_NELEM(ecdsa_doit); loop++)
Packit c4476c
            ecdsa_doit[loop] = 1;
Packit c4476c
        for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
Packit c4476c
            if(!FIPS_mode() || (loop != R_EC_X25519 && loop != R_EC_X448))
Packit c4476c
                ecdh_doit[loop] = 1;
Packit c4476c
        if (!FIPS_mode())
Packit c4476c
            for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
Packit c4476c
                eddsa_doit[loop] = 1;
Packit c4476c
#endif
Packit c4476c
    }
Packit c4476c
    for (i = 0; i < ALGOR_NUM; i++)
Packit c4476c
        if (doit[i])
Packit c4476c
            pr_header++;
Packit c4476c
Packit c4476c
    if (usertime == 0 && !mr)
Packit c4476c
        BIO_printf(bio_err,
Packit c4476c
                   "You have chosen to measure elapsed time "
Packit c4476c
                   "instead of user CPU time.\n");
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
    for (i = 0; i < loopargs_len; i++) {
Packit c4476c
        if (primes > RSA_DEFAULT_PRIME_NUM) {
Packit c4476c
            /* for multi-prime RSA, skip this */
Packit c4476c
            break;
Packit c4476c
        }
Packit c4476c
        for (k = 0; k < RSA_NUM; k++) {
Packit c4476c
            const unsigned char *p;
Packit c4476c
Packit c4476c
            p = rsa_data[k];
Packit c4476c
            loopargs[i].rsa_key[k] =
Packit c4476c
                d2i_RSAPrivateKey(NULL, &p, rsa_data_length[k]);
Packit c4476c
            if (loopargs[i].rsa_key[k] == NULL) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "internal error loading RSA key number %d\n", k);
Packit c4476c
                goto end;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
    for (i = 0; i < loopargs_len; i++) {
Packit c4476c
        loopargs[i].dsa_key[0] = get_dsa(512);
Packit c4476c
        loopargs[i].dsa_key[1] = get_dsa(1024);
Packit c4476c
        loopargs[i].dsa_key[2] = get_dsa(2048);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
    DES_set_key_unchecked(&key, &sch;;
Packit c4476c
    DES_set_key_unchecked(&key2, &sch2);
Packit c4476c
    DES_set_key_unchecked(&key3, &sch3);
Packit c4476c
#endif
Packit c4476c
    AES_set_encrypt_key(key16, 128, &aes_ks1);
Packit c4476c
    AES_set_encrypt_key(key24, 192, &aes_ks2);
Packit c4476c
    AES_set_encrypt_key(key32, 256, &aes_ks3);
Packit c4476c
#ifndef OPENSSL_NO_CAMELLIA
Packit c4476c
    if (doit[D_CBC_128_CML] || doit[D_CBC_192_CML] || doit[D_CBC_256_CML]) {
Packit c4476c
        Camellia_set_key(key16, 128, &camellia_ks1);
Packit c4476c
        Camellia_set_key(ckey24, 192, &camellia_ks2);
Packit c4476c
        Camellia_set_key(ckey32, 256, &camellia_ks3);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
    if (doit[D_CBC_IDEA]) {
Packit c4476c
        IDEA_set_encrypt_key(key16, &idea_ks);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_SEED
Packit c4476c
    if (doit[D_CBC_SEED]) {
Packit c4476c
        SEED_set_key(key16, &seed_ks);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
   if (doit[D_RC4]) {
Packit c4476c
        RC4_set_key(&rc4_ks, 16, key16);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC2
Packit c4476c
    if (doit[D_CBC_RC2]) {
Packit c4476c
        RC2_set_key(&rc2_ks, 16, key16, 128);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC5
Packit c4476c
    if (doit[D_CBC_RC5]) {
Packit c4476c
        RC5_32_set_key(&rc5_ks, 16, key16, 12);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
    if (doit[D_CBC_BF]) {
Packit c4476c
        BF_set_key(&bf_ks, 16, key16);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_CAST
Packit c4476c
    if (doit[D_CBC_CAST]) {
Packit c4476c
        CAST_set_key(&cast_ks, 16, key16);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef SIGALRM
Packit c4476c
# ifndef OPENSSL_NO_DES
Packit c4476c
    BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
Packit c4476c
    count = 10;
Packit c4476c
    do {
Packit c4476c
        long it;
Packit c4476c
        count *= 2;
Packit c4476c
        Time_F(START);
Packit c4476c
        for (it = count; it; it--)
Packit c4476c
            DES_ecb_encrypt((DES_cblock *)loopargs[0].buf,
Packit c4476c
                            (DES_cblock *)loopargs[0].buf, &sch, DES_ENCRYPT);
Packit c4476c
        d = Time_F(STOP);
Packit c4476c
    } while (d < 3);
Packit c4476c
    save_count = count;
Packit c4476c
    c[D_MD2][0] = count / 10;
Packit c4476c
    c[D_MDC2][0] = count / 10;
Packit c4476c
    c[D_MD4][0] = count;
Packit c4476c
    c[D_MD5][0] = count;
Packit c4476c
    c[D_HMAC][0] = count;
Packit c4476c
    c[D_SHA1][0] = count;
Packit c4476c
    c[D_RMD160][0] = count;
Packit c4476c
    c[D_RC4][0] = count * 5;
Packit c4476c
    c[D_CBC_DES][0] = count;
Packit c4476c
    c[D_EDE3_DES][0] = count / 3;
Packit c4476c
    c[D_CBC_IDEA][0] = count;
Packit c4476c
    c[D_CBC_SEED][0] = count;
Packit c4476c
    c[D_CBC_RC2][0] = count;
Packit c4476c
    c[D_CBC_RC5][0] = count;
Packit c4476c
    c[D_CBC_BF][0] = count;
Packit c4476c
    c[D_CBC_CAST][0] = count;
Packit c4476c
    c[D_CBC_128_AES][0] = count;
Packit c4476c
    c[D_CBC_192_AES][0] = count;
Packit c4476c
    c[D_CBC_256_AES][0] = count;
Packit c4476c
    c[D_CBC_128_CML][0] = count;
Packit c4476c
    c[D_CBC_192_CML][0] = count;
Packit c4476c
    c[D_CBC_256_CML][0] = count;
Packit c4476c
    c[D_SHA256][0] = count;
Packit c4476c
    c[D_SHA512][0] = count;
Packit c4476c
    c[D_WHIRLPOOL][0] = count;
Packit c4476c
    c[D_IGE_128_AES][0] = count;
Packit c4476c
    c[D_IGE_192_AES][0] = count;
Packit c4476c
    c[D_IGE_256_AES][0] = count;
Packit c4476c
    c[D_GHASH][0] = count;
Packit c4476c
    c[D_RAND][0] = count;
Packit c4476c
Packit c4476c
    for (i = 1; i < size_num; i++) {
Packit c4476c
        long l0, l1;
Packit c4476c
Packit c4476c
        l0 = (long)lengths[0];
Packit c4476c
        l1 = (long)lengths[i];
Packit c4476c
Packit c4476c
        c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
Packit c4476c
        c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
Packit c4476c
        c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
Packit c4476c
        c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
Packit c4476c
        c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
Packit c4476c
        c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
Packit c4476c
        c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
Packit c4476c
        c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
Packit c4476c
        c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
Packit c4476c
        c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
Packit c4476c
        c[D_GHASH][i] = c[D_GHASH][0] * 4 * l0 / l1;
Packit c4476c
        c[D_RAND][i] = c[D_RAND][0] * 4 * l0 / l1;
Packit c4476c
Packit c4476c
        l0 = (long)lengths[i - 1];
Packit c4476c
Packit c4476c
        c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
Packit c4476c
        c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
Packit c4476c
        c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
Packit c4476c
        c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
Packit c4476c
        c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
Packit c4476c
        c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
Packit c4476c
    }
Packit c4476c
Packit c4476c
#  ifndef OPENSSL_NO_RSA
Packit c4476c
    rsa_c[R_RSA_512][0] = count / 2000;
Packit c4476c
    rsa_c[R_RSA_512][1] = count / 400;
Packit c4476c
    for (i = 1; i < RSA_NUM; i++) {
Packit c4476c
        rsa_c[i][0] = rsa_c[i - 1][0] / 8;
Packit c4476c
        rsa_c[i][1] = rsa_c[i - 1][1] / 4;
Packit c4476c
        if (rsa_doit[i] <= 1 && rsa_c[i][0] == 0)
Packit c4476c
            rsa_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (rsa_c[i][0] == 0) {
Packit c4476c
                rsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
Packit c4476c
                rsa_c[i][1] = 20;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#  endif
Packit c4476c
Packit c4476c
#  ifndef OPENSSL_NO_DSA
Packit c4476c
    dsa_c[R_DSA_512][0] = count / 1000;
Packit c4476c
    dsa_c[R_DSA_512][1] = count / 1000 / 2;
Packit c4476c
    for (i = 1; i < DSA_NUM; i++) {
Packit c4476c
        dsa_c[i][0] = dsa_c[i - 1][0] / 4;
Packit c4476c
        dsa_c[i][1] = dsa_c[i - 1][1] / 4;
Packit c4476c
        if (dsa_doit[i] <= 1 && dsa_c[i][0] == 0)
Packit c4476c
            dsa_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (dsa_c[i][0] == 0) {
Packit c4476c
                dsa_c[i][0] = 1; /* Set minimum iteration Nb to 1. */
Packit c4476c
                dsa_c[i][1] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#  endif
Packit c4476c
Packit c4476c
#  ifndef OPENSSL_NO_EC
Packit c4476c
    ecdsa_c[R_EC_P224][0] = count / 1000;
Packit c4476c
    ecdsa_c[R_EC_P224][1] = count / 1000 / 2;
Packit c4476c
    for (i = R_EC_P256; i <= R_EC_P521; i++) {
Packit c4476c
        ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
Packit c4476c
        ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
Packit c4476c
        if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
Packit c4476c
            ecdsa_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdsa_c[i][0] == 0) {
Packit c4476c
                ecdsa_c[i][0] = 1;
Packit c4476c
                ecdsa_c[i][1] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#   if 0
Packit c4476c
    ecdsa_c[R_EC_K163][0] = count / 1000;
Packit c4476c
    ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
Packit c4476c
    for (i = R_EC_K233; i <= R_EC_K571; i++) {
Packit c4476c
        ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
Packit c4476c
        ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
Packit c4476c
        if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
Packit c4476c
            ecdsa_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdsa_c[i][0] == 0) {
Packit c4476c
                ecdsa_c[i][0] = 1;
Packit c4476c
                ecdsa_c[i][1] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    ecdsa_c[R_EC_B163][0] = count / 1000;
Packit c4476c
    ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
Packit c4476c
    for (i = R_EC_B233; i <= R_EC_B571; i++) {
Packit c4476c
        ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
Packit c4476c
        ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
Packit c4476c
        if (ecdsa_doit[i] <= 1 && ecdsa_c[i][0] == 0)
Packit c4476c
            ecdsa_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdsa_c[i][0] == 0) {
Packit c4476c
                ecdsa_c[i][0] = 1;
Packit c4476c
                ecdsa_c[i][1] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#   endif
Packit c4476c
Packit c4476c
    ecdh_c[R_EC_P224][0] = count / 1000;
Packit c4476c
    for (i = R_EC_P256; i <= R_EC_P521; i++) {
Packit c4476c
        ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
Packit c4476c
        if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
Packit c4476c
            ecdh_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdh_c[i][0] == 0) {
Packit c4476c
                ecdh_c[i][0] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#   if 0
Packit c4476c
    ecdh_c[R_EC_K163][0] = count / 1000;
Packit c4476c
    for (i = R_EC_K233; i <= R_EC_K571; i++) {
Packit c4476c
        ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
Packit c4476c
        if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
Packit c4476c
            ecdh_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdh_c[i][0] == 0) {
Packit c4476c
                ecdh_c[i][0] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    ecdh_c[R_EC_B163][0] = count / 1000;
Packit c4476c
    for (i = R_EC_B233; i <= R_EC_B571; i++) {
Packit c4476c
        ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
Packit c4476c
        if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
Packit c4476c
            ecdh_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdh_c[i][0] == 0) {
Packit c4476c
                ecdh_c[i][0] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#   endif
Packit c4476c
    /* repeated code good to factorize */
Packit c4476c
    ecdh_c[R_EC_BRP256R1][0] = count / 1000;
Packit c4476c
    for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
Packit c4476c
        ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
Packit c4476c
        if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
Packit c4476c
            ecdh_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdh_c[i][0] == 0) {
Packit c4476c
                ecdh_c[i][0] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    ecdh_c[R_EC_BRP256T1][0] = count / 1000;
Packit c4476c
    for (i = R_EC_BRP384T1; i <= R_EC_BRP512T1; i += 2) {
Packit c4476c
        ecdh_c[i][0] = ecdh_c[i - 2][0] / 2;
Packit c4476c
        if (ecdh_doit[i] <= 1 && ecdh_c[i][0] == 0)
Packit c4476c
            ecdh_doit[i] = 0;
Packit c4476c
        else {
Packit c4476c
            if (ecdh_c[i][0] == 0) {
Packit c4476c
                ecdh_c[i][0] = 1;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    /* default iteration count for the last two EC Curves */
Packit c4476c
    ecdh_c[R_EC_X25519][0] = count / 1800;
Packit c4476c
    ecdh_c[R_EC_X448][0] = count / 7200;
Packit c4476c
Packit c4476c
    eddsa_c[R_EC_Ed25519][0] = count / 1800;
Packit c4476c
    eddsa_c[R_EC_Ed448][0] = count / 7200;
Packit c4476c
#  endif
Packit c4476c
Packit c4476c
# else
Packit c4476c
/* not worth fixing */
Packit c4476c
#  error "You cannot disable DES on systems without SIGALRM."
Packit c4476c
# endif                         /* OPENSSL_NO_DES */
Packit c4476c
#elif SIGALRM > 0
Packit c4476c
    signal(SIGALRM, alarmed);
Packit c4476c
#endif                          /* SIGALRM */
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
    if (doit[D_MD2]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_MD2], c[D_MD2][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, EVP_Digest_MD2_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_MD2, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_MDC2
Packit c4476c
    if (doit[D_MDC2]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_MDC2], c[D_MDC2][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, EVP_Digest_MDC2_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_MDC2, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD4
Packit c4476c
    if (doit[D_MD4]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_MD4], c[D_MD4][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, EVP_Digest_MD4_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_MD4, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_MD5
Packit c4476c
    if (doit[D_MD5]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_MD5], c[D_MD5][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, MD5_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_MD5, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    if (doit[D_HMAC]) {
Packit c4476c
        static const char hmac_key[] = "This is a key...";
Packit c4476c
        int len = strlen(hmac_key);
Packit c4476c
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            loopargs[i].hctx = HMAC_CTX_new();
Packit c4476c
            HMAC_CTX_set_flags(loopargs[i].hctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
Packit c4476c
            if (loopargs[i].hctx == NULL) {
Packit c4476c
                BIO_printf(bio_err, "HMAC malloc failure, exiting...");
Packit c4476c
                exit(1);
Packit c4476c
            }
Packit c4476c
Packit c4476c
            HMAC_Init_ex(loopargs[i].hctx, hmac_key, len, EVP_md5(), NULL);
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_HMAC], c[D_HMAC][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, HMAC_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_HMAC, testnum, count, d);
Packit c4476c
        }
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            HMAC_CTX_free(loopargs[i].hctx);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
    if (doit[D_SHA1]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_SHA1], c[D_SHA1][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, SHA1_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_SHA1, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_SHA256]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_SHA256], c[D_SHA256][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, SHA256_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_SHA256, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_SHA512]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_SHA512], c[D_SHA512][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, SHA512_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_SHA512, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#ifndef OPENSSL_NO_WHIRLPOOL
Packit c4476c
    if (doit[D_WHIRLPOOL]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, WHIRLPOOL_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_WHIRLPOOL, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RMD160
Packit c4476c
    if (doit[D_RMD160]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_RMD160], c[D_RMD160][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, EVP_Digest_RMD160_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_RMD160, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
    if (doit[D_RC4]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_RC4], c[D_RC4][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, RC4_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_RC4, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
    if (doit[D_CBC_DES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_CBC_DES], c[D_CBC_DES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, DES_ncbc_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_DES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    if (doit[D_EDE3_DES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_EDE3_DES], c[D_EDE3_DES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, DES_ede3_cbc_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_EDE3_DES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
Packit c4476c
    if (doit[D_CBC_128_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_cbc_128_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_128_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_CBC_192_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_cbc_192_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_192_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_CBC_256_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_cbc_256_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_256_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    if (doit[D_IGE_128_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_ige_128_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_IGE_128_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_IGE_192_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_ige_192_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_IGE_192_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_IGE_256_AES]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, AES_ige_256_encrypt_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_IGE_256_AES, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_GHASH]) {
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            loopargs[i].gcm_ctx =
Packit c4476c
                CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
Packit c4476c
            CRYPTO_gcm128_setiv(loopargs[i].gcm_ctx,
Packit c4476c
                                (unsigned char *)"0123456789ab", 12);
Packit c4476c
        }
Packit c4476c
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_GHASH], c[D_GHASH][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, CRYPTO_gcm128_aad_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_GHASH, testnum, count, d);
Packit c4476c
        }
Packit c4476c
        for (i = 0; i < loopargs_len; i++)
Packit c4476c
            CRYPTO_gcm128_release(loopargs[i].gcm_ctx);
Packit c4476c
    }
Packit c4476c
#ifndef OPENSSL_NO_CAMELLIA
Packit c4476c
    if (doit[D_CBC_128_CML]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_128_CML]);
Packit c4476c
            doit[D_CBC_128_CML] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_128_CML][testnum]); count++)
Packit c4476c
                Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                     (size_t)lengths[testnum], &camellia_ks1,
Packit c4476c
                                     iv, CAMELLIA_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_128_CML, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_CBC_192_CML]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_192_CML]);
Packit c4476c
            doit[D_CBC_192_CML] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            if (async_jobs > 0) {
Packit c4476c
                BIO_printf(bio_err, "Async mode is not supported, exiting...");
Packit c4476c
                exit(1);
Packit c4476c
            }
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_192_CML][testnum]); count++)
Packit c4476c
                Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                     (size_t)lengths[testnum], &camellia_ks2,
Packit c4476c
                                     iv, CAMELLIA_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_192_CML, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
    if (doit[D_CBC_256_CML]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_256_CML]);
Packit c4476c
            doit[D_CBC_256_CML] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_256_CML][testnum]); count++)
Packit c4476c
                Camellia_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                     (size_t)lengths[testnum], &camellia_ks3,
Packit c4476c
                                     iv, CAMELLIA_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_256_CML, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
    if (doit[D_CBC_IDEA]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_IDEA]);
Packit c4476c
            doit[D_CBC_IDEA] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_IDEA][testnum]); count++)
Packit c4476c
                IDEA_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                 (size_t)lengths[testnum], &idea_ks,
Packit c4476c
                                 iv, IDEA_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_IDEA, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_SEED
Packit c4476c
    if (doit[D_CBC_SEED]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_SEED]);
Packit c4476c
            doit[D_CBC_SEED] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_SEED], c[D_CBC_SEED][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_SEED][testnum]); count++)
Packit c4476c
                SEED_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                 (size_t)lengths[testnum], &seed_ks, iv, 1);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_SEED, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC2
Packit c4476c
    if (doit[D_CBC_RC2]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_RC2]);
Packit c4476c
            doit[D_CBC_RC2] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_RC2], c[D_CBC_RC2][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            if (async_jobs > 0) {
Packit c4476c
                BIO_printf(bio_err, "Async mode is not supported, exiting...");
Packit c4476c
                exit(1);
Packit c4476c
            }
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_RC2][testnum]); count++)
Packit c4476c
                RC2_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                (size_t)lengths[testnum], &rc2_ks,
Packit c4476c
                                iv, RC2_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_RC2, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC5
Packit c4476c
    if (doit[D_CBC_RC5]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_RC5]);
Packit c4476c
            doit[D_CBC_RC5] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_RC5], c[D_CBC_RC5][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            if (async_jobs > 0) {
Packit c4476c
                BIO_printf(bio_err, "Async mode is not supported, exiting...");
Packit c4476c
                exit(1);
Packit c4476c
            }
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_RC5][testnum]); count++)
Packit c4476c
                RC5_32_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                   (size_t)lengths[testnum], &rc5_ks,
Packit c4476c
                                   iv, RC5_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_RC5, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
    if (doit[D_CBC_BF]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_BF]);
Packit c4476c
            doit[D_CBC_BF] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_BF], c[D_CBC_BF][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_BF][testnum]); count++)
Packit c4476c
                BF_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                               (size_t)lengths[testnum], &bf_ks,
Packit c4476c
                               iv, BF_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_BF, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_CAST
Packit c4476c
    if (doit[D_CBC_CAST]) {
Packit c4476c
        if (async_jobs > 0) {
Packit c4476c
            BIO_printf(bio_err, "Async mode is not supported with %s\n",
Packit c4476c
                       names[D_CBC_CAST]);
Packit c4476c
            doit[D_CBC_CAST] = 0;
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num && async_init == 0; testnum++) {
Packit c4476c
            print_message(names[D_CBC_CAST], c[D_CBC_CAST][testnum],
Packit c4476c
                          lengths[testnum], seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            for (count = 0; COND(c[D_CBC_CAST][testnum]); count++)
Packit c4476c
                CAST_cbc_encrypt(loopargs[0].buf, loopargs[0].buf,
Packit c4476c
                                 (size_t)lengths[testnum], &cast_ks,
Packit c4476c
                                 iv, CAST_ENCRYPT);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_CBC_CAST, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
    if (doit[D_RAND]) {
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            print_message(names[D_RAND], c[D_RAND][testnum], lengths[testnum],
Packit c4476c
                          seconds.sym);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, RAND_bytes_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            print_result(D_RAND, testnum, count, d);
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    if (doit[D_EVP]) {
Packit c4476c
        if (evp_cipher != NULL) {
Packit c4476c
            int (*loopfunc)(void *args) = EVP_Update_loop;
Packit c4476c
Packit c4476c
            if (multiblock && (EVP_CIPHER_flags(evp_cipher) &
Packit c4476c
                               EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
Packit c4476c
                multiblock_speed(evp_cipher, lengths_single, &seconds);
Packit c4476c
                ret = 0;
Packit c4476c
                goto end;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            names[D_EVP] = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher));
Packit c4476c
Packit c4476c
            if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_CCM_MODE) {
Packit c4476c
                loopfunc = EVP_Update_loop_ccm;
Packit c4476c
            } else if (aead && (EVP_CIPHER_flags(evp_cipher) &
Packit c4476c
                                EVP_CIPH_FLAG_AEAD_CIPHER)) {
Packit c4476c
                loopfunc = EVP_Update_loop_aead;
Packit c4476c
                if (lengths == lengths_list) {
Packit c4476c
                    lengths = aead_lengths_list;
Packit c4476c
                    size_num = OSSL_NELEM(aead_lengths_list);
Packit c4476c
                }
Packit c4476c
            }
Packit c4476c
Packit c4476c
            for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
                print_message(names[D_EVP], save_count, lengths[testnum],
Packit c4476c
                              seconds.sym);
Packit c4476c
Packit c4476c
                for (k = 0; k < loopargs_len; k++) {
Packit c4476c
                    loopargs[k].ctx = EVP_CIPHER_CTX_new();
Packit c4476c
                    if (loopargs[k].ctx == NULL) {
Packit c4476c
                        BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
Packit c4476c
                        exit(1);
Packit c4476c
                    }
Packit c4476c
                    if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
Packit c4476c
                                           NULL, iv, decrypt ? 0 : 1)) {
Packit c4476c
                        BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
Packit c4476c
                        ERR_print_errors(bio_err);
Packit c4476c
                        exit(1);
Packit c4476c
                    }
Packit c4476c
Packit c4476c
                    EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
Packit c4476c
Packit c4476c
                    keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
Packit c4476c
                    loopargs[k].key = app_malloc(keylen, "evp_cipher key");
Packit c4476c
                    EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
Packit c4476c
                    if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
Packit c4476c
                                           loopargs[k].key, NULL, -1)) {
Packit c4476c
                        BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
Packit c4476c
                        ERR_print_errors(bio_err);
Packit c4476c
                        exit(1);
Packit c4476c
                    }
Packit c4476c
                    OPENSSL_clear_free(loopargs[k].key, keylen);
Packit c4476c
                }
Packit c4476c
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, loopfunc, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
                for (k = 0; k < loopargs_len; k++) {
Packit c4476c
                    EVP_CIPHER_CTX_free(loopargs[k].ctx);
Packit c4476c
                }
Packit c4476c
                print_result(D_EVP, testnum, count, d);
Packit c4476c
            }
Packit c4476c
        } else if (evp_md != NULL) {
Packit c4476c
            names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md));
Packit c4476c
Packit c4476c
            for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
                print_message(names[D_EVP], save_count, lengths[testnum],
Packit c4476c
                              seconds.sym);
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
                print_result(D_EVP, testnum, count, d);
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    for (i = 0; i < loopargs_len; i++)
Packit c4476c
        if (RAND_bytes(loopargs[i].buf, 36) <= 0)
Packit c4476c
            goto end;
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
    for (testnum = 0; testnum < RSA_NUM; testnum++) {
Packit c4476c
        int st = 0;
Packit c4476c
        if (!rsa_doit[testnum])
Packit c4476c
            continue;
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            if (primes > 2) {
Packit c4476c
                /* we haven't set keys yet,  generate multi-prime RSA keys */
Packit c4476c
                BIGNUM *bn = BN_new();
Packit c4476c
Packit c4476c
                if (bn == NULL)
Packit c4476c
                    goto end;
Packit c4476c
                if (!BN_set_word(bn, RSA_F4)) {
Packit c4476c
                    BN_free(bn);
Packit c4476c
                    goto end;
Packit c4476c
                }
Packit c4476c
Packit c4476c
                BIO_printf(bio_err, "Generate multi-prime RSA key for %s\n",
Packit c4476c
                           rsa_choices[testnum].name);
Packit c4476c
Packit c4476c
                loopargs[i].rsa_key[testnum] = RSA_new();
Packit c4476c
                if (loopargs[i].rsa_key[testnum] == NULL) {
Packit c4476c
                    BN_free(bn);
Packit c4476c
                    goto end;
Packit c4476c
                }
Packit c4476c
Packit c4476c
                if (!RSA_generate_multi_prime_key(loopargs[i].rsa_key[testnum],
Packit c4476c
                                                  rsa_bits[testnum],
Packit c4476c
                                                  primes, bn, NULL)) {
Packit c4476c
                    BN_free(bn);
Packit c4476c
                    goto end;
Packit c4476c
                }
Packit c4476c
                BN_free(bn);
Packit c4476c
            }
Packit c4476c
            st = RSA_sign(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
Packit c4476c
                          &loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
Packit c4476c
            if (st == 0)
Packit c4476c
                break;
Packit c4476c
        }
Packit c4476c
        if (st == 0) {
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "RSA sign failure.  No RSA sign will be done.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            rsa_count = 1;
Packit c4476c
        } else {
Packit c4476c
            pkey_print_message("private", "rsa",
Packit c4476c
                               rsa_c[testnum][0], rsa_bits[testnum],
Packit c4476c
                               seconds.rsa);
Packit c4476c
            /* RSA_blinding_on(rsa_key[testnum],NULL); */
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, RSA_sign_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       mr ? "+R1:%ld:%d:%.2f\n"
Packit c4476c
                       : "%ld %u bits private RSA's in %.2fs\n",
Packit c4476c
                       count, rsa_bits[testnum], d);
Packit c4476c
            rsa_results[testnum][0] = (double)count / d;
Packit c4476c
            rsa_count = count;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            st = RSA_verify(NID_md5_sha1, loopargs[i].buf, 36, loopargs[i].buf2,
Packit c4476c
                            loopargs[i].siglen, loopargs[i].rsa_key[testnum]);
Packit c4476c
            if (st <= 0)
Packit c4476c
                break;
Packit c4476c
        }
Packit c4476c
        if (st <= 0) {
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "RSA verify failure.  No RSA verify will be done.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            rsa_doit[testnum] = 0;
Packit c4476c
        } else {
Packit c4476c
            pkey_print_message("public", "rsa",
Packit c4476c
                               rsa_c[testnum][1], rsa_bits[testnum],
Packit c4476c
                               seconds.rsa);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, RSA_verify_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       mr ? "+R2:%ld:%d:%.2f\n"
Packit c4476c
                       : "%ld %u bits public RSA's in %.2fs\n",
Packit c4476c
                       count, rsa_bits[testnum], d);
Packit c4476c
            rsa_results[testnum][1] = (double)count / d;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (rsa_count <= 1) {
Packit c4476c
            /* if longer than 10s, don't do any more */
Packit c4476c
            for (testnum++; testnum < RSA_NUM; testnum++)
Packit c4476c
                rsa_doit[testnum] = 0;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif                          /* OPENSSL_NO_RSA */
Packit c4476c
Packit c4476c
    for (i = 0; i < loopargs_len; i++)
Packit c4476c
        if (RAND_bytes(loopargs[i].buf, 36) <= 0)
Packit c4476c
            goto end;
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
    for (testnum = 0; testnum < DSA_NUM; testnum++) {
Packit c4476c
        int st = 0;
Packit c4476c
        if (!dsa_doit[testnum])
Packit c4476c
            continue;
Packit c4476c
Packit c4476c
        /* DSA_generate_key(dsa_key[testnum]); */
Packit c4476c
        /* DSA_sign_setup(dsa_key[testnum],NULL); */
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            st = DSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
Packit c4476c
                          &loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
Packit c4476c
            if (st == 0)
Packit c4476c
                break;
Packit c4476c
        }
Packit c4476c
        if (st == 0) {
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "DSA sign failure.  No DSA sign will be done.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            rsa_count = 1;
Packit c4476c
        } else {
Packit c4476c
            pkey_print_message("sign", "dsa",
Packit c4476c
                               dsa_c[testnum][0], dsa_bits[testnum],
Packit c4476c
                               seconds.dsa);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, DSA_sign_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       mr ? "+R3:%ld:%u:%.2f\n"
Packit c4476c
                       : "%ld %u bits DSA signs in %.2fs\n",
Packit c4476c
                       count, dsa_bits[testnum], d);
Packit c4476c
            dsa_results[testnum][0] = (double)count / d;
Packit c4476c
            rsa_count = count;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            st = DSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
Packit c4476c
                            loopargs[i].siglen, loopargs[i].dsa_key[testnum]);
Packit c4476c
            if (st <= 0)
Packit c4476c
                break;
Packit c4476c
        }
Packit c4476c
        if (st <= 0) {
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       "DSA verify failure.  No DSA verify will be done.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            dsa_doit[testnum] = 0;
Packit c4476c
        } else {
Packit c4476c
            pkey_print_message("verify", "dsa",
Packit c4476c
                               dsa_c[testnum][1], dsa_bits[testnum],
Packit c4476c
                               seconds.dsa);
Packit c4476c
            Time_F(START);
Packit c4476c
            count = run_benchmark(async_jobs, DSA_verify_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       mr ? "+R4:%ld:%u:%.2f\n"
Packit c4476c
                       : "%ld %u bits DSA verify in %.2fs\n",
Packit c4476c
                       count, dsa_bits[testnum], d);
Packit c4476c
            dsa_results[testnum][1] = (double)count / d;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (rsa_count <= 1) {
Packit c4476c
            /* if longer than 10s, don't do any more */
Packit c4476c
            for (testnum++; testnum < DSA_NUM; testnum++)
Packit c4476c
                dsa_doit[testnum] = 0;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
#endif                          /* OPENSSL_NO_DSA */
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
    for (testnum = 0; testnum < ECDSA_NUM; testnum++) {
Packit c4476c
        int st = 1;
Packit c4476c
Packit c4476c
        if (!ecdsa_doit[testnum])
Packit c4476c
            continue;           /* Ignore Curve */
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            loopargs[i].ecdsa[testnum] =
Packit c4476c
                EC_KEY_new_by_curve_name(test_curves[testnum].nid);
Packit c4476c
            if (loopargs[i].ecdsa[testnum] == NULL) {
Packit c4476c
                st = 0;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
        if (st == 0) {
Packit c4476c
            BIO_printf(bio_err, "ECDSA failure.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            rsa_count = 1;
Packit c4476c
        } else {
Packit c4476c
            for (i = 0; i < loopargs_len; i++) {
Packit c4476c
                EC_KEY_precompute_mult(loopargs[i].ecdsa[testnum], NULL);
Packit c4476c
                /* Perform ECDSA signature test */
Packit c4476c
                EC_KEY_generate_key(loopargs[i].ecdsa[testnum]);
Packit c4476c
                st = ECDSA_sign(0, loopargs[i].buf, 20, loopargs[i].buf2,
Packit c4476c
                                &loopargs[i].siglen,
Packit c4476c
                                loopargs[i].ecdsa[testnum]);
Packit c4476c
                if (st == 0)
Packit c4476c
                    break;
Packit c4476c
            }
Packit c4476c
            if (st == 0) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "ECDSA sign failure.  No ECDSA sign will be done.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
            } else {
Packit c4476c
                pkey_print_message("sign", "ecdsa",
Packit c4476c
                                   ecdsa_c[testnum][0],
Packit c4476c
                                   test_curves[testnum].bits, seconds.ecdsa);
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, ECDSA_sign_loop, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           mr ? "+R5:%ld:%u:%.2f\n" :
Packit c4476c
                           "%ld %u bits ECDSA signs in %.2fs \n",
Packit c4476c
                           count, test_curves[testnum].bits, d);
Packit c4476c
                ecdsa_results[testnum][0] = (double)count / d;
Packit c4476c
                rsa_count = count;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            /* Perform ECDSA verification test */
Packit c4476c
            for (i = 0; i < loopargs_len; i++) {
Packit c4476c
                st = ECDSA_verify(0, loopargs[i].buf, 20, loopargs[i].buf2,
Packit c4476c
                                  loopargs[i].siglen,
Packit c4476c
                                  loopargs[i].ecdsa[testnum]);
Packit c4476c
                if (st != 1)
Packit c4476c
                    break;
Packit c4476c
            }
Packit c4476c
            if (st != 1) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "ECDSA verify failure.  No ECDSA verify will be done.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                ecdsa_doit[testnum] = 0;
Packit c4476c
            } else {
Packit c4476c
                pkey_print_message("verify", "ecdsa",
Packit c4476c
                                   ecdsa_c[testnum][1],
Packit c4476c
                                   test_curves[testnum].bits, seconds.ecdsa);
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, ECDSA_verify_loop, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           mr ? "+R6:%ld:%u:%.2f\n"
Packit c4476c
                           : "%ld %u bits ECDSA verify in %.2fs\n",
Packit c4476c
                           count, test_curves[testnum].bits, d);
Packit c4476c
                ecdsa_results[testnum][1] = (double)count / d;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            if (rsa_count <= 1) {
Packit c4476c
                /* if longer than 10s, don't do any more */
Packit c4476c
                for (testnum++; testnum < ECDSA_NUM; testnum++)
Packit c4476c
                    ecdsa_doit[testnum] = 0;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    for (testnum = 0; testnum < EC_NUM; testnum++) {
Packit c4476c
        int ecdh_checks = 1;
Packit c4476c
Packit c4476c
        if (!ecdh_doit[testnum])
Packit c4476c
            continue;
Packit c4476c
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            EVP_PKEY_CTX *kctx = NULL;
Packit c4476c
            EVP_PKEY_CTX *test_ctx = NULL;
Packit c4476c
            EVP_PKEY_CTX *ctx = NULL;
Packit c4476c
            EVP_PKEY *key_A = NULL;
Packit c4476c
            EVP_PKEY *key_B = NULL;
Packit c4476c
            size_t outlen;
Packit c4476c
            size_t test_outlen;
Packit c4476c
Packit c4476c
            /* Ensure that the error queue is empty */
Packit c4476c
            if (ERR_peek_error()) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "WARNING: the error queue contains previous unhandled errors.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
            }
Packit c4476c
Packit c4476c
            /* Let's try to create a ctx directly from the NID: this works for
Packit c4476c
             * curves like Curve25519 that are not implemented through the low
Packit c4476c
             * level EC interface.
Packit c4476c
             * If this fails we try creating a EVP_PKEY_EC generic param ctx,
Packit c4476c
             * then we set the curve by NID before deriving the actual keygen
Packit c4476c
             * ctx for that specific curve. */
Packit c4476c
            kctx = EVP_PKEY_CTX_new_id(test_curves[testnum].nid, NULL); /* keygen ctx from NID */
Packit c4476c
            if (!kctx) {
Packit c4476c
                EVP_PKEY_CTX *pctx = NULL;
Packit c4476c
                EVP_PKEY *params = NULL;
Packit c4476c
Packit c4476c
                /* If we reach this code EVP_PKEY_CTX_new_id() failed and a
Packit c4476c
                 * "int_ctx_new:unsupported algorithm" error was added to the
Packit c4476c
                 * error queue.
Packit c4476c
                 * We remove it from the error queue as we are handling it. */
Packit c4476c
                unsigned long error = ERR_peek_error(); /* peek the latest error in the queue */
Packit c4476c
                if (error == ERR_peek_last_error() && /* oldest and latest errors match */
Packit c4476c
                    /* check that the error origin matches */
Packit c4476c
                    ERR_GET_LIB(error) == ERR_LIB_EVP &&
Packit c4476c
                    ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
Packit c4476c
                    ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
Packit c4476c
                    ERR_get_error(); /* pop error from queue */
Packit c4476c
                if (ERR_peek_error()) {
Packit c4476c
                    BIO_printf(bio_err,
Packit c4476c
                               "Unhandled error in the error queue during ECDH init.\n");
Packit c4476c
                    ERR_print_errors(bio_err);
Packit c4476c
                    rsa_count = 1;
Packit c4476c
                    break;
Packit c4476c
                }
Packit c4476c
Packit c4476c
                if (            /* Create the context for parameter generation */
Packit c4476c
                       !(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) ||
Packit c4476c
                       /* Initialise the parameter generation */
Packit c4476c
                       !EVP_PKEY_paramgen_init(pctx) ||
Packit c4476c
                       /* Set the curve by NID */
Packit c4476c
                       !EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
Packit c4476c
                                                               test_curves
Packit c4476c
                                                               [testnum].nid) ||
Packit c4476c
                       /* Create the parameter object params */
Packit c4476c
                       !EVP_PKEY_paramgen(pctx, &params)) {
Packit c4476c
                    ecdh_checks = 0;
Packit c4476c
                    BIO_printf(bio_err, "ECDH EC params init failure.\n");
Packit c4476c
                    ERR_print_errors(bio_err);
Packit c4476c
                    rsa_count = 1;
Packit c4476c
                    break;
Packit c4476c
                }
Packit c4476c
                /* Create the context for the key generation */
Packit c4476c
                kctx = EVP_PKEY_CTX_new(params, NULL);
Packit c4476c
Packit c4476c
                EVP_PKEY_free(params);
Packit c4476c
                params = NULL;
Packit c4476c
                EVP_PKEY_CTX_free(pctx);
Packit c4476c
                pctx = NULL;
Packit c4476c
            }
Packit c4476c
            if (kctx == NULL ||      /* keygen ctx is not null */
Packit c4476c
                EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
Packit c4476c
                ecdh_checks = 0;
Packit c4476c
                BIO_printf(bio_err, "ECDH keygen failure.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
Packit c4476c
                EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
Packit c4476c
                !(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
Packit c4476c
                EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
Packit c4476c
                EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
Packit c4476c
                EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
Packit c4476c
                outlen == 0 ||  /* ensure outlen is a valid size */
Packit c4476c
                outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
Packit c4476c
                ecdh_checks = 0;
Packit c4476c
                BIO_printf(bio_err, "ECDH key generation failure.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            /* Here we perform a test run, comparing the output of a*B and b*A;
Packit c4476c
             * we try this here and assume that further EVP_PKEY_derive calls
Packit c4476c
             * never fail, so we can skip checks in the actually benchmarked
Packit c4476c
             * code, for maximum performance. */
Packit c4476c
            if (!(test_ctx = EVP_PKEY_CTX_new(key_B, NULL)) || /* test ctx from skeyB */
Packit c4476c
                !EVP_PKEY_derive_init(test_ctx) || /* init derivation test_ctx */
Packit c4476c
                !EVP_PKEY_derive_set_peer(test_ctx, key_A) || /* set peer pubkey in test_ctx */
Packit c4476c
                !EVP_PKEY_derive(test_ctx, NULL, &test_outlen) || /* determine max length */
Packit c4476c
                !EVP_PKEY_derive(ctx, loopargs[i].secret_a, &outlen) || /* compute a*B */
Packit c4476c
                !EVP_PKEY_derive(test_ctx, loopargs[i].secret_b, &test_outlen) || /* compute b*A */
Packit c4476c
                test_outlen != outlen /* compare output length */ ) {
Packit c4476c
                ecdh_checks = 0;
Packit c4476c
                BIO_printf(bio_err, "ECDH computation failure.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            /* Compare the computation results: CRYPTO_memcmp() returns 0 if equal */
Packit c4476c
            if (CRYPTO_memcmp(loopargs[i].secret_a,
Packit c4476c
                              loopargs[i].secret_b, outlen)) {
Packit c4476c
                ecdh_checks = 0;
Packit c4476c
                BIO_printf(bio_err, "ECDH computations don't match.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            loopargs[i].ecdh_ctx[testnum] = ctx;
Packit c4476c
            loopargs[i].outlen[testnum] = outlen;
Packit c4476c
Packit c4476c
            EVP_PKEY_free(key_A);
Packit c4476c
            EVP_PKEY_free(key_B);
Packit c4476c
            EVP_PKEY_CTX_free(kctx);
Packit c4476c
            kctx = NULL;
Packit c4476c
            EVP_PKEY_CTX_free(test_ctx);
Packit c4476c
            test_ctx = NULL;
Packit c4476c
        }
Packit c4476c
        if (ecdh_checks != 0) {
Packit c4476c
            pkey_print_message("", "ecdh",
Packit c4476c
                               ecdh_c[testnum][0],
Packit c4476c
                               test_curves[testnum].bits, seconds.ecdh);
Packit c4476c
            Time_F(START);
Packit c4476c
            count =
Packit c4476c
                run_benchmark(async_jobs, ECDH_EVP_derive_key_loop, loopargs);
Packit c4476c
            d = Time_F(STOP);
Packit c4476c
            BIO_printf(bio_err,
Packit c4476c
                       mr ? "+R7:%ld:%d:%.2f\n" :
Packit c4476c
                       "%ld %u-bits ECDH ops in %.2fs\n", count,
Packit c4476c
                       test_curves[testnum].bits, d);
Packit c4476c
            ecdh_results[testnum][0] = (double)count / d;
Packit c4476c
            rsa_count = count;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (rsa_count <= 1) {
Packit c4476c
            /* if longer than 10s, don't do any more */
Packit c4476c
            for (testnum++; testnum < OSSL_NELEM(ecdh_doit); testnum++)
Packit c4476c
                ecdh_doit[testnum] = 0;
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
    for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
Packit c4476c
        int st = 1;
Packit c4476c
        EVP_PKEY *ed_pkey = NULL;
Packit c4476c
        EVP_PKEY_CTX *ed_pctx = NULL;
Packit c4476c
Packit c4476c
        if (!eddsa_doit[testnum])
Packit c4476c
            continue;           /* Ignore Curve */
Packit c4476c
        for (i = 0; i < loopargs_len; i++) {
Packit c4476c
            loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
Packit c4476c
            if (loopargs[i].eddsa_ctx[testnum] == NULL) {
Packit c4476c
                st = 0;
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
Packit c4476c
                    == NULL
Packit c4476c
                || EVP_PKEY_keygen_init(ed_pctx) <= 0
Packit c4476c
                || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
Packit c4476c
                st = 0;
Packit c4476c
                EVP_PKEY_CTX_free(ed_pctx);
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
            EVP_PKEY_CTX_free(ed_pctx);
Packit c4476c
Packit c4476c
            if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
Packit c4476c
                                    NULL, ed_pkey)) {
Packit c4476c
                st = 0;
Packit c4476c
                EVP_PKEY_free(ed_pkey);
Packit c4476c
                break;
Packit c4476c
            }
Packit c4476c
            EVP_PKEY_free(ed_pkey);
Packit c4476c
        }
Packit c4476c
        if (st == 0) {
Packit c4476c
            BIO_printf(bio_err, "EdDSA failure.\n");
Packit c4476c
            ERR_print_errors(bio_err);
Packit c4476c
            rsa_count = 1;
Packit c4476c
        } else {
Packit c4476c
            for (i = 0; i < loopargs_len; i++) {
Packit c4476c
                /* Perform EdDSA signature test */
Packit c4476c
                loopargs[i].sigsize = test_ed_curves[testnum].sigsize;
Packit c4476c
                st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
Packit c4476c
                                    loopargs[i].buf2, &loopargs[i].sigsize,
Packit c4476c
                                    loopargs[i].buf, 20);
Packit c4476c
                if (st == 0)
Packit c4476c
                    break;
Packit c4476c
            }
Packit c4476c
            if (st == 0) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "EdDSA sign failure.  No EdDSA sign will be done.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                rsa_count = 1;
Packit c4476c
            } else {
Packit c4476c
                pkey_print_message("sign", test_ed_curves[testnum].name,
Packit c4476c
                                   eddsa_c[testnum][0],
Packit c4476c
                                   test_ed_curves[testnum].bits, seconds.eddsa);
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           mr ? "+R8:%ld:%u:%s:%.2f\n" :
Packit c4476c
                           "%ld %u bits %s signs in %.2fs \n",
Packit c4476c
                           count, test_ed_curves[testnum].bits,
Packit c4476c
                           test_ed_curves[testnum].name, d);
Packit c4476c
                eddsa_results[testnum][0] = (double)count / d;
Packit c4476c
                rsa_count = count;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            /* Perform EdDSA verification test */
Packit c4476c
            for (i = 0; i < loopargs_len; i++) {
Packit c4476c
                st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
Packit c4476c
                                      loopargs[i].buf2, loopargs[i].sigsize,
Packit c4476c
                                      loopargs[i].buf, 20);
Packit c4476c
                if (st != 1)
Packit c4476c
                    break;
Packit c4476c
            }
Packit c4476c
            if (st != 1) {
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           "EdDSA verify failure.  No EdDSA verify will be done.\n");
Packit c4476c
                ERR_print_errors(bio_err);
Packit c4476c
                eddsa_doit[testnum] = 0;
Packit c4476c
            } else {
Packit c4476c
                pkey_print_message("verify", test_ed_curves[testnum].name,
Packit c4476c
                                   eddsa_c[testnum][1],
Packit c4476c
                                   test_ed_curves[testnum].bits, seconds.eddsa);
Packit c4476c
                Time_F(START);
Packit c4476c
                count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
Packit c4476c
                d = Time_F(STOP);
Packit c4476c
                BIO_printf(bio_err,
Packit c4476c
                           mr ? "+R9:%ld:%u:%s:%.2f\n"
Packit c4476c
                           : "%ld %u bits %s verify in %.2fs\n",
Packit c4476c
                           count, test_ed_curves[testnum].bits,
Packit c4476c
                           test_ed_curves[testnum].name, d);
Packit c4476c
                eddsa_results[testnum][1] = (double)count / d;
Packit c4476c
            }
Packit c4476c
Packit c4476c
            if (rsa_count <= 1) {
Packit c4476c
                /* if longer than 10s, don't do any more */
Packit c4476c
                for (testnum++; testnum < EdDSA_NUM; testnum++)
Packit c4476c
                    eddsa_doit[testnum] = 0;
Packit c4476c
            }
Packit c4476c
        }
Packit c4476c
    }
Packit c4476c
Packit c4476c
#endif                          /* OPENSSL_NO_EC */
Packit c4476c
#ifndef NO_FORK
Packit c4476c
 show_res:
Packit c4476c
#endif
Packit c4476c
    if (!mr) {
Packit c4476c
        printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
Packit c4476c
        printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
Packit c4476c
        printf("options:");
Packit c4476c
        printf("%s ", BN_options());
Packit c4476c
#ifndef OPENSSL_NO_MD2
Packit c4476c
        printf("%s ", MD2_options());
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_RC4
Packit c4476c
        printf("%s ", RC4_options());
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DES
Packit c4476c
        printf("%s ", DES_options());
Packit c4476c
#endif
Packit c4476c
        printf("%s ", AES_options());
Packit c4476c
#ifndef OPENSSL_NO_IDEA
Packit c4476c
        printf("%s ", IDEA_options());
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_BF
Packit c4476c
        printf("%s ", BF_options());
Packit c4476c
#endif
Packit c4476c
        printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
Packit c4476c
    }
Packit c4476c
Packit c4476c
    if (pr_header) {
Packit c4476c
        if (mr)
Packit c4476c
            printf("+H");
Packit c4476c
        else {
Packit c4476c
            printf
Packit c4476c
                ("The 'numbers' are in 1000s of bytes per second processed.\n");
Packit c4476c
            printf("type        ");
Packit c4476c
        }
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++)
Packit c4476c
            printf(mr ? ":%d" : "%7d bytes", lengths[testnum]);
Packit c4476c
        printf("\n");
Packit c4476c
    }
Packit c4476c
Packit c4476c
    for (k = 0; k < ALGOR_NUM; k++) {
Packit c4476c
        if (!doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F:%u:%s", k, names[k]);
Packit c4476c
        else
Packit c4476c
            printf("%-13s", names[k]);
Packit c4476c
        for (testnum = 0; testnum < size_num; testnum++) {
Packit c4476c
            if (results[k][testnum] > 10000 && !mr)
Packit c4476c
                printf(" %11.2fk", results[k][testnum] / 1e3);
Packit c4476c
            else
Packit c4476c
                printf(mr ? ":%.2f" : " %11.2f ", results[k][testnum]);
Packit c4476c
        }
Packit c4476c
        printf("\n");
Packit c4476c
    }
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
    testnum = 1;
Packit c4476c
    for (k = 0; k < RSA_NUM; k++) {
Packit c4476c
        if (!rsa_doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (testnum && !mr) {
Packit c4476c
            printf("%18ssign    verify    sign/s verify/s\n", " ");
Packit c4476c
            testnum = 0;
Packit c4476c
        }
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F2:%u:%u:%f:%f\n",
Packit c4476c
                   k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
Packit c4476c
        else
Packit c4476c
            printf("rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
Packit c4476c
                   rsa_bits[k], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1],
Packit c4476c
                   rsa_results[k][0], rsa_results[k][1]);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_DSA
Packit c4476c
    testnum = 1;
Packit c4476c
    for (k = 0; k < DSA_NUM; k++) {
Packit c4476c
        if (!dsa_doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (testnum && !mr) {
Packit c4476c
            printf("%18ssign    verify    sign/s verify/s\n", " ");
Packit c4476c
            testnum = 0;
Packit c4476c
        }
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F3:%u:%u:%f:%f\n",
Packit c4476c
                   k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
Packit c4476c
        else
Packit c4476c
            printf("dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
Packit c4476c
                   dsa_bits[k], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1],
Packit c4476c
                   dsa_results[k][0], dsa_results[k][1]);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
#ifndef OPENSSL_NO_EC
Packit c4476c
    testnum = 1;
Packit c4476c
    for (k = 0; k < OSSL_NELEM(ecdsa_doit); k++) {
Packit c4476c
        if (!ecdsa_doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (testnum && !mr) {
Packit c4476c
            printf("%30ssign    verify    sign/s verify/s\n", " ");
Packit c4476c
            testnum = 0;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F4:%u:%u:%f:%f\n",
Packit c4476c
                   k, test_curves[k].bits,
Packit c4476c
                   ecdsa_results[k][0], ecdsa_results[k][1]);
Packit c4476c
        else
Packit c4476c
            printf("%4u bits ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
Packit c4476c
                   test_curves[k].bits, test_curves[k].name,
Packit c4476c
                   1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1],
Packit c4476c
                   ecdsa_results[k][0], ecdsa_results[k][1]);
Packit c4476c
    }
Packit c4476c
Packit c4476c
    testnum = 1;
Packit c4476c
    for (k = 0; k < EC_NUM; k++) {
Packit c4476c
        if (!ecdh_doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (testnum && !mr) {
Packit c4476c
            printf("%30sop      op/s\n", " ");
Packit c4476c
            testnum = 0;
Packit c4476c
        }
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F5:%u:%u:%f:%f\n",
Packit c4476c
                   k, test_curves[k].bits,
Packit c4476c
                   ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
Packit c4476c
Packit c4476c
        else
Packit c4476c
            printf("%4u bits ecdh (%s) %8.4fs %8.1f\n",
Packit c4476c
                   test_curves[k].bits, test_curves[k].name,
Packit c4476c
                   1.0 / ecdh_results[k][0], ecdh_results[k][0]);
Packit c4476c
    }
Packit c4476c
Packit c4476c
    testnum = 1;
Packit c4476c
    for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
Packit c4476c
        if (!eddsa_doit[k])
Packit c4476c
            continue;
Packit c4476c
        if (testnum && !mr) {
Packit c4476c
            printf("%30ssign    verify    sign/s verify/s\n", " ");
Packit c4476c
            testnum = 0;
Packit c4476c
        }
Packit c4476c
Packit c4476c
        if (mr)
Packit c4476c
            printf("+F6:%u:%u:%s:%f:%f\n",
Packit c4476c
                   k, test_ed_curves[k].bits, test_ed_curves[k].name,
Packit c4476c
                   eddsa_results[k][0], eddsa_results[k][1]);
Packit c4476c
        else
Packit c4476c
            printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
Packit c4476c
                   test_ed_curves[k].bits, test_ed_curves[k].name,
Packit c4476c
                   1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
Packit c4476c
                   eddsa_results[k][0], eddsa_results[k][1]);
Packit c4476c
    }
Packit c4476c
#endif
Packit c4476c
Packit c4476c
    ret = 0;
Packit c4476c
Packit c4476c
 end:
Packit c4476c
    ERR_print_errors(bio_err);
Packit c4476c
    for (i = 0; i < loopargs_len; i++) {
Packit c4476c
        OPENSSL_free(loopargs[i].buf_malloc);
Packit c4476c
        OPENSSL_free(loopargs[i].buf2_malloc);
Packit c4476c
Packit c4476c
#ifndef OPENSSL_NO_RSA
Packit c4476c
        for (k = 0; k < RSA_NUM; k++)
Packit c4476c
            RSA_