Deprecate EC_GROUP_clear_free()
[openssl.git] / test / mdc2test.c
index 724d6d323e7c06c81477b596d8024efa4549501d..f8c492297ec9ea4de46d260c913813d3c8949c6f 100644 (file)
@@ -1,15 +1,18 @@
 /*
  * Copyright 1995-2017 The OpenSSL Project Authors. 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
  */
 
 #include <string.h>
-
-#include "../e_os.h"
+#include <openssl/provider.h>
+#include <openssl/params.h>
+#include <openssl/types.h>
+#include <openssl/core_names.h>
+#include "internal/nelem.h"
 #include "testutil.h"
 
 #if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
@@ -37,11 +40,19 @@ static unsigned char pad2[16] = {
 static int test_mdc2(void)
 {
     int testresult = 0;
+    unsigned int pad_type = 2;
     unsigned char md[MDC2_DIGEST_LENGTH];
     EVP_MD_CTX *c;
     static char text[] = "Now is the time for all ";
-    size_t tlen = strlen(text);
+    size_t tlen = strlen(text), i = 0;
+    OSSL_PROVIDER *prov = NULL;
+    OSSL_PARAM params[2];
+
+    params[i++] = OSSL_PARAM_construct_uint(OSSL_DIGEST_PARAM_PAD_TYPE,
+                                            &pad_type),
+    params[i++] = OSSL_PARAM_construct_end();
 
+    prov = OSSL_PROVIDER_load(NULL, "legacy");
 # ifdef CHARSET_EBCDIC
     ebcdic2ascii(text, text, tlen);
 # endif
@@ -55,9 +66,8 @@ static int test_mdc2(void)
         || !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL)))
         goto end;
 
-    /* FIXME: use a ctl function? */
-    ((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
-    if (!TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
+    if (!TEST_int_gt(EVP_MD_CTX_set_params(c, params), 0)
+        || !TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
         || !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
         || !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad2, MDC2_DIGEST_LENGTH))
         goto end;
@@ -65,13 +75,15 @@ static int test_mdc2(void)
     testresult = 1;
  end:
     EVP_MD_CTX_free(c);
+    OSSL_PROVIDER_unload(prov);
     return testresult;
 }
 #endif
 
-void register_tests(void)
+int setup_tests(void)
 {
 #ifndef OPENSSL_NO_MDC2
     ADD_TEST(test_mdc2);
 #endif
+    return 1;
 }