CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
- ERR_load_crypto_strings();
- OpenSSL_add_all_algorithms();
-
memset(&t, 0, sizeof(t));
t.start_line = -1;
in = fopen(argv[1], "r");
free_key_list(t.public);
free_key_list(t.private);
fclose(in);
- EVP_cleanup();
- CRYPTO_cleanup_all_ex_data();
- ERR_remove_thread_state(NULL);
- ERR_free_strings();
+
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- CRYPTO_mem_leaks_fp(stderr);
+ if (CRYPTO_mem_leaks_fp(stderr) <= 0)
+ return 1;
#endif
if (t.errors)
return 1;
EVP_PKEY_CTX_free(kdata->ctx);
}
+static int pkey_test_ctrl(EVP_PKEY_CTX *pctx, const char *value)
+{
+ int rv;
+ char *p, *tmpval;
+
+ tmpval = OPENSSL_strdup(value);
+ if (tmpval == NULL)
+ return 0;
+ p = strchr(tmpval, ':');
+ if (p != NULL)
+ *p++ = 0;
+ rv = EVP_PKEY_CTX_ctrl_str(pctx, tmpval, p);
+ OPENSSL_free(tmpval);
+ return rv > 0;
+}
+
static int pkey_test_parse(struct evp_test *t,
const char *keyword, const char *value)
{
return test_bin(value, &kdata->input, &kdata->input_len);
if (strcmp(keyword, "Output") == 0)
return test_bin(value, &kdata->output, &kdata->output_len);
- if (strcmp(keyword, "Ctrl") == 0) {
- char *p = strchr(value, ':');
- if (p)
- *p++ = 0;
- if (EVP_PKEY_CTX_ctrl_str(kdata->ctx, value, p) <= 0)
- return 0;
- return 1;
- }
+ if (strcmp(keyword, "Ctrl") == 0)
+ return pkey_test_ctrl(kdata->ctx, value);
return 0;
}
}
if (strcmp(keyword, "SharedSecret") == 0)
return test_bin(value, &kdata->output, &kdata->output_len);
- if (strcmp(keyword, "Ctrl") == 0) {
- char *p = strchr(value, ':');
- if (p)
- *p++ = 0;
- if (EVP_PKEY_CTX_ctrl_str(kdata->ctx, value, p) <= 0)
- return 0;
- return 1;
- }
+ if (strcmp(keyword, "Ctrl") == 0)
+ return pkey_test_ctrl(kdata->ctx, value);
return 0;
}
encode_test_run,
};
-/*
- * KDF operations: initially just TLS1 PRF but can be adapted.
- */
+/* KDF operations */
struct kdf_data {
/* Context for this operation */
EVP_PKEY_CTX_free(kdata->ctx);
}
-static int kdf_ctrl(EVP_PKEY_CTX *ctx, int op, const char *value)
-{
- unsigned char *buf = NULL;
- size_t buf_len;
- int rv = 0;
- if (test_bin(value, &buf, &buf_len) == 0)
- return 0;
- if (EVP_PKEY_CTX_ctrl(ctx, -1, -1, op, buf_len, buf) <= 0)
- goto err;
- rv = 1;
- err:
- OPENSSL_free(buf);
- return rv;
-}
-
static int kdf_test_parse(struct evp_test *t,
const char *keyword, const char *value)
{
struct kdf_data *kdata = t->data;
if (strcmp(keyword, "Output") == 0)
return test_bin(value, &kdata->output, &kdata->output_len);
- else if (strcmp(keyword, "MD") == 0) {
- const EVP_MD *md = EVP_get_digestbyname(value);
- if (md == NULL)
- return 0;
- if (EVP_PKEY_CTX_set_tls1_prf_md(kdata->ctx, md) <= 0)
- return 0;
- return 1;
- } else if (strcmp(keyword, "Secret") == 0) {
- return kdf_ctrl(kdata->ctx, EVP_PKEY_CTRL_TLS_SECRET, value);
- } else if (strncmp("Seed", keyword, 4) == 0) {
- return kdf_ctrl(kdata->ctx, EVP_PKEY_CTRL_TLS_SEED, value);
- }
+ if (strncmp(keyword, "Ctrl", 4) == 0)
+ return pkey_test_ctrl(kdata->ctx, value);
return 0;
}