Add testcases for EVP_PKEY_get1_encoded_public_key
authorTomas Mraz <tomas@openssl.org>
Thu, 28 Jul 2022 12:13:06 +0000 (14:13 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 18 Aug 2022 08:22:02 +0000 (10:22 +0200)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18902)

(cherry picked from commit 3a1596f4e3d710c163279a20e6b844d371886e73)

test/evp_extra_test.c

index 49ee8319c632c8aa36ae868745981396e9775b95..12dc0e36288dab4ae8ac20a7b1d5c0d8445972e0 100644 (file)
@@ -897,6 +897,7 @@ static int test_EC_priv_pub(void)
     EVP_PKEY *params_and_keypair = NULL;
     BIGNUM *priv = NULL;
     int ret = 0;
+    unsigned char *encoded = NULL;
 
     /*
      * Setup the parameters for our pkey object. For our purposes they don't
@@ -1005,6 +1006,17 @@ static int test_EC_priv_pub(void)
         || !TEST_int_gt(EVP_PKEY_eq(params_and_keypair, params_and_priv), 0))
         goto err;
 
+    /* Positive and negative testcase for EVP_PKEY_get1_encoded_public_key */
+    if (!TEST_int_gt(EVP_PKEY_get1_encoded_public_key(params_and_pub, &encoded), 0))
+        goto err;
+    OPENSSL_free(encoded);
+    encoded = NULL;
+    if (!TEST_int_eq(EVP_PKEY_get1_encoded_public_key(just_params, &encoded), 0)) {
+        OPENSSL_free(encoded);
+        encoded = NULL;
+        goto err;
+    }
+
     ret = 1;
  err:
     OSSL_PARAM_free(params);