summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorBenjamin Kaduk <bkaduk@akamai.com>2021-01-25 12:19:16 -0800
committerRichard Levitte <levitte@openssl.org>2021-02-27 16:14:09 +0100
commitc0ff1932e446621f43cd607371b7d265370d4bc6 (patch)
tree120b8b6b83f72dda60d18c8f7e0f1eb4ab5d7b4b /test
parent4ef70dbcf495adfa28efa815c5415dfb9903b92d (diff)
Add test for EC pubkey export/import
There seems to be an issue with i2d_provided() in i2d_evp.c that causes us to fail to construct a valid chain of encoders for the "type-specific" output when it's an EC pubkey. This test is designed to exercise that codepath for a variety of curves. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14291)
Diffstat (limited to 'test')
-rw-r--r--test/evp_extra_test.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 845752fae4..487767f651 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -2415,6 +2415,47 @@ err:
return ret;
}
+#ifndef OPENSSL_NO_EC
+static int ecpub_nids[] = { NID_brainpoolP256r1, NID_X9_62_prime256v1,
+ NID_secp384r1, NID_secp521r1, NID_sect233k1, NID_sect233r1, NID_sect283r1,
+ NID_sect409k1, NID_sect409r1, NID_sect571k1, NID_sect571r1,
+ NID_brainpoolP384r1, NID_brainpoolP512r1};
+
+static int test_ecpub(int idx)
+{
+ int ret = 0, len;
+ int nid;
+ unsigned char buf[1024];
+ unsigned char *p;
+ EVP_PKEY *pkey = NULL;
+ EVP_PKEY_CTX *ctx = NULL;
+
+ nid = ecpub_nids[idx];
+
+ ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
+ if (!TEST_ptr(ctx)
+ || !TEST_true(EVP_PKEY_keygen_init(ctx))
+ || !TEST_true(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid))
+ || !TEST_true(EVP_PKEY_keygen(ctx, &pkey)))
+ goto done;
+ len = i2d_PublicKey(pkey, NULL);
+ if (!TEST_int_ge(len, 1)
+ || !TEST_int_lt(len, 1024))
+ goto done;
+ p = buf;
+ len = i2d_PublicKey(pkey, &p);
+ if (!TEST_int_ge(len, 1))
+ goto done;
+
+ ret = 1;
+
+ done:
+ EVP_PKEY_CTX_free(ctx);
+ EVP_PKEY_free(pkey);
+ return ret;
+}
+#endif
+
static int test_EVP_rsa_pss_with_keygen_bits(void)
{
int ret;
@@ -2556,6 +2597,9 @@ int setup_tests(void)
ADD_TEST(test_rand_agglomeration);
ADD_ALL_TESTS(test_evp_iv, 10);
ADD_TEST(test_EVP_rsa_pss_with_keygen_bits);
+#ifndef OPENSSL_NO_EC
+ ADD_ALL_TESTS(test_ecpub, OSSL_NELEM(ecpub_nids));
+#endif
ADD_TEST(test_names_do_all);