]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
provider: return error if buf too small when getting ec pubkey param
authorYi Li <yi1.li@intel.com>
Fri, 5 May 2023 03:30:05 +0000 (11:30 +0800)
committerTomas Mraz <tomas@openssl.org>
Fri, 12 May 2023 08:32:06 +0000 (10:32 +0200)
Fixes #20889

There was an incorrect value passed to EC_POINT_point2oct() for the
buffer size of the param passed-in.

Added testcases.

Signed-off-by: Yi Li <yi1.li@intel.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20890)

providers/implementations/keymgmt/ec_kmgmt.c
test/evp_extra_test.c

index e79a50df42902d748885d51e60fedf36d233dc32..d9c585cd3b4ed3b6163c9739163a68038e1bf8d9 100644 (file)
@@ -745,7 +745,7 @@ int common_get_params(void *key, OSSL_PARAM params[], int sm2)
         }
         p->return_size = EC_POINT_point2oct(ecg, ecp,
                                             POINT_CONVERSION_UNCOMPRESSED,
-                                            p->data, p->return_size, bnctx);
+                                            p->data, p->data_size, bnctx);
         if (p->return_size == 0)
             goto err;
     }
index 1141d52666588a2d6785f7887fa3238ae8f10091..72a6305d89addaa1e915fa3e89938bcdb2be8460 100644 (file)
@@ -900,6 +900,8 @@ static int test_EC_priv_pub(void)
     BIGNUM *priv = NULL;
     int ret = 0;
     unsigned char *encoded = NULL;
+    size_t len = 0;
+    unsigned char buffer[128];
 
     /*
      * Setup the parameters for our pkey object. For our purposes they don't
@@ -1019,6 +1021,26 @@ static int test_EC_priv_pub(void)
         goto err;
     }
 
+    /* Positive and negative testcase for EVP_PKEY_get_octet_string_param */
+    if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
+                                                     OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
+                                                     buffer, sizeof(buffer), &len), 1)
+        || !TEST_int_eq(len, 65))
+        goto err;
+
+    len = 0;
+    if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
+                                                     OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
+                                                     NULL, 0, &len), 1)
+        || !TEST_int_eq(len, 65))
+        goto err;
+
+    /* too-short buffer len*/
+    if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
+                                                     OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
+                                                     buffer, 10, &len), 0))
+        goto err;
+
     ret = 1;
  err:
     OSSL_PARAM_free(params);