diff options
author | Richard Levitte <levitte@openssl.org> | 2020-03-21 06:26:41 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-03-25 17:01:31 +0100 |
commit | ff7262b4f4dfade7d2d6e05dcd3727ecc2bc7a5c (patch) | |
tree | ae9cc9e2880c891d7aa03221493db0a8e9fd44d7 /test/evp_pkey_provided_test.c | |
parent | acb90ba8ffe6a27f625607760e82842673eb9378 (diff) |
test/evp_pkey_provided_test.c: Add test of EVP_PKEY_copy_parameters()
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11375)
Diffstat (limited to 'test/evp_pkey_provided_test.c')
-rw-r--r-- | test/evp_pkey_provided_test.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c index d0a87b08d3..589261a060 100644 --- a/test/evp_pkey_provided_test.c +++ b/test/evp_pkey_provided_test.c @@ -262,7 +262,7 @@ static int test_fromdata_rsa(void) { int ret = 0; EVP_PKEY_CTX *ctx = NULL, *key_ctx = NULL; - EVP_PKEY *pk = NULL; + EVP_PKEY *pk = NULL, *copy_pk = NULL; /* * 32-bit RSA key, extracted from this command, * executed with OpenSSL 1.0.2: @@ -310,11 +310,17 @@ static int test_fromdata_rsa(void) || !TEST_true(EVP_PKEY_pairwise_check(key_ctx))) goto err; + /* EVP_PKEY_copy_parameters() should fail for RSA */ + if (!TEST_ptr(copy_pk = EVP_PKEY_new()) + || !TEST_false(EVP_PKEY_copy_parameters(copy_pk, pk))) + goto err; + ret = test_print_key_using_pem("RSA", pk) && test_print_key_using_serializer("RSA", pk); err: EVP_PKEY_free(pk); + EVP_PKEY_free(copy_pk); EVP_PKEY_CTX_free(key_ctx); EVP_PKEY_CTX_free(ctx); @@ -332,7 +338,7 @@ static int test_fromdata_dh(void) { int ret = 0; EVP_PKEY_CTX *ctx = NULL, *key_ctx = NULL; - EVP_PKEY *pk = NULL; + EVP_PKEY *pk = NULL, *copy_pk = NULL; /* * 32-bit DH key, extracted from this command, * executed with OpenSSL 1.0.2: @@ -364,6 +370,10 @@ static int test_fromdata_dh(void) || !TEST_int_eq(EVP_PKEY_size(pk), 4)) goto err; + if (!TEST_ptr(copy_pk = EVP_PKEY_new()) + || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk))) + goto err; + ret = test_print_key_using_pem("DH", pk) && test_print_key_using_serializer("DH", pk); @@ -378,6 +388,7 @@ static int test_fromdata_dh(void) err: EVP_PKEY_free(pk); + EVP_PKEY_free(copy_pk); EVP_PKEY_CTX_free(ctx); EVP_PKEY_CTX_free(key_ctx); @@ -399,7 +410,7 @@ static int test_fromdata_ecx(int tst) { int ret = 0; EVP_PKEY_CTX *ctx = NULL; - EVP_PKEY *pk = NULL; + EVP_PKEY *pk = NULL, *copy_pk = NULL; const char *alg = NULL; /* ED448_KEYLEN > X448_KEYLEN > X25519_KEYLEN == ED25519_KEYLEN */ @@ -565,11 +576,16 @@ static int test_fromdata_ecx(int tst) || !TEST_int_eq(EVP_PKEY_size(pk), size)) goto err; + if (!TEST_ptr(copy_pk = EVP_PKEY_new()) + || !TEST_false(EVP_PKEY_copy_parameters(copy_pk, pk))) + goto err; + ret = test_print_key_using_pem(alg, pk) && test_print_key_using_serializer(alg, pk); err: EVP_PKEY_free(pk); + EVP_PKEY_free(copy_pk); EVP_PKEY_CTX_free(ctx); return ret; @@ -579,7 +595,7 @@ static int test_fromdata_ec(void) { int ret = 0; EVP_PKEY_CTX *ctx = NULL; - EVP_PKEY *pk = NULL; + EVP_PKEY *pk = NULL, *copy_pk = NULL; OSSL_PARAM_BLD bld; BIGNUM *ec_priv_bn = NULL; OSSL_PARAM *fromdata_params = NULL; @@ -630,12 +646,17 @@ static int test_fromdata_ec(void) || !TEST_int_eq(EVP_PKEY_size(pk), 2 + 35 * 2)) goto err; + if (!TEST_ptr(copy_pk = EVP_PKEY_new()) + || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk))) + goto err; + ret = test_print_key_using_pem(alg, pk) && test_print_key_using_serializer(alg, pk); err: BN_free(ec_priv_bn); ossl_param_bld_free(fromdata_params); EVP_PKEY_free(pk); + EVP_PKEY_free(copy_pk); EVP_PKEY_CTX_free(ctx); return ret; } |