Test importing EC key parameters with a bad curve
authorTomas Mraz <tomas@openssl.org>
Tue, 4 Jan 2022 10:57:54 +0000 (11:57 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 7 Jan 2022 08:51:48 +0000 (09:51 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17411)

(cherry picked from commit d4d8f163db1d32c98d8f956e6966263a7a22fac1)

test/evp_pkey_provided_test.c

index 8b5c7b34577d5182e5449646c0bb5b4c722ca2a7..cf4d8e1294a29090cec1cc366fed408ecca4c888 100644 (file)
@@ -1113,8 +1113,6 @@ err:
     return ret;
 }
 
-#define CURVE_NAME 2
-
 static int test_fromdata_ec(void)
 {
     int ret = 0;
@@ -1126,6 +1124,11 @@ static int test_fromdata_ec(void)
     OSSL_PARAM *fromdata_params = NULL;
     const char *alg = "EC";
     const char *curve = "prime256v1";
+    const char bad_curve[] = "nonexistent-curve";
+    OSSL_PARAM nokey_params[2] = {
+       OSSL_PARAM_END,
+       OSSL_PARAM_END
+    };
     /* UNCOMPRESSED FORMAT */
     static const unsigned char ec_pub_keydata[] = {
        POINT_CONVERSION_UNCOMPRESSED,
@@ -1179,6 +1182,16 @@ static int test_fromdata_ec(void)
     if (!TEST_ptr(ctx))
         goto err;
 
+    /* try importing parameters with bad curve first */
+    nokey_params[0] =
+        OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME,
+                                         (char *)bad_curve, sizeof(bad_curve));
+    if (!TEST_int_eq(EVP_PKEY_fromdata_init(ctx), 1)
+        || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEY_PARAMETERS,
+                                          nokey_params), 0)
+        || !TEST_ptr_null(pk))
+        goto err;
+
     if (!TEST_int_eq(EVP_PKEY_fromdata_init(ctx), 1)
         || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
                                           fromdata_params), 1))