diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-01-04 11:57:54 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-01-07 09:51:48 +0100 |
commit | 277a8334cd4a213619fe92107dd393eab6d8a801 (patch) | |
tree | 0708019636a45b161f9bfada615bfcd40cefbcce | |
parent | 86914ceadf2909204485605106cc121036ab091d (diff) |
Test importing EC key parameters with a bad curve
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17411)
(cherry picked from commit d4d8f163db1d32c98d8f956e6966263a7a22fac1)
-rw-r--r-- | test/evp_pkey_provided_test.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c index 8b5c7b3457..cf4d8e1294 100644 --- a/test/evp_pkey_provided_test.c +++ b/test/evp_pkey_provided_test.c @@ -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)) |