]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/evp_test.c: modify to use OSSL_PROVIDER_available()
authorRichard Levitte <levitte@openssl.org>
Wed, 17 Jul 2019 09:34:14 +0000 (11:34 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 26 Jul 2019 16:14:41 +0000 (18:14 +0200)
This changes the stanza format used so far.  Some test stanza had the
following line, only possible for digests:

    Legacy = 1

These have been traded for the following:

    Availablein = legacy

That line is globally available in all test stanza and can be used to
tell what providers a certain algorithm may be available in.  Only one
provider needs to match, so one might have something like this for
some tests:

    Availablein = default fips

This means that one of those providers must be available for the test
stanza to be performed.

If the providers mentioned for a stanza aren't available, the test is
skipped.
If this line isn't used in a stanza, the algorithm is assumed to be
available unconditionally (either by fallback providers, or providers
loaded by the config file).

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9398)

test/evp_test.c
test/recipes/30-test_evp_data/evpdigest.txt

index 7e282031a1e1597cabbf1ade74b6eb3f1de6b7d1..5f2bcc623a40b0fd889729be7afc13d487736312 100644 (file)
@@ -75,9 +75,6 @@ static int find_key(EVP_PKEY **ppk, const char *name, KEY_LIST *lst);
 
 static int parse_bin(const char *value, unsigned char **buf, size_t *buflen);
 
-static OSSL_PROVIDER *defltprov = NULL;
-static OSSL_PROVIDER *legacyprov = NULL;
-
 /*
  * Compare two memory regions for equality, returning zero if they differ.
  * However, if there is expected to be an error and the actual error
@@ -373,11 +370,6 @@ 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, "Legacy") == 0) {
-        if (legacyprov == NULL)
-            t->skip = 1;
-        return 1;
-    }
     return 0;
 }
 
@@ -2899,6 +2891,33 @@ static char *take_value(PAIR *pp)
     return p;
 }
 
+/*
+ * Return 1 if one of the providers named in the string is available.
+ * The provider names are separated with whitespace.
+ * NOTE: destructive function, it inserts '\0' after each provider name.
+ */
+static int prov_available(char *providers)
+{
+    char *p;
+    int more = 1;
+
+    while (more) {
+        for (; isspace(*providers); providers++)
+            continue;
+        if (*providers == '\0')
+            break;               /* End of the road */
+        for (p = providers; *p != '\0' && !isspace(*p); p++)
+            continue;
+        if (*p == '\0')
+            more = 0;
+        else
+            *p = '\0';
+        if (OSSL_PROVIDER_available(NULL, providers))
+            return 1;            /* Found one */
+    }
+    return 0;
+}
+
 /*
  * Read and parse one test.  Return 0 if failure, 1 if okay.
  */
@@ -3029,6 +3048,14 @@ top:
     }
 
     for (pp++, i = 1; i < t->s.numpairs; pp++, i++) {
+        if (strcmp(pp->key, "Availablein") == 0) {
+            if (!prov_available(pp->value)) {
+                TEST_info("skipping, providers not available: %s:%d",
+                          t->s.test_file, t->s.start);
+                t->skip = 1;
+                return 0;
+            }
+        }
         if (strcmp(pp->key, "Result") == 0) {
             if (t->expected_err != NULL) {
                 TEST_info("Line %d: multiple result lines", t->s.curr);
@@ -3106,23 +3133,6 @@ int setup_tests(void)
     if (n == 0)
         return 0;
 
-    defltprov = OSSL_PROVIDER_load(NULL, "default");
-    if (!TEST_ptr(defltprov))
-        return 0;
-#ifndef NO_LEGACY_MODULE
-    legacyprov = OSSL_PROVIDER_load(NULL, "legacy");
-    if (!TEST_ptr(legacyprov)) {
-        OSSL_PROVIDER_unload(defltprov);
-        return 0;
-    }
-#endif /* NO_LEGACY_MODULE */
-
     ADD_ALL_TESTS(run_file_tests, n);
     return 1;
 }
-
-void cleanup_tests(void)
-{
-    OSSL_PROVIDER_unload(legacyprov);
-    OSSL_PROVIDER_unload(defltprov);
-}
index e32c5dd6ab3cdef44711aa8bb3fcca54b6c3a4a1..45f79ed9bd94176d53e95a2b4df00e7835f1b9c2 100644 (file)
@@ -274,129 +274,129 @@ Output = 8215ef0796a20bcaaae116d3876c664a84983e441c3bd26ebaae4aa1f95129e5e54670f
 Title = MD4 tests
 
 Digest = MD4
+Availablein = legacy
 Input = ""
 Output = 31d6cfe0d16ae931b73c59d7e0c089c0
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "a"
 Output = bde52cb31de33e46245e05fbdbd6fb24
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "abc"
 Output = a448017aaf21d8525fc10ae87aa6729d
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "message digest"
 Output = d9130a8164549fe818874806e1c7014b
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "abcdefghijklmnopqrstuvwxyz"
 Output = d79e1c308aa5bbcdeea8ed63df412da9
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 Output = 043f8582f241db351ce627e153e7f0e4
-Legacy = 1
 
 Digest = MD4
+Availablein = legacy
 Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
 Output = e33b4ddc9c38f2199c3e7b164fcc0536
-Legacy = 1
 
 Title = RIPEMD160 tests
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = ""
 Output = 9c1185a5c5e9fc54612808977ee8f548b2258d31
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "a"
 Output = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "abc"
 Output = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "message digest"
 Output = 5d0689ef49d2fae572b881b123a85ffa21595f36
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "abcdefghijklmnopqrstuvwxyz"
 Output = f71c27109c692c1b56bbdceb5b9d2865b3708dbc
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
 Output = 12a053384a9c0c88e405a06c27dcf49ada62eb2b
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 Output = b0e20b6e3116640286ed3a87a5713079b21f5189
-Legacy = 1
 
 Digest = RIPEMD160
+Availablein = legacy
 Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
 Output = 9b752e45573d4b39f4dbd3323cab82bf63326bfb
-Legacy = 1
 
 Title = Whirlpool (from ISO/IEC 10118-3 test vector set)
 
 Digest = whirlpool
+Availablein = legacy
 Input = ""
 Output = 19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A73E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "a"
 Output = 8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "abc"
 Output = 4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "message digest"
 Output = 378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "abcdefghijklmnopqrstuvwxyz"
 Output = F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 Output = DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
 Output = 466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB6014294D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "abcdbcdecdefdefgefghfghighijhijk"
 Output = 2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C6916BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD
-Legacy = 1
 
 Digest = whirlpool
+Availablein = legacy
 Input = "aaaaaaaaaa"
 Count = 100000
 Output = 0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF51FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01
-Legacy = 1
 
 Title = SHA3