diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2019-04-11 20:27:59 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2019-06-04 12:09:50 +1000 |
commit | d5e5e2ffafc7dbc861f7d285508cf129c5e8f5ac (patch) | |
tree | 3920b0febd6d2716940fb022b57894fe2ebf565d /test | |
parent | bf5b04ea25d6ac7d31e388b4e87d3eb5cd1e1e2b (diff) |
Move digests to providers
Move digest code into the relevant providers (fips, default, legacy).
The headers are temporarily moved to be internal, and will be moved
into providers after all external references are resolved. The deprecated
digest code can not be removed until EVP_PKEY (signing) is supported by
providers. EVP_MD data can also not yet be cleaned up for the same reasons.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8763)
Diffstat (limited to 'test')
-rw-r--r-- | test/build.info | 3 | ||||
-rw-r--r-- | test/evp_test.c | 28 | ||||
-rw-r--r-- | test/mdc2test.c | 22 | ||||
-rw-r--r-- | test/recipes/05-test_mdc2.t | 18 | ||||
-rw-r--r-- | test/recipes/30-test_evp.t | 4 | ||||
-rw-r--r-- | test/recipes/30-test_evp_data/evpdigest.txt | 25 |
6 files changed, 89 insertions, 11 deletions
diff --git a/test/build.info b/test/build.info index fa3c1f1ea6..7a777d1bef 100644 --- a/test/build.info +++ b/test/build.info @@ -182,6 +182,9 @@ IF[{- !$disabled{tests} -}] SOURCE[evp_test]=evp_test.c INCLUDE[evp_test]=../include ../apps/include DEPEND[evp_test]=../libcrypto libtestutil.a + IF[{- $disabled{legacy} || !$target{dso_scheme} -}] + DEFINE[evp_test]=NO_LEGACY_MODULE + ENDIF SOURCE[evp_extra_test]=evp_extra_test.c INCLUDE[evp_extra_test]=../include ../apps/include ../crypto/include diff --git a/test/evp_test.c b/test/evp_test.c index fa9cde8289..6fc9f03797 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -14,6 +14,7 @@ #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/err.h> +#include <openssl/provider.h> #include <openssl/x509v3.h> #include <openssl/pkcs12.h> #include <openssl/kdf.h> @@ -75,6 +76,9 @@ 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 @@ -370,6 +374,11 @@ 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; } @@ -3053,8 +3062,10 @@ static int run_file_tests(int i) while (!BIO_eof(t->s.fp)) { c = parse(t); - if (t->skip) + if (t->skip) { + t->s.numskip++; continue; + } if (c == 0 || !run_test(t)) { t->s.errors++; break; @@ -3080,6 +3091,21 @@ 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)) + 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); +} diff --git a/test/mdc2test.c b/test/mdc2test.c index 79512fc7a1..418a2566de 100644 --- a/test/mdc2test.c +++ b/test/mdc2test.c @@ -8,7 +8,10 @@ */ #include <string.h> - +#include <openssl/provider.h> +#include <openssl/params.h> +#include <openssl/ossl_typ.h> +#include <openssl/core_names.h> #include "internal/nelem.h" #include "testutil.h" @@ -36,12 +39,19 @@ static unsigned char pad2[16] = { static int test_mdc2(void) { - int testresult = 0; + int testresult = 0, 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_int(OSSL_DIGEST_PARAM_PAD_TYPE, + &pad_type, NULL), + params[i++] = OSSL_PARAM_construct_end(); + prov = OSSL_PROVIDER_load(NULL, "legacy"); # ifdef CHARSET_EBCDIC ebcdic2ascii(text, text, tlen); # endif @@ -55,9 +65,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,6 +74,7 @@ static int test_mdc2(void) testresult = 1; end: EVP_MD_CTX_free(c); + OSSL_PROVIDER_unload(prov); return testresult; } #endif diff --git a/test/recipes/05-test_mdc2.t b/test/recipes/05-test_mdc2.t index eb5cd8f108..495a146e35 100644 --- a/test/recipes/05-test_mdc2.t +++ b/test/recipes/05-test_mdc2.t @@ -7,6 +7,20 @@ # https://www.openssl.org/source/license.html -use OpenSSL::Test::Simple; +use strict; +use warnings; -simple_test("test_mdc2", "mdc2test", "mdc2"); +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; + +$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); + +ok(run(test(["mdc2test"])), "running mdc2test"); diff --git a/test/recipes/30-test_evp.t b/test/recipes/30-test_evp.t index 6cc4df045a..c140f1a87e 100644 --- a/test/recipes/30-test_evp.t +++ b/test/recipes/30-test_evp.t @@ -10,7 +10,7 @@ use strict; use warnings; -use OpenSSL::Test qw/:DEFAULT data_file/; +use OpenSSL::Test qw(:DEFAULT data_file bldtop_dir); setup("test_evp"); @@ -20,6 +20,8 @@ my @files = ( "evpciph.txt", "evpdigest.txt", "evpencod.txt", "evpkdf.txt", plan tests => scalar(@files); +$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); + foreach my $f ( @files ) { ok(run(test(["evp_test", data_file("$f")])), "running evp_test $f"); diff --git a/test/recipes/30-test_evp_data/evpdigest.txt b/test/recipes/30-test_evp_data/evpdigest.txt index fe3de3cb35..e32c5dd6ab 100644 --- a/test/recipes/30-test_evp_data/evpdigest.txt +++ b/test/recipes/30-test_evp_data/evpdigest.txt @@ -276,104 +276,127 @@ Title = MD4 tests Digest = MD4 Input = "" Output = 31d6cfe0d16ae931b73c59d7e0c089c0 +Legacy = 1 Digest = MD4 Input = "a" Output = bde52cb31de33e46245e05fbdbd6fb24 +Legacy = 1 Digest = MD4 Input = "abc" Output = a448017aaf21d8525fc10ae87aa6729d +Legacy = 1 Digest = MD4 Input = "message digest" Output = d9130a8164549fe818874806e1c7014b +Legacy = 1 Digest = MD4 Input = "abcdefghijklmnopqrstuvwxyz" Output = d79e1c308aa5bbcdeea8ed63df412da9 +Legacy = 1 Digest = MD4 Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Output = 043f8582f241db351ce627e153e7f0e4 +Legacy = 1 Digest = MD4 Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890" Output = e33b4ddc9c38f2199c3e7b164fcc0536 +Legacy = 1 Title = RIPEMD160 tests Digest = RIPEMD160 Input = "" Output = 9c1185a5c5e9fc54612808977ee8f548b2258d31 +Legacy = 1 Digest = RIPEMD160 Input = "a" Output = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe +Legacy = 1 Digest = RIPEMD160 Input = "abc" Output = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc +Legacy = 1 Digest = RIPEMD160 Input = "message digest" Output = 5d0689ef49d2fae572b881b123a85ffa21595f36 +Legacy = 1 Digest = RIPEMD160 Input = "abcdefghijklmnopqrstuvwxyz" Output = f71c27109c692c1b56bbdceb5b9d2865b3708dbc +Legacy = 1 Digest = RIPEMD160 Input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" Output = 12a053384a9c0c88e405a06c27dcf49ada62eb2b +Legacy = 1 Digest = RIPEMD160 Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Output = b0e20b6e3116640286ed3a87a5713079b21f5189 +Legacy = 1 Digest = RIPEMD160 Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890" Output = 9b752e45573d4b39f4dbd3323cab82bf63326bfb +Legacy = 1 Title = Whirlpool (from ISO/IEC 10118-3 test vector set) Digest = whirlpool Input = "" Output = 19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A73E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3 +Legacy = 1 Digest = whirlpool Input = "a" Output = 8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A +Legacy = 1 Digest = whirlpool Input = "abc" Output = 4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5 +Legacy = 1 Digest = whirlpool Input = "message digest" Output = 378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E +Legacy = 1 Digest = whirlpool Input = "abcdefghijklmnopqrstuvwxyz" Output = F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B +Legacy = 1 Digest = whirlpool Input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Output = DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467 +Legacy = 1 Digest = whirlpool Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890" Output = 466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB6014294D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B +Legacy = 1 Digest = whirlpool Input = "abcdbcdecdefdefgefghfghighijhijk" Output = 2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C6916BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD +Legacy = 1 Digest = whirlpool Input = "aaaaaaaaaa" Count = 100000 Output = 0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF51FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01 - +Legacy = 1 Title = SHA3 |