* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#define DSA_SECONDS 10
#define ECDSA_SECONDS 10
#define ECDH_SECONDS 10
+#define EdDSA_SECONDS 10
+#define SM2_SECONDS 10
#include <stdio.h>
#include <stdlib.h>
#include <openssl/objects.h>
#include <openssl/async.h>
#if !defined(OPENSSL_SYS_MSDOS)
-# include OPENSSL_UNISTD
+# include <unistd.h>
#endif
#if defined(_WIN32)
# include <openssl/md5.h>
#endif
#include <openssl/hmac.h>
+#ifndef OPENSSL_NO_CMAC
+#include <openssl/cmac.h>
+#endif
#include <openssl/sha.h>
#ifndef OPENSSL_NO_RMD160
# include <openssl/ripemd.h>
#include <openssl/modes.h>
#ifndef HAVE_FORK
-# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)
+# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS)
# define HAVE_FORK 0
# else
# define HAVE_FORK 1
int dsa;
int ecdsa;
int ecdh;
+ int eddsa;
+ int sm2;
} openssl_speed_sec_t;
static volatile int run = 0;
#endif
static int AES_cbc_128_encrypt_loop(void *args);
static int AES_cbc_192_encrypt_loop(void *args);
-static int AES_ige_128_encrypt_loop(void *args);
static int AES_cbc_256_encrypt_loop(void *args);
+#ifndef OPENSSL_NO_DEPRECATED_3_0
+static int AES_ige_128_encrypt_loop(void *args);
static int AES_ige_192_encrypt_loop(void *args);
static int AES_ige_256_encrypt_loop(void *args);
+#endif
static int CRYPTO_gcm128_aad_loop(void *args);
static int RAND_bytes_loop(void *args);
static int EVP_Update_loop(void *args);
#ifndef OPENSSL_NO_EC
static int ECDSA_sign_loop(void *args);
static int ECDSA_verify_loop(void *args);
+static int EdDSA_sign_loop(void *args);
+static int EdDSA_verify_loop(void *args);
+# ifndef OPENSSL_NO_SM2
+static int SM2_sign_loop(void *args);
+static int SM2_verify_loop(void *args);
+# endif
#endif
static double Time_F(int s);
typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
- OPT_ELAPSED, OPT_EVP, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
+ OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM,
- OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD
+ OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC
} OPTION_CHOICE;
const OPTIONS speed_options[] = {
{OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"},
- {OPT_HELP_STR, 1, '-', "Valid options are:\n"},
+
+ OPT_SECTION("General"),
{"help", OPT_HELP, '-', "Display this summary"},
- {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
- {"decrypt", OPT_DECRYPT, '-',
- "Time decryption instead of encryption (only EVP)"},
- {"aead", OPT_AEAD, '-',
- "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
{"mb", OPT_MB, '-',
"Enable (tls1>=1) multi-block mode on EVP-named cipher"},
{"mr", OPT_MR, '-', "Produce machine readable output"},
{"async_jobs", OPT_ASYNCJOBS, 'p',
"Enable async mode and start specified number of jobs"},
#endif
- OPT_R_OPTIONS,
#ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
#endif
+ {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
+
+ OPT_SECTION("Selection"),
+ {"evp", OPT_EVP, 's', "Use EVP-named cipher or digest"},
+ {"hmac", OPT_HMAC, 's', "HMAC using EVP-named digest"},
+#ifndef OPENSSL_NO_CMAC
+ {"cmac", OPT_CMAC, 's', "CMAC using EVP-named cipher"},
+#endif
+ {"decrypt", OPT_DECRYPT, '-',
+ "Time decryption instead of encryption (only EVP)"},
+ {"aead", OPT_AEAD, '-',
+ "Benchmark EVP-named AEAD cipher in TLS-like sequence"},
+
+ OPT_SECTION("Timing"),
{"elapsed", OPT_ELAPSED, '-',
"Use wall-clock time instead of CPU user time as divisor"},
- {"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
{"seconds", OPT_SECONDS, 'p',
"Run benchmarks for specified amount of seconds"},
{"bytes", OPT_BYTES, 'p',
"Run [non-PKI] benchmarks on custom-sized buffer"},
{"misalign", OPT_MISALIGN, 'p',
"Use specified offset to mis-align buffers"},
+
+ OPT_R_OPTIONS,
{NULL}
};
#define D_IGE_256_AES 28
#define D_GHASH 29
#define D_RAND 30
+#define D_EVP_HMAC 31
+#define D_EVP_CMAC 32
+
/* name of algorithms to test */
static const char *names[] = {
"md2", "mdc2", "md4", "md5", "hmac(md5)", "sha1", "rmd160", "rc4",
"camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
"evp", "sha256", "sha512", "whirlpool",
"aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
- "rand"
+ "rand", "hmac", "cmac"
};
#define ALGOR_NUM OSSL_NELEM(names)
{"aes-128-cbc", D_CBC_128_AES},
{"aes-192-cbc", D_CBC_192_AES},
{"aes-256-cbc", D_CBC_256_AES},
+#ifndef OPENSSL_NO_DEPRECATED_3_0
{"aes-128-ige", D_IGE_128_AES},
{"aes-192-ige", D_IGE_192_AES},
{"aes-256-ige", D_IGE_256_AES},
+#endif
#ifndef OPENSSL_NO_RC2
{"rc2-cbc", D_CBC_RC2},
{"rc2", D_CBC_RC2},
static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */
#endif /* OPENSSL_NO_RSA */
-#define R_EC_P160 0
-#define R_EC_P192 1
-#define R_EC_P224 2
-#define R_EC_P256 3
-#define R_EC_P384 4
-#define R_EC_P521 5
-#define R_EC_K163 6
-#define R_EC_K233 7
-#define R_EC_K283 8
-#define R_EC_K409 9
-#define R_EC_K571 10
-#define R_EC_B163 11
-#define R_EC_B233 12
-#define R_EC_B283 13
-#define R_EC_B409 14
-#define R_EC_B571 15
-#define R_EC_BRP256R1 16
-#define R_EC_BRP256T1 17
-#define R_EC_BRP384R1 18
-#define R_EC_BRP384T1 19
-#define R_EC_BRP512R1 20
-#define R_EC_BRP512T1 21
-#define R_EC_X25519 22
-#define R_EC_X448 23
+enum {
+ R_EC_P160,
+ R_EC_P192,
+ R_EC_P224,
+ R_EC_P256,
+ R_EC_P384,
+ R_EC_P521,
+#ifndef OPENSSL_NO_EC2M
+ R_EC_K163,
+ R_EC_K233,
+ R_EC_K283,
+ R_EC_K409,
+ R_EC_K571,
+ R_EC_B163,
+ R_EC_B233,
+ R_EC_B283,
+ R_EC_B409,
+ R_EC_B571,
+#endif
+ R_EC_BRP256R1,
+ R_EC_BRP256T1,
+ R_EC_BRP384R1,
+ R_EC_BRP384T1,
+ R_EC_BRP512R1,
+ R_EC_BRP512T1,
+ R_EC_X25519,
+ R_EC_X448
+};
+
#ifndef OPENSSL_NO_EC
static OPT_PAIR ecdsa_choices[] = {
{"ecdsap160", R_EC_P160},
{"ecdsap256", R_EC_P256},
{"ecdsap384", R_EC_P384},
{"ecdsap521", R_EC_P521},
+# ifndef OPENSSL_NO_EC2M
{"ecdsak163", R_EC_K163},
{"ecdsak233", R_EC_K233},
{"ecdsak283", R_EC_K283},
{"ecdsab283", R_EC_B283},
{"ecdsab409", R_EC_B409},
{"ecdsab571", R_EC_B571},
+# endif
{"ecdsabrp256r1", R_EC_BRP256R1},
{"ecdsabrp256t1", R_EC_BRP256T1},
{"ecdsabrp384r1", R_EC_BRP384R1},
{"ecdhp256", R_EC_P256},
{"ecdhp384", R_EC_P384},
{"ecdhp521", R_EC_P521},
+# ifndef OPENSSL_NO_EC2M
{"ecdhk163", R_EC_K163},
{"ecdhk233", R_EC_K233},
{"ecdhk283", R_EC_K283},
{"ecdhb283", R_EC_B283},
{"ecdhb409", R_EC_B409},
{"ecdhb571", R_EC_B571},
+# endif
{"ecdhbrp256r1", R_EC_BRP256R1},
{"ecdhbrp256t1", R_EC_BRP256T1},
{"ecdhbrp384r1", R_EC_BRP384R1},
# define EC_NUM OSSL_NELEM(ecdh_choices)
static double ecdh_results[EC_NUM][1]; /* 1 op: derivation */
+
+#define R_EC_Ed25519 0
+#define R_EC_Ed448 1
+static OPT_PAIR eddsa_choices[] = {
+ {"ed25519", R_EC_Ed25519},
+ {"ed448", R_EC_Ed448}
+};
+# define EdDSA_NUM OSSL_NELEM(eddsa_choices)
+
+static double eddsa_results[EdDSA_NUM][2]; /* 2 ops: sign then verify */
+
+# ifndef OPENSSL_NO_SM2
+# define R_EC_CURVESM2 0
+static OPT_PAIR sm2_choices[] = {
+ {"curveSM2", R_EC_CURVESM2}
+};
+# define SM2_ID "TLSv1.3+GM+Cipher+Suite"
+# define SM2_ID_LEN sizeof("TLSv1.3+GM+Cipher+Suite") - 1
+# define SM2_NUM OSSL_NELEM(sm2_choices)
+
+static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
+# endif /* OPENSSL_NO_SM2 */
#endif /* OPENSSL_NO_EC */
#ifndef SIGALRM
unsigned char *buf2_malloc;
unsigned char *key;
unsigned int siglen;
+ size_t sigsize;
#ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
#endif
#ifndef OPENSSL_NO_EC
EC_KEY *ecdsa[ECDSA_NUM];
EVP_PKEY_CTX *ecdh_ctx[EC_NUM];
+ EVP_MD_CTX *eddsa_ctx[EdDSA_NUM];
+# ifndef OPENSSL_NO_SM2
+ EVP_MD_CTX *sm2_ctx[SM2_NUM];
+ EVP_MD_CTX *sm2_vfy_ctx[SM2_NUM];
+ EVP_PKEY *sm2_pkey[SM2_NUM];
+# endif
unsigned char *secret_a;
unsigned char *secret_b;
size_t outlen[EC_NUM];
#endif
EVP_CIPHER_CTX *ctx;
HMAC_CTX *hctx;
+#ifndef OPENSSL_NO_CMAC
+ CMAC_CTX *cmac_ctx;
+#endif
GCM128_CONTEXT *gcm_ctx;
} loopargs_t;
static int run_benchmark(int async_jobs, int (*loop_function) (void *),
return count;
}
+#ifndef OPENSSL_NO_DEPRECATED_3_0
static int AES_ige_128_encrypt_loop(void *args)
{
loopargs_t *tempargs = *(loopargs_t **) args;
(size_t)lengths[testnum], &aes_ks3, iv, AES_ENCRYPT);
return count;
}
+#endif
static int CRYPTO_gcm128_aad_loop(void *args)
{
if (decrypt) {
for (count = 0; COND(nb_iter); count++) {
rc = EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
- if (rc != 1)
+ if (rc != 1) {
+ /* reset iv in case of counter overflow */
EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
+ }
}
} else {
for (count = 0; COND(nb_iter); count++) {
rc = EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
- if (rc != 1)
+ if (rc != 1) {
+ /* reset iv in case of counter overflow */
EVP_CipherInit_ex(ctx, NULL, NULL, NULL, iv, -1);
+ }
}
}
if (decrypt)
#endif
if (decrypt) {
for (count = 0; COND(nb_iter); count++) {
- EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, sizeof(tag), tag);
- EVP_DecryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
+ /* reset iv */
+ EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv);
+ /* counter is reset on every update */
EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
- EVP_DecryptFinal_ex(ctx, buf, &outl);
}
} else {
for (count = 0; COND(nb_iter); count++) {
- EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv);
+ /* restore iv length field */
EVP_EncryptUpdate(ctx, NULL, &outl, NULL, lengths[testnum]);
+ /* counter is reset on every update */
EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]);
- EVP_EncryptFinal_ex(ctx, buf, &outl);
}
}
+ if (decrypt)
+ EVP_DecryptFinal_ex(ctx, buf, &outl);
+ else
+ EVP_EncryptFinal_ex(ctx, buf, &outl);
return count;
}
return count;
}
+static const EVP_MD *evp_hmac_md = NULL;
+static char *evp_hmac_name = NULL;
+static int EVP_HMAC_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ unsigned char no_key[32];
+ int count;
+#ifndef SIGALRM
+ int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
+#endif
+
+ for (count = 0; COND(nb_iter); count++) {
+ if (HMAC(evp_hmac_md, no_key, sizeof(no_key), buf, lengths[testnum],
+ NULL, NULL) == NULL)
+ return -1;
+ }
+ return count;
+}
+
+#ifndef OPENSSL_NO_CMAC
+static const EVP_CIPHER *evp_cmac_cipher = NULL;
+static char *evp_cmac_name = NULL;
+
+static int EVP_CMAC_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ CMAC_CTX *cmac_ctx = tempargs->cmac_ctx;
+ static const char key[16] = "This is a key...";
+ unsigned char mac[16];
+ size_t len = sizeof(mac);
+ int count;
+#ifndef SIGALRM
+ int nb_iter = save_count * 4 * lengths[0] / lengths[testnum];
+#endif
+
+ for (count = 0; COND(nb_iter); count++) {
+ if (!CMAC_Init(cmac_ctx, key, sizeof(key), evp_cmac_cipher, NULL)
+ || !CMAC_Update(cmac_ctx, buf, lengths[testnum])
+ || !CMAC_Final(cmac_ctx, mac, &len))
+ return -1;
+ }
+ return count;
+}
+#endif
+
#ifndef OPENSSL_NO_RSA
static long rsa_c[RSA_NUM][2]; /* # RSA iteration test */
return count;
}
+static long eddsa_c[EdDSA_NUM][2];
+static int EdDSA_sign_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
+ unsigned char *eddsasig = tempargs->buf2;
+ size_t *eddsasigsize = &tempargs->sigsize;
+ int ret, count;
+
+ for (count = 0; COND(eddsa_c[testnum][0]); count++) {
+ ret = EVP_DigestSign(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
+ if (ret == 0) {
+ BIO_printf(bio_err, "EdDSA sign failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ }
+ return count;
+}
+
+static int EdDSA_verify_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ EVP_MD_CTX **edctx = tempargs->eddsa_ctx;
+ unsigned char *eddsasig = tempargs->buf2;
+ size_t eddsasigsize = tempargs->sigsize;
+ int ret, count;
+
+ for (count = 0; COND(eddsa_c[testnum][1]); count++) {
+ ret = EVP_DigestVerify(edctx[testnum], eddsasig, eddsasigsize, buf, 20);
+ if (ret != 1) {
+ BIO_printf(bio_err, "EdDSA verify failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ }
+ return count;
+}
+
+# ifndef OPENSSL_NO_SM2
+static long sm2_c[SM2_NUM][2];
+static int SM2_sign_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ EVP_MD_CTX **sm2ctx = tempargs->sm2_ctx;
+ unsigned char *sm2sig = tempargs->buf2;
+ size_t sm2sigsize = tempargs->sigsize;
+ const size_t max_size = tempargs->sigsize;
+ int ret, count;
+ EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
+
+ for (count = 0; COND(sm2_c[testnum][0]); count++) {
+ if (!EVP_DigestSignInit(sm2ctx[testnum], NULL, EVP_sm3(),
+ NULL, sm2_pkey[testnum])) {
+ BIO_printf(bio_err, "SM2 init sign failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ ret = EVP_DigestSign(sm2ctx[testnum], sm2sig, &sm2sigsize,
+ buf, 20);
+ if (ret == 0) {
+ BIO_printf(bio_err, "SM2 sign failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ /* update the latest returned size and always use the fixed buffer size */
+ tempargs->sigsize = sm2sigsize;
+ sm2sigsize = max_size;
+ }
+
+ return count;
+}
+
+static int SM2_verify_loop(void *args)
+{
+ loopargs_t *tempargs = *(loopargs_t **) args;
+ unsigned char *buf = tempargs->buf;
+ EVP_MD_CTX **sm2ctx = tempargs->sm2_vfy_ctx;
+ unsigned char *sm2sig = tempargs->buf2;
+ size_t sm2sigsize = tempargs->sigsize;
+ int ret, count;
+ EVP_PKEY **sm2_pkey = tempargs->sm2_pkey;
+
+ for (count = 0; COND(sm2_c[testnum][1]); count++) {
+ if (!EVP_DigestVerifyInit(sm2ctx[testnum], NULL, EVP_sm3(),
+ NULL, sm2_pkey[testnum])) {
+ BIO_printf(bio_err, "SM2 verify init failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ ret = EVP_DigestVerify(sm2ctx[testnum], sm2sig, sm2sigsize,
+ buf, 20);
+ if (ret != 1) {
+ BIO_printf(bio_err, "SM2 verify failure\n");
+ ERR_print_errors(bio_err);
+ count = -1;
+ break;
+ }
+ }
+ return count;
+}
+# endif /* OPENSSL_NO_SM2 */
#endif /* OPENSSL_NO_EC */
static int run_benchmark(int async_jobs,
long rsa_count = 1;
#endif
openssl_speed_sec_t seconds = { SECONDS, RSA_SECONDS, DSA_SECONDS,
- ECDSA_SECONDS, ECDH_SECONDS };
+ ECDSA_SECONDS, ECDH_SECONDS,
+ EdDSA_SECONDS, SM2_SECONDS };
/* What follows are the buffers and key material. */
#ifndef OPENSSL_NO_RC5
{"nistp192", NID_X9_62_prime192v1, 192},
{"nistp224", NID_secp224r1, 224},
{"nistp256", NID_X9_62_prime256v1, 256},
- {"nistp384", NID_secp384r1, 384},
+ {"nistp384", NID_secp384r1, 384},
{"nistp521", NID_secp521r1, 521},
+# ifndef OPENSSL_NO_EC2M
/* Binary Curves */
{"nistk163", NID_sect163k1, 163},
- {"nistk233", NID_sect233k1, 233},
+ {"nistk233", NID_sect233k1, 233},
{"nistk283", NID_sect283k1, 283},
{"nistk409", NID_sect409k1, 409},
{"nistk571", NID_sect571k1, 571},
{"nistb283", NID_sect283r1, 283},
{"nistb409", NID_sect409r1, 409},
{"nistb571", NID_sect571r1, 571},
+# endif
{"brainpoolP256r1", NID_brainpoolP256r1, 256},
{"brainpoolP256t1", NID_brainpoolP256t1, 256},
{"brainpoolP384r1", NID_brainpoolP384r1, 384},
{"X25519", NID_X25519, 253},
{"X448", NID_X448, 448}
};
+ static const struct {
+ const char *name;
+ unsigned int nid;
+ unsigned int bits;
+ size_t sigsize;
+ } test_ed_curves[] = {
+ /* EdDSA */
+ {"Ed25519", NID_ED25519, 253, 64},
+ {"Ed448", NID_ED448, 456, 114}
+ };
+# ifndef OPENSSL_NO_SM2
+ static const struct {
+ const char *name;
+ unsigned int nid;
+ unsigned int bits;
+ } test_sm2_curves[] = {
+ /* SM2 */
+ {"CurveSM2", NID_sm2, 256}
+ };
+# endif
int ecdsa_doit[ECDSA_NUM] = { 0 };
int ecdh_doit[EC_NUM] = { 0 };
+ int eddsa_doit[EdDSA_NUM] = { 0 };
+# ifndef OPENSSL_NO_SM2
+ int sm2_doit[SM2_NUM] = { 0 };
+# endif
OPENSSL_assert(OSSL_NELEM(test_curves) >= EC_NUM);
+ OPENSSL_assert(OSSL_NELEM(test_ed_curves) >= EdDSA_NUM);
+# ifndef OPENSSL_NO_SM2
+ OPENSSL_assert(OSSL_NELEM(test_sm2_curves) >= SM2_NUM);
+# endif
#endif /* ndef OPENSSL_NO_EC */
prog = opt_init(argc, argv, speed_options);
}
doit[D_EVP] = 1;
break;
+ case OPT_HMAC:
+ evp_hmac_md = EVP_get_digestbyname(opt_arg());
+ if (evp_hmac_md == NULL) {
+ BIO_printf(bio_err, "%s: %s is an unknown digest\n",
+ prog, opt_arg());
+ goto end;
+ }
+ doit[D_EVP_HMAC] = 1;
+ break;
+ case OPT_CMAC:
+#ifndef OPENSSL_NO_CMAC
+ evp_cmac_cipher = EVP_get_cipherbyname(opt_arg());
+ if (evp_cmac_cipher == NULL) {
+ BIO_printf(bio_err, "%s: %s is an unknown cipher\n",
+ prog, opt_arg());
+ goto end;
+ }
+ doit[D_EVP_CMAC] = 1;
+#endif
+ break;
case OPT_DECRYPT:
decrypt = 1;
break;
break;
case OPT_SECONDS:
seconds.sym = seconds.rsa = seconds.dsa = seconds.ecdsa
- = seconds.ecdh = atoi(opt_arg());
+ = seconds.ecdh = seconds.eddsa
+ = seconds.sm2 = atoi(opt_arg());
break;
case OPT_BYTES:
lengths_single = atoi(opt_arg());
ecdh_doit[i] = 2;
continue;
}
+ if (strcmp(*argv, "eddsa") == 0) {
+ for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
+ eddsa_doit[loop] = 1;
+ continue;
+ }
+ if (found(*argv, eddsa_choices, &i)) {
+ eddsa_doit[i] = 2;
+ continue;
+ }
+# ifndef OPENSSL_NO_SM2
+ if (strcmp(*argv, "sm2") == 0) {
+ for (loop = 0; loop < OSSL_NELEM(sm2_doit); loop++)
+ sm2_doit[loop] = 1;
+ continue;
+ }
+ if (found(*argv, sm2_choices, &i)) {
+ sm2_doit[i] = 2;
+ continue;
+ }
+# endif
#endif
BIO_printf(bio_err, "%s: Unknown algorithm %s\n", prog, *argv);
goto end;
}
}
- buflen = lengths[size_num - 1] + MAX_MISALIGNMENT + 1;
+ buflen = lengths[size_num - 1];
+ if (buflen < 36) /* size of random vector in RSA benchmark */
+ buflen = 36;
+ buflen += MAX_MISALIGNMENT + 1;
loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
memset(loopargs[i].buf_malloc, 0, buflen);
e = setup_engine(engine_id, 0);
/* No parameters; turn on everything. */
- if ((argc == 0) && !doit[D_EVP]) {
+ if (argc == 0 && !doit[D_EVP] && !doit[D_EVP_HMAC] && !doit[D_EVP_CMAC]) {
for (i = 0; i < ALGOR_NUM; i++)
- if (i != D_EVP)
+ if (i != D_EVP && i != D_EVP_HMAC && i != D_EVP_CMAC)
doit[i] = 1;
#ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++)
ecdsa_doit[loop] = 1;
for (loop = 0; loop < OSSL_NELEM(ecdh_doit); loop++)
ecdh_doit[loop] = 1;
+ for (loop = 0; loop < OSSL_NELEM(eddsa_doit); loop++)
+ eddsa_doit[loop] = 1;
+# ifndef OPENSSL_NO_SM2
+ for (loop = 0; loop < OSSL_NELEM(sm2_doit); loop++)
+ sm2_doit[loop] = 1;
+# endif
#endif
}
for (i = 0; i < ALGOR_NUM; i++)
RC2_set_key(&rc2_ks, 16, key16, 128);
#endif
#ifndef OPENSSL_NO_RC5
- RC5_32_set_key(&rc5_ks, 16, key16, 12);
+ if (!RC5_32_set_key(&rc5_ks, 16, key16, 12)) {
+ BIO_printf(bio_err, "Failed setting RC5 key\n");
+ goto end;
+ }
#endif
#ifndef OPENSSL_NO_BF
BF_set_key(&bf_ks, 16, key16);
}
}
}
+# ifndef OPENSSL_NO_EC2M
ecdsa_c[R_EC_K163][0] = count / 1000;
ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
}
}
}
+# endif
ecdh_c[R_EC_P160][0] = count / 1000;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
}
}
}
+# ifndef OPENSSL_NO_EC2M
ecdh_c[R_EC_K163][0] = count / 1000;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
}
}
}
+# endif
/* repeated code good to factorize */
ecdh_c[R_EC_BRP256R1][0] = count / 1000;
for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) {
/* default iteration count for the last two EC Curves */
ecdh_c[R_EC_X25519][0] = count / 1800;
ecdh_c[R_EC_X448][0] = count / 7200;
+
+ eddsa_c[R_EC_Ed25519][0] = count / 1800;
+ eddsa_c[R_EC_Ed448][0] = count / 7200;
+
+# ifndef OPENSSL_NO_SM2
+ sm2_c[R_EC_SM2P256][0] = count / 1800;
+# endif
# endif
# else
}
}
+#ifndef OPENSSL_NO_DEPRECATED_3_0
if (doit[D_IGE_128_AES]) {
for (testnum = 0; testnum < size_num; testnum++) {
print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][testnum],
print_result(D_IGE_256_AES, testnum, count, d);
}
}
+#endif
if (doit[D_GHASH]) {
for (i = 0; i < loopargs_len; i++) {
loopargs[i].gcm_ctx =
for (k = 0; k < loopargs_len; k++) {
loopargs[k].ctx = EVP_CIPHER_CTX_new();
- EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
- iv, decrypt ? 0 : 1);
+ if (loopargs[k].ctx == NULL) {
+ BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
+ exit(1);
+ }
+ if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
+ NULL, iv, decrypt ? 0 : 1)) {
+ BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
+ ERR_print_errors(bio_err);
+ exit(1);
+ }
EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
loopargs[k].key = app_malloc(keylen, "evp_cipher key");
EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
- EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
- loopargs[k].key, NULL, -1);
+ if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
+ loopargs[k].key, NULL, -1)) {
+ BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
+ ERR_print_errors(bio_err);
+ exit(1);
+ }
OPENSSL_clear_free(loopargs[k].key, keylen);
+
+ /* SIV mode only allows for a single Update operation */
+ if (EVP_CIPHER_mode(evp_cipher) == EVP_CIPH_SIV_MODE)
+ EVP_CIPHER_CTX_ctrl(loopargs[k].ctx, EVP_CTRL_SET_SPEED, 1, NULL);
}
Time_F(START);
}
}
+ if (doit[D_EVP_HMAC]) {
+ if (evp_hmac_md != NULL) {
+ const char *md_name = OBJ_nid2ln(EVP_MD_type(evp_hmac_md));
+ evp_hmac_name = app_malloc(sizeof("HMAC()") + strlen(md_name),
+ "HMAC name");
+ sprintf(evp_hmac_name, "HMAC(%s)", md_name);
+ names[D_EVP_HMAC] = evp_hmac_name;
+
+ for (testnum = 0; testnum < size_num; testnum++) {
+ print_message(names[D_EVP_HMAC], save_count, lengths[testnum],
+ seconds.sym);
+ Time_F(START);
+ count = run_benchmark(async_jobs, EVP_HMAC_loop, loopargs);
+ d = Time_F(STOP);
+ print_result(D_EVP_HMAC, testnum, count, d);
+ }
+ }
+ }
+
+#ifndef OPENSSL_NO_CMAC
+ if (doit[D_EVP_CMAC]) {
+ if (evp_cmac_cipher != NULL) {
+ const char *cipher_name = OBJ_nid2ln(EVP_CIPHER_type(evp_cmac_cipher));
+ evp_cmac_name = app_malloc(sizeof("CMAC()") + strlen(cipher_name),
+ "CMAC name");
+ sprintf(evp_cmac_name, "CMAC(%s)", cipher_name);
+ names[D_EVP_CMAC] = evp_cmac_name;
+
+ for (i = 0; i < loopargs_len; i++) {
+ loopargs[i].cmac_ctx = CMAC_CTX_new();
+ if (loopargs[i].cmac_ctx == NULL) {
+ BIO_printf(bio_err, "CMAC malloc failure, exiting...");
+ exit(1);
+ }
+ }
+ for (testnum = 0; testnum < size_num; testnum++) {
+ print_message(names[D_EVP_CMAC], save_count, lengths[testnum],
+ seconds.sym);
+ Time_F(START);
+ count = run_benchmark(async_jobs, EVP_CMAC_loop, loopargs);
+ d = Time_F(STOP);
+ print_result(D_EVP_CMAC, testnum, count, d);
+ }
+ for (i = 0; i < loopargs_len; i++)
+ CMAC_CTX_free(loopargs[i].cmac_ctx);
+ }
+ }
+#endif
+
for (i = 0; i < loopargs_len; i++)
- RAND_bytes(loopargs[i].buf, 36);
+ if (RAND_bytes(loopargs[i].buf, 36) <= 0)
+ goto end;
#ifndef OPENSSL_NO_RSA
for (testnum = 0; testnum < RSA_NUM; testnum++) {
#endif /* OPENSSL_NO_RSA */
for (i = 0; i < loopargs_len; i++)
- RAND_bytes(loopargs[i].buf, 36);
+ if (RAND_bytes(loopargs[i].buf, 36) <= 0)
+ goto end;
#ifndef OPENSSL_NO_DSA
for (testnum = 0; testnum < DSA_NUM; testnum++) {
if (rsa_count <= 1) {
/* if longer than 10s, don't do any more */
- for (testnum++; testnum < EC_NUM; testnum++)
+ for (testnum++; testnum < ECDSA_NUM; testnum++)
ecdsa_doit[testnum] = 0;
}
}
if (error == ERR_peek_last_error() && /* oldest and latest errors match */
/* check that the error origin matches */
ERR_GET_LIB(error) == ERR_LIB_EVP &&
- ERR_GET_FUNC(error) == EVP_F_INT_CTX_NEW &&
ERR_GET_REASON(error) == EVP_R_UNSUPPORTED_ALGORITHM)
ERR_get_error(); /* pop error from queue */
if (ERR_peek_error()) {
pctx = NULL;
}
if (kctx == NULL || /* keygen ctx is not null */
- !EVP_PKEY_keygen_init(kctx) /* init keygen ctx */ ) {
+ EVP_PKEY_keygen_init(kctx) <= 0/* init keygen ctx */ ) {
ecdh_checks = 0;
BIO_printf(bio_err, "ECDH keygen failure.\n");
ERR_print_errors(bio_err);
break;
}
- if (!EVP_PKEY_keygen(kctx, &key_A) || /* generate secret key A */
- !EVP_PKEY_keygen(kctx, &key_B) || /* generate secret key B */
+ if (EVP_PKEY_keygen(kctx, &key_A) <= 0 || /* generate secret key A */
+ EVP_PKEY_keygen(kctx, &key_B) <= 0 || /* generate secret key B */
!(ctx = EVP_PKEY_CTX_new(key_A, NULL)) || /* derivation ctx from skeyA */
- !EVP_PKEY_derive_init(ctx) || /* init derivation ctx */
- !EVP_PKEY_derive_set_peer(ctx, key_B) || /* set peer pubkey in ctx */
- !EVP_PKEY_derive(ctx, NULL, &outlen) || /* determine max length */
+ EVP_PKEY_derive_init(ctx) <= 0 || /* init derivation ctx */
+ EVP_PKEY_derive_set_peer(ctx, key_B) <= 0 || /* set peer pubkey in ctx */
+ EVP_PKEY_derive(ctx, NULL, &outlen) <= 0 || /* determine max length */
outlen == 0 || /* ensure outlen is a valid size */
outlen > MAX_ECDH_SIZE /* avoid buffer overflow */ ) {
ecdh_checks = 0;
ecdh_doit[testnum] = 0;
}
}
+
+ for (testnum = 0; testnum < EdDSA_NUM; testnum++) {
+ int st = 1;
+ EVP_PKEY *ed_pkey = NULL;
+ EVP_PKEY_CTX *ed_pctx = NULL;
+
+ if (!eddsa_doit[testnum])
+ continue; /* Ignore Curve */
+ for (i = 0; i < loopargs_len; i++) {
+ loopargs[i].eddsa_ctx[testnum] = EVP_MD_CTX_new();
+ if (loopargs[i].eddsa_ctx[testnum] == NULL) {
+ st = 0;
+ break;
+ }
+
+ if ((ed_pctx = EVP_PKEY_CTX_new_id(test_ed_curves[testnum].nid, NULL))
+ == NULL
+ || EVP_PKEY_keygen_init(ed_pctx) <= 0
+ || EVP_PKEY_keygen(ed_pctx, &ed_pkey) <= 0) {
+ st = 0;
+ EVP_PKEY_CTX_free(ed_pctx);
+ break;
+ }
+ EVP_PKEY_CTX_free(ed_pctx);
+
+ if (!EVP_DigestSignInit(loopargs[i].eddsa_ctx[testnum], NULL, NULL,
+ NULL, ed_pkey)) {
+ st = 0;
+ EVP_PKEY_free(ed_pkey);
+ break;
+ }
+ EVP_PKEY_free(ed_pkey);
+ }
+ if (st == 0) {
+ BIO_printf(bio_err, "EdDSA failure.\n");
+ ERR_print_errors(bio_err);
+ rsa_count = 1;
+ } else {
+ for (i = 0; i < loopargs_len; i++) {
+ /* Perform EdDSA signature test */
+ loopargs[i].sigsize = test_ed_curves[testnum].sigsize;
+ st = EVP_DigestSign(loopargs[i].eddsa_ctx[testnum],
+ loopargs[i].buf2, &loopargs[i].sigsize,
+ loopargs[i].buf, 20);
+ if (st == 0)
+ break;
+ }
+ if (st == 0) {
+ BIO_printf(bio_err,
+ "EdDSA sign failure. No EdDSA sign will be done.\n");
+ ERR_print_errors(bio_err);
+ rsa_count = 1;
+ } else {
+ pkey_print_message("sign", test_ed_curves[testnum].name,
+ eddsa_c[testnum][0],
+ test_ed_curves[testnum].bits, seconds.eddsa);
+ Time_F(START);
+ count = run_benchmark(async_jobs, EdDSA_sign_loop, loopargs);
+ d = Time_F(STOP);
+
+ BIO_printf(bio_err,
+ mr ? "+R8:%ld:%u:%s:%.2f\n" :
+ "%ld %u bits %s signs in %.2fs \n",
+ count, test_ed_curves[testnum].bits,
+ test_ed_curves[testnum].name, d);
+ eddsa_results[testnum][0] = (double)count / d;
+ rsa_count = count;
+ }
+
+ /* Perform EdDSA verification test */
+ for (i = 0; i < loopargs_len; i++) {
+ st = EVP_DigestVerify(loopargs[i].eddsa_ctx[testnum],
+ loopargs[i].buf2, loopargs[i].sigsize,
+ loopargs[i].buf, 20);
+ if (st != 1)
+ break;
+ }
+ if (st != 1) {
+ BIO_printf(bio_err,
+ "EdDSA verify failure. No EdDSA verify will be done.\n");
+ ERR_print_errors(bio_err);
+ eddsa_doit[testnum] = 0;
+ } else {
+ pkey_print_message("verify", test_ed_curves[testnum].name,
+ eddsa_c[testnum][1],
+ test_ed_curves[testnum].bits, seconds.eddsa);
+ Time_F(START);
+ count = run_benchmark(async_jobs, EdDSA_verify_loop, loopargs);
+ d = Time_F(STOP);
+ BIO_printf(bio_err,
+ mr ? "+R9:%ld:%u:%s:%.2f\n"
+ : "%ld %u bits %s verify in %.2fs\n",
+ count, test_ed_curves[testnum].bits,
+ test_ed_curves[testnum].name, d);
+ eddsa_results[testnum][1] = (double)count / d;
+ }
+
+ if (rsa_count <= 1) {
+ /* if longer than 10s, don't do any more */
+ for (testnum++; testnum < EdDSA_NUM; testnum++)
+ eddsa_doit[testnum] = 0;
+ }
+ }
+ }
+
+# ifndef OPENSSL_NO_SM2
+ for (testnum = 0; testnum < SM2_NUM; testnum++) {
+ int st = 1;
+ EVP_PKEY *sm2_pkey = NULL;
+ EVP_PKEY_CTX *pctx = NULL;
+ EVP_PKEY_CTX *sm2_pctx = NULL;
+ EVP_PKEY_CTX *sm2_vfy_pctx = NULL;
+ size_t sm2_sigsize = 0;
+
+ if (!sm2_doit[testnum])
+ continue; /* Ignore Curve */
+ /* Init signing and verification */
+ for (i = 0; i < loopargs_len; i++) {
+ loopargs[i].sm2_ctx[testnum] = EVP_MD_CTX_new();
+ if (loopargs[i].sm2_ctx[testnum] == NULL) {
+ st = 0;
+ break;
+ }
+ loopargs[i].sm2_vfy_ctx[testnum] = EVP_MD_CTX_new();
+ if (loopargs[i].sm2_vfy_ctx[testnum] == NULL) {
+ st = 0;
+ break;
+ }
+
+ /* SM2 keys are generated as normal EC keys with a special curve */
+ if ((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL)) == NULL
+ || EVP_PKEY_keygen_init(pctx) <= 0
+ || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
+ test_sm2_curves[testnum].nid) <= 0
+ || EVP_PKEY_keygen(pctx, &sm2_pkey) <= 0) {
+ st = 0;
+ EVP_PKEY_CTX_free(pctx);
+ break;
+ }
+ /* free previous one and alloc a new one */
+ EVP_PKEY_CTX_free(pctx);
+
+ loopargs[i].sigsize = sm2_sigsize
+ = ECDSA_size(EVP_PKEY_get0_EC_KEY(sm2_pkey));
+
+ if (!EVP_PKEY_set_alias_type(sm2_pkey, EVP_PKEY_SM2)) {
+ st = 0;
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+
+ sm2_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
+ if (sm2_pctx == NULL) {
+ st = 0;
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+ sm2_vfy_pctx = EVP_PKEY_CTX_new(sm2_pkey, NULL);
+ if (sm2_vfy_pctx == NULL) {
+ st = 0;
+ EVP_PKEY_CTX_free(sm2_pctx);
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+ /*
+ * No need to allow user to set an explicit ID here, just use
+ * the one defined in the 'draft-yang-tls-tl13-sm-suites' I-D.
+ */
+ if (EVP_PKEY_CTX_set1_id(sm2_pctx, SM2_ID, SM2_ID_LEN) != 1) {
+ st = 0;
+ EVP_PKEY_CTX_free(sm2_pctx);
+ EVP_PKEY_CTX_free(sm2_vfy_pctx);
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+
+ if (EVP_PKEY_CTX_set1_id(sm2_vfy_pctx, SM2_ID, SM2_ID_LEN) != 1) {
+ st = 0;
+ EVP_PKEY_CTX_free(sm2_pctx);
+ EVP_PKEY_CTX_free(sm2_vfy_pctx);
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+
+ EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_ctx[testnum], sm2_pctx);
+ EVP_MD_CTX_set_pkey_ctx(loopargs[i].sm2_vfy_ctx[testnum], sm2_vfy_pctx);
+
+ if (!EVP_DigestSignInit(loopargs[i].sm2_ctx[testnum], NULL,
+ EVP_sm3(), NULL, sm2_pkey)) {
+ st = 0;
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+ if (!EVP_DigestVerifyInit(loopargs[i].sm2_vfy_ctx[testnum], NULL,
+ EVP_sm3(), NULL, sm2_pkey)) {
+ st = 0;
+ EVP_PKEY_free(sm2_pkey);
+ break;
+ }
+ loopargs[i].sm2_pkey[testnum] = sm2_pkey;
+ }
+ if (st == 0) {
+ BIO_printf(bio_err, "SM2 failure.\n");
+ ERR_print_errors(bio_err);
+ rsa_count = 1;
+ } else {
+ for (i = 0; i < loopargs_len; i++) {
+ sm2_sigsize = loopargs[i].sigsize;
+ /* Perform SM2 signature test */
+ st = EVP_DigestSign(loopargs[i].sm2_ctx[testnum],
+ loopargs[i].buf2, &sm2_sigsize,
+ loopargs[i].buf, 20);
+ if (st == 0)
+ break;
+ }
+ if (st == 0) {
+ BIO_printf(bio_err,
+ "SM2 sign failure. No SM2 sign will be done.\n");
+ ERR_print_errors(bio_err);
+ rsa_count = 1;
+ } else {
+ pkey_print_message("sign", test_sm2_curves[testnum].name,
+ sm2_c[testnum][0],
+ test_sm2_curves[testnum].bits, seconds.sm2);
+ Time_F(START);
+ count = run_benchmark(async_jobs, SM2_sign_loop, loopargs);
+ d = Time_F(STOP);
+
+ BIO_printf(bio_err,
+ mr ? "+R8:%ld:%u:%s:%.2f\n" :
+ "%ld %u bits %s signs in %.2fs \n",
+ count, test_sm2_curves[testnum].bits,
+ test_sm2_curves[testnum].name, d);
+ sm2_results[testnum][0] = (double)count / d;
+ rsa_count = count;
+ }
+
+ /* Perform SM2 verification test */
+ for (i = 0; i < loopargs_len; i++) {
+ st = EVP_DigestVerify(loopargs[i].sm2_vfy_ctx[testnum],
+ loopargs[i].buf2, loopargs[i].sigsize,
+ loopargs[i].buf, 20);
+ if (st != 1)
+ break;
+ }
+ if (st != 1) {
+ BIO_printf(bio_err,
+ "SM2 verify failure. No SM2 verify will be done.\n");
+ ERR_print_errors(bio_err);
+ sm2_doit[testnum] = 0;
+ } else {
+ pkey_print_message("verify", test_sm2_curves[testnum].name,
+ sm2_c[testnum][1],
+ test_sm2_curves[testnum].bits, seconds.sm2);
+ Time_F(START);
+ count = run_benchmark(async_jobs, SM2_verify_loop, loopargs);
+ d = Time_F(STOP);
+ BIO_printf(bio_err,
+ mr ? "+R9:%ld:%u:%s:%.2f\n"
+ : "%ld %u bits %s verify in %.2fs\n",
+ count, test_sm2_curves[testnum].bits,
+ test_sm2_curves[testnum].name, d);
+ sm2_results[testnum][1] = (double)count / d;
+ }
+
+ if (rsa_count <= 1) {
+ /* if longer than 10s, don't do any more */
+ for (testnum++; testnum < SM2_NUM; testnum++)
+ sm2_doit[testnum] = 0;
+ }
+ }
+ }
+# endif /* OPENSSL_NO_SM2 */
+
#endif /* OPENSSL_NO_EC */
#ifndef NO_FORK
show_res:
#endif
if (!mr) {
- printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
- printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
+ printf("version: %s\n", OpenSSL_version(OPENSSL_FULL_VERSION_STRING));
+ printf("built on: %s\n", OpenSSL_version(OPENSSL_BUILT_ON));
printf("options:");
printf("%s ", BN_options());
#ifndef OPENSSL_NO_MD2
printf("%s ", BF_options());
#endif
printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS));
+ printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
}
if (pr_header) {
test_curves[k].bits, test_curves[k].name,
1.0 / ecdh_results[k][0], ecdh_results[k][0]);
}
+
+ testnum = 1;
+ for (k = 0; k < OSSL_NELEM(eddsa_doit); k++) {
+ if (!eddsa_doit[k])
+ continue;
+ if (testnum && !mr) {
+ printf("%30ssign verify sign/s verify/s\n", " ");
+ testnum = 0;
+ }
+
+ if (mr)
+ printf("+F6:%u:%u:%s:%f:%f\n",
+ k, test_ed_curves[k].bits, test_ed_curves[k].name,
+ eddsa_results[k][0], eddsa_results[k][1]);
+ else
+ printf("%4u bits EdDSA (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
+ test_ed_curves[k].bits, test_ed_curves[k].name,
+ 1.0 / eddsa_results[k][0], 1.0 / eddsa_results[k][1],
+ eddsa_results[k][0], eddsa_results[k][1]);
+ }
+
+# ifndef OPENSSL_NO_SM2
+ testnum = 1;
+ for (k = 0; k < OSSL_NELEM(sm2_doit); k++) {
+ if (!sm2_doit[k])
+ continue;
+ if (testnum && !mr) {
+ printf("%30ssign verify sign/s verify/s\n", " ");
+ testnum = 0;
+ }
+
+ if (mr)
+ printf("+F6:%u:%u:%s:%f:%f\n",
+ k, test_sm2_curves[k].bits, test_sm2_curves[k].name,
+ sm2_results[k][0], sm2_results[k][1]);
+ else
+ printf("%4u bits SM2 (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
+ test_sm2_curves[k].bits, test_sm2_curves[k].name,
+ 1.0 / sm2_results[k][0], 1.0 / sm2_results[k][1],
+ sm2_results[k][0], sm2_results[k][1]);
+ }
+# endif
#endif
ret = 0;
EC_KEY_free(loopargs[i].ecdsa[k]);
for (k = 0; k < EC_NUM; k++)
EVP_PKEY_CTX_free(loopargs[i].ecdh_ctx[k]);
+ for (k = 0; k < EdDSA_NUM; k++)
+ EVP_MD_CTX_free(loopargs[i].eddsa_ctx[k]);
+# ifndef OPENSSL_NO_SM2
+ for (k = 0; k < SM2_NUM; k++) {
+ EVP_PKEY_CTX *pctx = NULL;
+
+ /* free signing ctx */
+ if (loopargs[i].sm2_ctx[k] != NULL
+ && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_ctx[k])) != NULL)
+ EVP_PKEY_CTX_free(pctx);
+ EVP_MD_CTX_free(loopargs[i].sm2_ctx[k]);
+ /* free verification ctx */
+ if (loopargs[i].sm2_vfy_ctx[k] != NULL
+ && (pctx = EVP_MD_CTX_pkey_ctx(loopargs[i].sm2_vfy_ctx[k])) != NULL)
+ EVP_PKEY_CTX_free(pctx);
+ EVP_MD_CTX_free(loopargs[i].sm2_vfy_ctx[k]);
+ /* free pkey */
+ EVP_PKEY_free(loopargs[i].sm2_pkey[k]);
+ }
+# endif
OPENSSL_free(loopargs[i].secret_a);
OPENSSL_free(loopargs[i].secret_b);
#endif
}
+ OPENSSL_free(evp_hmac_name);
+#ifndef OPENSSL_NO_CMAC
+ OPENSSL_free(evp_cmac_name);
+#endif
if (async_jobs > 0) {
for (i = 0; i < loopargs_len; i++)
close(fd[1]);
mr = 1;
usertime = 0;
- free(fds);
+ OPENSSL_free(fds);
return 0;
}
printf("Forked child %d\n", n);
d = atof(sstrsep(&p, sep));
ecdh_results[k][0] += d;
+ } else if (strncmp(buf, "+F6:", 4) == 0) {
+ int k;
+ double d;
+
+ p = buf + 4;
+ k = atoi(sstrsep(&p, sep));
+ sstrsep(&p, sep);
+
+ d = atof(sstrsep(&p, sep));
+ eddsa_results[k][0] += d;
+
+ d = atof(sstrsep(&p, sep));
+ eddsa_results[k][1] += d;
+ }
+# ifndef OPENSSL_NO_SM2
+ else if (strncmp(buf, "+F7:", 4) == 0) {
+ int k;
+ double d;
+
+ p = buf + 4;
+ k = atoi(sstrsep(&p, sep));
+ sstrsep(&p, sep);
+
+ d = atof(sstrsep(&p, sep));
+ sm2_results[k][0] += d;
+
+ d = atof(sstrsep(&p, sep));
+ sm2_results[k][1] += d;
}
+# endif /* OPENSSL_NO_SM2 */
# endif
else if (strncmp(buf, "+H:", 3) == 0) {
fclose(f);
}
- free(fds);
+ OPENSSL_free(fds);
return 1;
}
#endif