From 6ed4022cd1e4b066ddc6131ca659d8a260944a76 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 18 Dec 2020 13:17:33 +0100 Subject: Fix 'no-deprecated' Some of the handling of no-deprecated stuff wasn't quite complete, or even plain wrong. This restores i2d_PublicKey() to be able to handle EVP_PKEYs with legacy internal keys. This also refactors the DSA key tests in test/evp_extra_test.c to use EVP functionality entirely. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/13706) --- test/evp_extra_test.c | 69 ++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'test') diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index c1aaf67c85..67e5a48c3e 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -435,26 +435,8 @@ static EVP_PKEY *load_example_rsa_key(void) #ifndef OPENSSL_NO_DSA static EVP_PKEY *load_example_dsa_key(void) { - EVP_PKEY *ret = NULL; - const unsigned char *derp = kExampleDSAKeyDER; - EVP_PKEY *pkey = NULL; - DSA *dsa = NULL; - - if (!TEST_true(d2i_DSAPrivateKey(&dsa, &derp, sizeof(kExampleDSAKeyDER)))) - return NULL; - - if (!TEST_ptr(pkey = EVP_PKEY_new()) - || !TEST_true(EVP_PKEY_set1_DSA(pkey, dsa))) - goto end; - - ret = pkey; - pkey = NULL; - -end: - EVP_PKEY_free(pkey); - DSA_free(dsa); - - return ret; + return load_example_key("DSA", kExampleDSAKeyDER, + sizeof(kExampleDSAKeyDER)); } #endif @@ -1684,8 +1666,10 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) #ifndef OPENSSL_NO_DSA static int test_DSA_get_set_params(void) { - DSA *dsa = NULL; + OSSL_PARAM_BLD *bld = NULL; + OSSL_PARAM *params = NULL; BIGNUM *p = NULL, *q = NULL, *g = NULL, *pub = NULL, *priv = NULL; + EVP_PKEY_CTX *pctx = NULL; EVP_PKEY *pkey = NULL; int ret = 0; @@ -1693,34 +1677,39 @@ static int test_DSA_get_set_params(void) * Setup the parameters for our DSA object. For our purposes they don't * have to actually be *valid* parameters. We just need to set something. */ - dsa = DSA_new(); - p = BN_new(); - q = BN_new(); - g = BN_new(); - pub = BN_new(); - priv = BN_new(); - if (!TEST_ptr(dsa) - || !TEST_ptr(p) - || !TEST_ptr(q) - || !TEST_ptr(g) - || !TEST_ptr(pub) - || !DSA_set0_pqg(dsa, p, q, g) - || !DSA_set0_key(dsa, pub, priv)) + if (!TEST_ptr(pctx = EVP_PKEY_CTX_new_from_name(testctx, "DSA", NULL)) + || !TEST_ptr(bld = OSSL_PARAM_BLD_new()) + || !TEST_ptr(p = BN_new()) + || !TEST_ptr(q = BN_new()) + || !TEST_ptr(g = BN_new()) + || !TEST_ptr(pub = BN_new()) + || !TEST_ptr(priv = BN_new())) + goto err; + if (!TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_P, p)) + || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q)) + || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g)) + || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PUB_KEY, + pub)) + || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, + priv))) + goto err; + if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld))) goto err; - p = q = g = pub = priv = NULL; - pkey = EVP_PKEY_new(); - if (!TEST_ptr(pkey) - || !TEST_true(EVP_PKEY_assign_DSA(pkey, dsa))) + if (!TEST_int_gt(EVP_PKEY_key_fromdata_init(pctx), 0) + || !TEST_int_gt(EVP_PKEY_fromdata(pctx, &pkey, params), 0)) goto err; - dsa = NULL; + if (!TEST_ptr(pkey)) + goto err; ret = test_EVP_PKEY_CTX_get_set_params(pkey); err: EVP_PKEY_free(pkey); - DSA_free(dsa); + EVP_PKEY_CTX_free(pctx); + OSSL_PARAM_BLD_free_params(params); + OSSL_PARAM_BLD_free(bld); BN_free(p); BN_free(q); BN_free(g); -- cgit v1.2.3