Start documenting Configure internals
[openssl.git] / test / evp_test.c
index 8618cfe708a200864d590da5cb77590a2a0c0284..bda7f694a3d52335adab4a220fecc028d28701ac 100644 (file)
@@ -592,9 +592,6 @@ int main(int argc, char **argv)
 
     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");
@@ -612,12 +609,10 @@ int main(int argc, char **argv)
     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;
@@ -1228,6 +1223,22 @@ static void pkey_test_cleanup(struct evp_test *t)
     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)
 {
@@ -1236,14 +1247,8 @@ static int pkey_test_parse(struct evp_test *t,
         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;
 }
 
@@ -1362,14 +1367,8 @@ static int pderive_test_parse(struct evp_test *t,
     }
     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;
 }
 
@@ -1740,9 +1739,7 @@ static const struct evp_test_method encode_test_method = {
     encode_test_run,
 };
 
-/*
- * KDF operations: initially just TLS1 PRF but can be adapted.
- */
+/* KDF operations */
 
 struct kdf_data {
     /* Context for this operation */
@@ -1781,39 +1778,14 @@ static void kdf_test_cleanup(struct evp_test *t)
     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;
 }