Browse Source

mdc2: use evp_test instead of a separate test application.

One of the MDC2 test applications can be done using evp_test.
This makes it so.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10831)
Pauli 4 years ago
parent
commit
ed5cb1776b

+ 15 - 0
test/evp_test.c

@@ -331,6 +331,8 @@ typedef struct digest_data_st {
     /* Expected output */
     unsigned char *output;
     size_t output_len;
+    /* Padding type */
+    int pad_type;
 } DIGEST_DATA;
 
 static int digest_test_init(EVP_TEST *t, const char *alg)
@@ -353,6 +355,7 @@ static int digest_test_init(EVP_TEST *t, const char *alg)
     t->data = mdat;
     mdat->digest = digest;
     mdat->fetched_digest = fetched_digest;
+    mdat->pad_type = 0;
     if (fetched_digest != NULL)
         TEST_info("%s is fetched", alg);
     return 1;
@@ -380,6 +383,8 @@ static int digest_test_parse(EVP_TEST *t,
         return evp_test_buffer_set_count(value, mdata->input);
     if (strcmp(keyword, "Ncopy") == 0)
         return evp_test_buffer_ncopy(value, mdata->input);
+    if (strcmp(keyword, "Padding") == 0)
+        return (mdata->pad_type = atoi(value)) > 0;
     return 0;
 }
 
@@ -394,6 +399,7 @@ static int digest_test_run(EVP_TEST *t)
     EVP_MD_CTX *mctx;
     unsigned char *got = NULL;
     unsigned int got_len;
+    OSSL_PARAM params[2];
 
     t->err = "TEST_FAILURE";
     if (!TEST_ptr(mctx = EVP_MD_CTX_new()))
@@ -408,6 +414,15 @@ static int digest_test_run(EVP_TEST *t)
         t->err = "DIGESTINIT_ERROR";
         goto err;
     }
+    if (expected->pad_type > 0) {
+        params[0] = OSSL_PARAM_construct_int(OSSL_DIGEST_PARAM_PAD_TYPE,
+                                              &expected->pad_type);
+        params[1] = OSSL_PARAM_construct_end();
+        if (!TEST_int_gt(EVP_MD_CTX_set_params(mctx, params), 0)) {
+            t->err = "PARAMS_ERROR";
+            goto err;
+        }
+    }
     if (!evp_test_buffer_do(expected->input, digest_update_fn, mctx)) {
         t->err = "DIGESTUPDATE_ERROR";
         goto err;

+ 0 - 24
test/recipes/05-test_mdc2.t

@@ -1,24 +0,0 @@
-#! /usr/bin/env perl
-# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
-#
-# 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
-
-
-use strict;
-use warnings;
-
-use OpenSSL::Test qw/:DEFAULT bldtop_dir/;
-use OpenSSL::Test::Utils;
-
-setup("test_mdc2");
-
-if (disabled("mdc2") || disabled("legacy")) {
-    plan skip_all => "mdc2 is not supported by this OpenSSL build";
-}
-
-plan tests => 1;
-
-ok(run(test(["mdc2test"])), "running mdc2test");

+ 3 - 0
test/recipes/30-test_evp.t

@@ -70,6 +70,9 @@ push @defltfiles, @bffiles unless disabled("bf");
 my @bffiles = qw( evpmd_md2.txt );
 push @defltfiles, @bffiles unless disabled("md2");
 
+my @bffiles = qw( evpmd_mdc2.txt );
+push @defltfiles, @bffiles unless disabled("mdc2");
+
 plan tests =>
     ($no_fips ? 0 : 1)          # FIPS install test
     + (scalar(@configs) * scalar(@files))

+ 27 - 0
test/recipes/30-test_evp_data/evpmd_mdc2.txt

@@ -0,0 +1,27 @@
+#
+# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
+#
+# 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
+
+
+Title = MDC2 test vectors
+
+Digest = MDC2
+Availablein = default
+Input = "Now is the time for all "
+Output = 42e50cd224baceba760bdd2bd409281a
+
+Digest = MDC2
+Availablein = default
+Padding = 1
+Input = "Now is the time for all "
+Output = 42e50cd224baceba760bdd2bd409281a
+
+Digest = MDC2
+Availablein = default
+Padding = 2
+Input = "Now is the time for all "
+Output = 2e4679b5add9ca7535d87afeab33bee2