#endif
static int domlock = 0;
+static int testmode = 0;
+static int testmoderesult = 0;
static const int lengths_list[] = {
16, 64, 256, 1024, 8 * 1024, 16 * 1024
typedef enum OPTION_choice {
OPT_COMMON,
OPT_ELAPSED, OPT_EVP, OPT_HMAC, OPT_DECRYPT, OPT_ENGINE, OPT_MULTI,
- OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM, OPT_CONFIG,
- OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC, OPT_MLOCK, OPT_KEM, OPT_SIG
+ OPT_MR, OPT_MB, OPT_MISALIGN, OPT_ASYNCJOBS, OPT_R_ENUM, OPT_PROV_ENUM,
+ OPT_CONFIG, OPT_PRIMES, OPT_SECONDS, OPT_BYTES, OPT_AEAD, OPT_CMAC,
+ OPT_MLOCK, OPT_TESTMODE, OPT_KEM, OPT_SIG
} OPTION_CHOICE;
const OPTIONS speed_options[] = {
#endif
{"primes", OPT_PRIMES, 'p', "Specify number of primes (for RSA only)"},
{"mlock", OPT_MLOCK, '-', "Lock memory for better result determinism"},
+ {"testmode", OPT_TESTMODE, '-', "Run the speed command in test mode"},
OPT_CONFIG_OPTION,
OPT_SECTION("Selection"),
static char *sigs_algname[MAX_SIG_NUM] = { NULL };
static double sigs_results[MAX_SIG_NUM][3]; /* keygen, sign, verify */
-#define COND(unused_cond) (run && count < INT_MAX)
+#define COND(unused_cond) (run && count < (testmode ? 1 : INT_MAX))
#define COUNT(d) (count)
typedef struct loopargs_st {
static char *evp_mac_ciphername = "aes-128-cbc";
static char *evp_cmac_name = NULL;
+static void dofail(void)
+{
+ ERR_print_errors(bio_err);
+ testmoderesult = 1;
+}
+
static int have_md(const char *name)
{
int ret = 0;
ret = EVP_PKEY_sign(rsa_sign_ctx[testnum], buf2, rsa_num, buf, 36);
if (ret <= 0) {
BIO_printf(bio_err, "RSA sign failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_verify(rsa_verify_ctx[testnum], buf2, rsa_num, buf, 36);
if (ret <= 0) {
BIO_printf(bio_err, "RSA verify failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_encrypt(rsa_encrypt_ctx[testnum], buf2, rsa_num, buf, 36);
if (ret <= 0) {
BIO_printf(bio_err, "RSA encrypt failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_decrypt(rsa_decrypt_ctx[testnum], buf, &rsa_num, buf2, tempargs->encsize);
if (ret <= 0) {
BIO_printf(bio_err, "RSA decrypt failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_sign(dsa_sign_ctx[testnum], buf2, dsa_num, buf, 20);
if (ret <= 0) {
BIO_printf(bio_err, "DSA sign failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_verify(dsa_verify_ctx[testnum], buf2, dsa_num, buf, 20);
if (ret <= 0) {
BIO_printf(bio_err, "DSA verify failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_PKEY_sign(ecdsa_sign_ctx[testnum], buf2, ecdsa_num, buf, 20);
if (ret <= 0) {
BIO_printf(bio_err, "ECDSA sign failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
buf, 20);
if (ret <= 0) {
BIO_printf(bio_err, "ECDSA verify failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
ret = EVP_DigestSignInit(edctx[testnum], NULL, NULL, NULL, NULL);
if (ret == 0) {
BIO_printf(bio_err, "EdDSA sign init failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
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);
+ dofail();
count = -1;
break;
}
ret = EVP_DigestVerifyInit(edctx[testnum], NULL, NULL, NULL, NULL);
if (ret == 0) {
BIO_printf(bio_err, "EdDSA verify init failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
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);
+ dofail();
count = -1;
break;
}
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);
+ dofail();
count = -1;
break;
}
buf, 20);
if (ret == 0) {
BIO_printf(bio_err, "SM2 sign failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
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);
+ dofail();
count = -1;
break;
}
buf, 20);
if (ret != 1) {
BIO_printf(bio_err, "SM2 verify failure\n");
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
if (ret <= 0) {
BIO_printf(bio_err, "SIG sign failure at count %d\n", count);
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
if (ret <= 0) {
BIO_printf(bio_err, "SIG verify failure at count %d\n", count);
- ERR_print_errors(bio_err);
+ dofail();
count = -1;
break;
}
case ASYNC_NO_JOBS:
case ASYNC_ERR:
BIO_printf(bio_err, "Failure in the job\n");
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
(loopargs[i].wait_ctx, NULL, &num_job_fds)
|| num_job_fds > 1) {
BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
"Error: max_fd (%d) must be smaller than FD_SETSIZE (%d). "
"Decrease the value of async_jobs\n",
max_fd, FD_SETSIZE);
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
if (select_result == -1) {
BIO_printf(bio_err, "Failure in the select\n");
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
(loopargs[i].wait_ctx, NULL, &num_job_fds)
|| num_job_fds > 1) {
BIO_printf(bio_err, "Too many fds in ASYNC_WAIT_CTX\n");
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
--num_inprogress;
loopargs[i].inprogress_job = NULL;
BIO_printf(bio_err, "Failure in the job\n");
- ERR_print_errors(bio_err);
+ dofail();
error = 1;
break;
}
if (ERR_peek_error()) {
BIO_printf(bio_err,
"WARNING: the error queue contains previous unhandled errors.\n");
- ERR_print_errors(bio_err);
+ dofail();
}
/*
if (ERR_peek_error()) {
BIO_printf(bio_err,
"Unhandled error in the error queue during EC key setup.\n");
- ERR_print_errors(bio_err);
+ dofail();
return NULL;
}
curve->nid) <= 0
|| EVP_PKEY_paramgen(pctx, ¶ms) <= 0) {
BIO_printf(bio_err, "EC params init failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
EVP_PKEY_CTX_free(pctx);
return NULL;
}
|| EVP_PKEY_keygen_init(kctx) <= 0
|| EVP_PKEY_keygen(kctx, &key) <= 0) {
BIO_printf(bio_err, "EC key generation failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
key = NULL;
}
EVP_PKEY_CTX_free(kctx);
goto end;
#endif
break;
+ case OPT_TESTMODE:
+ testmode = 1;
+ break;
}
}
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);
+ dofail();
exit(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);
+ dofail();
exit(1);
}
OPENSSL_clear_free(loopargs[k].key, keylen);
if (!st) {
BIO_printf(bio_err,
"RSA sign setup failure. No RSA sign will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("private", "rsa sign",
if (!st) {
BIO_printf(bio_err,
"RSA verify setup failure. No RSA verify will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
rsa_doit[testnum] = 0;
} else {
pkey_print_message("public", "rsa verify",
if (!st) {
BIO_printf(bio_err,
"RSA encrypt setup failure. No RSA encrypt will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("public", "rsa encrypt",
if (!st) {
BIO_printf(bio_err,
"RSA decrypt setup failure. No RSA decrypt will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("private", "rsa decrypt",
if (!st) {
BIO_printf(bio_err,
"DSA sign setup failure. No DSA sign will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("sign", "dsa",
if (!st) {
BIO_printf(bio_err,
"DSA verify setup failure. No DSA verify will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
dsa_doit[testnum] = 0;
} else {
pkey_print_message("verify", "dsa",
if (!st) {
BIO_printf(bio_err,
"ECDSA sign setup failure. No ECDSA sign will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("sign", "ecdsa",
if (!st) {
BIO_printf(bio_err,
"ECDSA verify setup failure. No ECDSA verify will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
ecdsa_doit[testnum] = 0;
} else {
pkey_print_message("verify", "ecdsa",
|| outlen > MAX_ECDH_SIZE /* avoid buffer overflow */) {
ecdh_checks = 0;
BIO_printf(bio_err, "ECDH key generation failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
break;
}
|| test_outlen != outlen /* compare output length */) {
ecdh_checks = 0;
BIO_printf(bio_err, "ECDH computation failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
break;
}
loopargs[i].secret_b, outlen)) {
ecdh_checks = 0;
BIO_printf(bio_err, "ECDH computations don't match.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
break;
}
}
if (st == 0) {
BIO_printf(bio_err, "EdDSA failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
for (i = 0; i < loopargs_len; i++) {
if (st == 0) {
BIO_printf(bio_err,
"EdDSA sign failure. No EdDSA sign will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("sign", ed_curves[testnum].name,
if (st != 1) {
BIO_printf(bio_err,
"EdDSA verify failure. No EdDSA verify will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
eddsa_doit[testnum] = 0;
} else {
pkey_print_message("verify", ed_curves[testnum].name,
}
if (st == 0) {
BIO_printf(bio_err, "SM2 init failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
for (i = 0; i < loopargs_len; i++) {
if (st == 0) {
BIO_printf(bio_err,
"SM2 sign failure. No SM2 sign will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
} else {
pkey_print_message("sign", sm2_curves[testnum].name,
if (st != 1) {
BIO_printf(bio_err,
"SM2 verify failure. No SM2 verify will be done.\n");
- ERR_print_errors(bio_err);
+ dofail();
sm2_doit[testnum] = 0;
} else {
pkey_print_message("verify", sm2_curves[testnum].name,
if (ERR_peek_error()) {
BIO_printf(bio_err,
"WARNING: the error queue contains previous unhandled errors.\n");
- ERR_print_errors(bio_err);
+ dofail();
}
pkey_A = EVP_PKEY_new();
if (!pkey_A) {
BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
pkey_B = EVP_PKEY_new();
if (!pkey_B) {
BIO_printf(bio_err, "Error while initialising EVP_PKEY (out of memory?).\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
ffdh_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DH, NULL);
if (!ffdh_ctx) {
BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
if (EVP_PKEY_keygen_init(ffdh_ctx) <= 0) {
BIO_printf(bio_err, "Error while initialising EVP_PKEY_CTX.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
}
if (EVP_PKEY_CTX_set_dh_nid(ffdh_ctx, ffdh_params[testnum].nid) <= 0) {
BIO_printf(bio_err, "Error setting DH key size for keygen.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
if (EVP_PKEY_keygen(ffdh_ctx, &pkey_A) <= 0 ||
EVP_PKEY_keygen(ffdh_ctx, &pkey_B) <= 0) {
BIO_printf(bio_err, "FFDH key generation failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
ffdh_ctx = EVP_PKEY_CTX_new(pkey_A, NULL);
if (ffdh_ctx == NULL) {
BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
}
if (EVP_PKEY_derive_init(ffdh_ctx) <= 0) {
BIO_printf(bio_err, "FFDH derivation context init failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
}
if (EVP_PKEY_derive_set_peer(ffdh_ctx, pkey_B) <= 0) {
BIO_printf(bio_err, "Assigning peer key for derivation failed.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
}
if (EVP_PKEY_derive(ffdh_ctx, NULL, &secret_size) <= 0) {
BIO_printf(bio_err, "Checking size of shared secret failed.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
loopargs[i].secret_ff_a,
&secret_size) <= 0) {
BIO_printf(bio_err, "Shared secret derive failure.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
test_ctx = EVP_PKEY_CTX_new(pkey_B, NULL);
if (!test_ctx) {
BIO_printf(bio_err, "Error while allocating EVP_PKEY_CTX.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
if (CRYPTO_memcmp(loopargs[i].secret_ff_a,
loopargs[i].secret_ff_b, secret_size)) {
BIO_printf(bio_err, "FFDH computations don't match.\n");
- ERR_print_errors(bio_err);
+ dofail();
op_count = 1;
ffdh_checks = 0;
break;
if (ERR_peek_error()) {
BIO_printf(bio_err,
"WARNING: the error queue contains previous unhandled errors.\n");
- ERR_print_errors(bio_err);
+ dofail();
}
if (kem_type == KEM_RSA) {
continue;
kem_err_break:
- ERR_print_errors(bio_err);
+ dofail();
EVP_PKEY_free(pkey);
op_count = 1;
kem_checks = 0;
if (ERR_peek_error()) {
BIO_printf(bio_err,
"WARNING: the error queue contains previous unhandled errors.\n");
- ERR_print_errors(bio_err);
+ dofail();
}
/* no string after rsa<bitcnt> permitted: */
continue;
sig_err_break:
- ERR_print_errors(bio_err);
+ dofail();
EVP_PKEY_free(pkey);
op_count = 1;
sig_checks = 0;
ret = 0;
end:
+ if (ret == 0 && testmode)
+ ret = testmoderesult;
ERR_print_errors(bio_err);
for (i = 0; i < loopargs_len; i++) {
OPENSSL_free(loopargs[i].buf_malloc);
{
if (count == -1) {
BIO_printf(bio_err, "%s error!\n", names[alg]);
- ERR_print_errors(bio_err);
+ dofail();
return;
}
BIO_printf(bio_err,
for (j = 0; j < num; j++) {
print_message(alg_name, mblengths[j], seconds->sym);
Time_F(START);
- for (count = 0; run && count < INT_MAX; count++) {
+ for (count = 0; run && COND(count); count++) {
unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
size_t len = mblengths[j];