diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-03-19 18:45:43 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-03-28 16:38:57 +1000 |
commit | 2145ba5e8383184d7f212500ec2f759bdf08503a (patch) | |
tree | a862106cc508e75f170b3105e3b5919fb38219d3 /test/keymgmt_internal_test.c | |
parent | c464583483df70ad8df9907168bf015d672742bd (diff) | |
download | openssl-2145ba5e8383184d7f212500ec2f759bdf08503a.zip openssl-2145ba5e8383184d7f212500ec2f759bdf08503a.tar.gz openssl-2145ba5e8383184d7f212500ec2f759bdf08503a.tar.bz2 |
Implement EVP_PKEY_dup() function
Fixes #14501
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14624)
Diffstat (limited to 'test/keymgmt_internal_test.c')
-rw-r--r-- | test/keymgmt_internal_test.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/test/keymgmt_internal_test.c b/test/keymgmt_internal_test.c index e309c9e..32e82d5 100644 --- a/test/keymgmt_internal_test.c +++ b/test/keymgmt_internal_test.c @@ -141,7 +141,7 @@ static int test_pass_rsa(FIXTURE *fixture) int ret = 0; RSA *rsa = NULL; BIGNUM *bn1 = NULL, *bn2 = NULL, *bn3 = NULL; - EVP_PKEY *pk = NULL; + EVP_PKEY *pk = NULL, *dup_pk = NULL; EVP_KEYMGMT *km = NULL, *km1 = NULL, *km2 = NULL, *km3 = NULL; void *provkey = NULL, *provkey2 = NULL; BIGNUM *bn_primes[1] = { NULL }; @@ -220,34 +220,47 @@ static int test_pass_rsa(FIXTURE *fixture) || !TEST_ptr_ne(km1, km2)) goto err; - km = km3; - /* Check that we can't export an RSA key into a RSA-PSS keymanager */ - if (!TEST_ptr_null(provkey2 = evp_pkey_export_to_provider(pk, NULL, &km, - NULL))) - goto err; - - if (!TEST_ptr(provkey = evp_pkey_export_to_provider(pk, NULL, &km1, NULL)) - || !TEST_true(evp_keymgmt_export(km2, provkey, - OSSL_KEYMGMT_SELECT_KEYPAIR, - &export_cb, keydata))) - goto err; - - /* - * At this point, the hope is that keydata will have all the numbers - * from the key. - */ - - for (i = 0; i < OSSL_NELEM(expected); i++) { - int rv = TEST_int_eq(expected[i], keydata[i]); - - if (!rv) - TEST_info("i = %zu", i); - else - ret++; + while (dup_pk == NULL) { + ret = 0; + km = km3; + /* Check that we can't export an RSA key into a RSA-PSS keymanager */ + if (!TEST_ptr_null(provkey2 = evp_pkey_export_to_provider(pk, NULL, + &km, + NULL))) + goto err; + + if (!TEST_ptr(provkey = evp_pkey_export_to_provider(pk, NULL, &km1, + NULL)) + || !TEST_true(evp_keymgmt_export(km2, provkey, + OSSL_KEYMGMT_SELECT_KEYPAIR, + &export_cb, keydata))) + goto err; + + /* + * At this point, the hope is that keydata will have all the numbers + * from the key. + */ + + for (i = 0; i < OSSL_NELEM(expected); i++) { + int rv = TEST_int_eq(expected[i], keydata[i]); + + if (!rv) + TEST_info("i = %zu", i); + else + ret++; + } + + ret = (ret == OSSL_NELEM(expected)); + if (!ret || !TEST_ptr(dup_pk = EVP_PKEY_dup(pk))) + goto err; + + ret = TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1); + EVP_PKEY_free(pk); + pk = dup_pk; + if (!ret) + goto err; } - ret = (ret == OSSL_NELEM(expected)); - err: RSA_free(rsa); BN_free(bn1); |