diff options
author | Richard Levitte <levitte@openssl.org> | 2020-09-11 08:35:26 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-09-12 20:24:52 +0200 |
commit | 655f73cecf411737cef9debdfa4c0b8b041656df (patch) | |
tree | e9a5a437df885cf57f97be8c70f8e5bac3c1c8a3 /crypto/evp | |
parent | 96bb4ff9b8473d01d9ac9301ec0f796898c8f459 (diff) |
EVP: Add the internal convenience function evp_keymgmt_util_export()
This is purely to allow exporting without having to repeatedly specify
the keymgmt and keydata from the EVP_PKEY.
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12853)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/keymgmt_lib.c | 16 | ||||
-rw-r--r-- | crypto/evp/p_lib.c | 16 |
2 files changed, 19 insertions, 13 deletions
diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c index 5ef4115f47..763982e58f 100644 --- a/crypto/evp/keymgmt_lib.c +++ b/crypto/evp/keymgmt_lib.c @@ -77,6 +77,13 @@ EVP_PKEY *evp_keymgmt_util_make_pkey(EVP_KEYMGMT *keymgmt, void *keydata) return pkey; } +int evp_keymgmt_util_export(const EVP_PKEY *pk, int selection, + OSSL_CALLBACK *export_cb, void *export_cbarg) +{ + return evp_keymgmt_export(pk->keymgmt, pk->keydata, selection, + export_cb, export_cbarg); +} + void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt) { struct evp_keymgmt_util_try_import_data_st import_data; @@ -139,8 +146,8 @@ void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt) * The export function calls the callback (evp_keymgmt_util_try_import), * which does the import for us. If successful, we're done. */ - if (!evp_keymgmt_export(pk->keymgmt, pk->keydata, OSSL_KEYMGMT_SELECT_ALL, - &evp_keymgmt_util_try_import, &import_data)) { + if (!evp_keymgmt_util_export(pk, OSSL_KEYMGMT_SELECT_ALL, + &evp_keymgmt_util_try_import, &import_data)) { /* If there was an error, bail out */ evp_keymgmt_freedata(keymgmt, import_data.keydata); return NULL; @@ -392,8 +399,9 @@ int evp_keymgmt_util_copy(EVP_PKEY *to, EVP_PKEY *from, int selection) import_data.keydata = to_keydata; import_data.selection = selection; - if (!evp_keymgmt_export(from->keymgmt, from->keydata, selection, - &evp_keymgmt_util_try_import, &import_data)) { + if (!evp_keymgmt_util_export(from, selection, + &evp_keymgmt_util_try_import, + &import_data)) { evp_keymgmt_freedata(to_keymgmt, alloc_keydata); return 0; } diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 0f5378c4fe..cb72048f86 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -527,9 +527,8 @@ int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, raw_key.len = len; raw_key.selection = OSSL_KEYMGMT_SELECT_PRIVATE_KEY; - return evp_keymgmt_export(pkey->keymgmt, pkey->keydata, - OSSL_KEYMGMT_SELECT_PRIVATE_KEY, - get_raw_key_details, &raw_key); + return evp_keymgmt_util_export(pkey, OSSL_KEYMGMT_SELECT_PRIVATE_KEY, + get_raw_key_details, &raw_key); } if (pkey->ameth == NULL) { @@ -560,9 +559,8 @@ int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, raw_key.len = len; raw_key.selection = OSSL_KEYMGMT_SELECT_PUBLIC_KEY; - return evp_keymgmt_export(pkey->keymgmt, pkey->keydata, - OSSL_KEYMGMT_SELECT_PUBLIC_KEY, - get_raw_key_details, &raw_key); + return evp_keymgmt_util_export(pkey, OSSL_KEYMGMT_SELECT_PUBLIC_KEY, + get_raw_key_details, &raw_key); } if (pkey->ameth == NULL) { @@ -1115,9 +1113,9 @@ int evp_pkey_get_EC_KEY_curve_nid(const EVP_PKEY *pkey) } else if (EVP_PKEY_is_a(pkey, "EC") || EVP_PKEY_is_a(pkey, "SM2")) { char *curve_name = NULL; - ret = evp_keymgmt_export(pkey->keymgmt, pkey->keydata, - OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, - get_ec_curve_name_cb, &curve_name); + ret = evp_keymgmt_util_export(pkey, + OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS, + get_ec_curve_name_cb, &curve_name); if (ret) ret = ec_curve_name2nid(curve_name); OPENSSL_free(curve_name); |