summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-11-18 20:09:57 +0100
committerTomas Mraz <tomas@openssl.org>2021-11-22 10:51:19 +0100
commitf89b54460053404d85b9a91a8b6a2b30e254bdf8 (patch)
treed79f4ed96b70094bc2f99bda862febcb10aea8d1 /test
parent3239bedea9d2767e20a420c84156e18b71b017ea (diff)
d2i_PublicKey: Make it work with EC parameters in a provided key
Fixes #16989 Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17065) (cherry picked from commit 615a9b8798e6ec58f1b2e1ec08a0f6b3c8cb7f60)
Diffstat (limited to 'test')
-rw-r--r--test/ectest.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ectest.c b/test/ectest.c
index 84e515d808..38772ba16f 100644
--- a/test/ectest.c
+++ b/test/ectest.c
@@ -2966,6 +2966,47 @@ static int custom_params_test(int id)
return ret;
}
+static int ec_d2i_publickey_test(void)
+{
+ unsigned char buf[1000];
+ unsigned char *pubkey_enc = buf;
+ const unsigned char *pk_enc = pubkey_enc;
+ EVP_PKEY *gen_key = NULL, *decoded_key = NULL;
+ EVP_PKEY_CTX *pctx = NULL;
+ int pklen, ret = 0;
+ OSSL_PARAM params[2];
+
+ if (!TEST_ptr(gen_key = EVP_EC_gen("P-256")))
+ goto err;
+
+ if (!TEST_int_gt(pklen = i2d_PublicKey(gen_key, &pubkey_enc), 0))
+ goto err;
+
+ params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME,
+ "P-256", 0);
+ params[1] = OSSL_PARAM_construct_end();
+
+ if (!TEST_ptr(pctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL))
+ || !TEST_true(EVP_PKEY_fromdata_init(pctx))
+ || !TEST_true(EVP_PKEY_fromdata(pctx, &decoded_key,
+ OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
+ params))
+ || !TEST_ptr(decoded_key)
+ || !TEST_ptr(decoded_key = d2i_PublicKey(EVP_PKEY_EC, &decoded_key,
+ &pk_enc, pklen)))
+ goto err;
+
+ if (!TEST_true(EVP_PKEY_eq(gen_key, decoded_key)))
+ goto err;
+ ret = 1;
+
+ err:
+ EVP_PKEY_CTX_free(pctx);
+ EVP_PKEY_free(gen_key);
+ EVP_PKEY_free(decoded_key);
+ return ret;
+}
+
int setup_tests(void)
{
crv_len = EC_get_builtin_curves(NULL, 0);
@@ -2993,6 +3034,7 @@ int setup_tests(void)
ADD_ALL_TESTS(ec_point_hex2point_test, crv_len);
ADD_ALL_TESTS(custom_generator_test, crv_len);
ADD_ALL_TESTS(custom_params_test, crv_len);
+ ADD_TEST(ec_d2i_publickey_test);
return 1;
}