From a732a4c329144f0b4c60372d9b7106c6b88ddd9f Mon Sep 17 00:00:00 2001 From: Shane Lontis Date: Thu, 8 Apr 2021 20:05:14 +1000 Subject: Add EVP_PKEY_todata() and EVP_PKEY_export() functions. Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14800) --- crypto/evp/keymgmt_lib.c | 2 ++ crypto/evp/pmeth_gn.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'crypto') diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c index 80aea65e88..f196bc4d88 100644 --- a/crypto/evp/keymgmt_lib.c +++ b/crypto/evp/keymgmt_lib.c @@ -80,6 +80,8 @@ EVP_PKEY *evp_keymgmt_util_make_pkey(EVP_KEYMGMT *keymgmt, void *keydata) int evp_keymgmt_util_export(const EVP_PKEY *pk, int selection, OSSL_CALLBACK *export_cb, void *export_cbarg) { + if (pk == NULL || export_cb == NULL) + return 0; return evp_keymgmt_export(pk->keymgmt, pk->keydata, selection, export_cb, export_cbarg); } diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 7383fbe072..e184db26a0 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -395,3 +395,26 @@ const OSSL_PARAM *EVP_PKEY_fromdata_settable(EVP_PKEY_CTX *ctx, int selection) return evp_keymgmt_import_types(ctx->keymgmt, selection); return NULL; } + +static OSSL_CALLBACK ossl_pkey_todata_cb; + +static int ossl_pkey_todata_cb(const OSSL_PARAM params[], void *arg) +{ + OSSL_PARAM **ret = arg; + + *ret = OSSL_PARAM_dup(params); + return 1; +} + +int EVP_PKEY_todata(const EVP_PKEY *pkey, int selection, OSSL_PARAM **params) +{ + if (params == NULL) + return 0; + return EVP_PKEY_export(pkey, selection, ossl_pkey_todata_cb, params); +} + +int EVP_PKEY_export(const EVP_PKEY *pkey, int selection, + OSSL_CALLBACK *export_cb, void *export_cbarg) +{ + return evp_keymgmt_util_export(pkey, selection, export_cb, export_cbarg); +} -- cgit v1.2.3