From 820723dde0c9ec9a4fc68406a0e5aee1dc83f836 Mon Sep 17 00:00:00 2001 From: slontis Date: Mon, 30 May 2022 14:32:36 +1000 Subject: Add d2i_PUBKEY_ex_fp and d2i_PUBKEY_ex_bio. These functions pass a library content and prop query. The i2d documentation related to these functions has been corrected since the bio and fp functions always return 0 or 1. Reviewed-by: Hugo Landau Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18427) --- test/build.info | 2 +- test/evp_extra_test2.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/build.info b/test/build.info index 419b5fb12c..fd7fa953fd 100644 --- a/test/build.info +++ b/test/build.info @@ -184,7 +184,7 @@ IF[{- !$disabled{tests} -}] INCLUDE[evp_extra_test]=../include ../apps/include DEPEND[evp_extra_test]=../libcrypto.a libtestutil.a - SOURCE[evp_extra_test2]=evp_extra_test2.c + SOURCE[evp_extra_test2]=evp_extra_test2.c $INITSRC INCLUDE[evp_extra_test2]=../include ../apps/include DEPEND[evp_extra_test2]=../libcrypto libtestutil.a diff --git a/test/evp_extra_test2.c b/test/evp_extra_test2.c index fc73994ca3..b03b6bd234 100644 --- a/test/evp_extra_test2.c +++ b/test/evp_extra_test2.c @@ -359,6 +359,35 @@ static int test_dh_tofrom_data_select(void) #endif #ifndef OPENSSL_NO_EC + +static int test_ec_d2i_i2d_pubkey(void) +{ + int ret = 0; + FILE *fp = NULL; + EVP_PKEY *key = NULL, *outkey = NULL; + static const char *filename = "pubkey.der"; + + if (!TEST_ptr(fp = fopen(filename, "wb")) + || !TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "EC", "P-256")) + || !TEST_true(i2d_PUBKEY_fp(fp, key)) + || !TEST_int_eq(fclose(fp), 0)) + goto err; + fp = NULL; + + if (!TEST_ptr(fp = fopen(filename, "rb")) + || !TEST_ptr(outkey = d2i_PUBKEY_ex_fp(fp, NULL, mainctx, NULL)) + || !TEST_int_eq(EVP_PKEY_eq(key, outkey), 1)) + goto err; + + ret = 1; + +err: + EVP_PKEY_free(outkey); + EVP_PKEY_free(key); + fclose(fp); + return ret; +} + static int test_ec_tofrom_data_select(void) { int ret; @@ -1117,6 +1146,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 2); ADD_TEST(test_ec_tofrom_data_select); ADD_TEST(test_ecx_tofrom_data_select); + ADD_TEST(test_ec_d2i_i2d_pubkey); #else ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 1); #endif -- cgit v1.2.3