From: Richard Levitte Date: Wed, 5 Feb 2020 14:41:58 +0000 (+0100) Subject: KEYMGMT: Add a keydata copy function X-Git-Tag: openssl-3.0.0-alpha1~348 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=13697f1c62e98a4c1365fd85cb39ada0f47dce5f KEYMGMT: Add a keydata copy function Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/11158) --- diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index 9d37dce20c..774db4da8f 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -92,6 +92,7 @@ struct evp_keymgmt_st { OSSL_OP_keymgmt_import_types_fn *import_types; OSSL_OP_keymgmt_export_fn *export; OSSL_OP_keymgmt_export_types_fn *export_types; + OSSL_OP_keymgmt_copy_fn *copy; } /* EVP_KEYMGMT */ ; struct evp_keyexch_st { diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 9dd53f9dc2..f80e6e29b5 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -335,3 +335,13 @@ const OSSL_PARAM *evp_keymgmt_export_types(const EVP_KEYMGMT *keymgmt, return NULL; return keymgmt->export_types(selection); } + +int evp_keymgmt_copy(const EVP_KEYMGMT *keymgmt, + void *keydata_to, const void *keydata_from, + int selection) +{ + /* We assume no copy if the implementation doesn't have a function */ + if (keymgmt->copy == NULL) + return 0; + return keymgmt->copy(keydata_to, keydata_from, selection); +} diff --git a/doc/man7/provider-keymgmt.pod b/doc/man7/provider-keymgmt.pod index e51ef74099..91b87cecdc 100644 --- a/doc/man7/provider-keymgmt.pod +++ b/doc/man7/provider-keymgmt.pod @@ -39,6 +39,9 @@ provider-keymgmt - The KEYMGMT library E-E provider functions OSSL_CALLBACK *param_cb, void *cbarg); const OSSL_PARAM *OP_keymgmt_export_types(int selection); + /* Key object copy */ + int OP_keymgmt_copy(void *keydata_to, const void *keydata_from, int selection); + /* Key object validation */ int OP_keymgmt_validate(void *keydata, int selection); @@ -93,6 +96,7 @@ macros in L, as follows: OP_keymgmt_export OSSL_FUNC_KEYMGMT_EXPORT OP_keymgmt_export_types OSSL_FUNC_KEYMGMT_EXPORT_TYPES + OP_keymgmt_copy OSSL_FUNC_KEYMGMT_COPY =head2 Key Objects @@ -247,7 +251,7 @@ I in I and I match. It is assumed that the caller has ensured that I and I are both owned by the implementation of this function. -=head2 Key Object Import and Export Functions +=head2 Key Object Import, Export and Copy Functions OP_keymgmt_import() should import data indicated by I into I with values taken from the B array I. @@ -264,6 +268,11 @@ OP_keymgmt_export_types() should return a constant array of descriptor B for data indicated by I, that the OP_keymgmt_export() callback can expect to receive. +OP_keymgmt_copy() should copy data subsets indicated by I +from I to I. It is assumed that the caller +has ensured that I and I are both owned by +the implementation of this function. + =head2 Built-in RSA Import/Export Types The following Import/Export types are available for the built-in RSA algorithm: diff --git a/include/crypto/evp.h b/include/crypto/evp.h index f9c67d2a71..21f3f16053 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -651,6 +651,9 @@ int evp_keymgmt_export(const EVP_KEYMGMT *keymgmt, void *keydata, int selection, OSSL_CALLBACK *param_cb, void *cbarg); const OSSL_PARAM *evp_keymgmt_export_types(const EVP_KEYMGMT *keymgmt, int selection); +int evp_keymgmt_copy(const EVP_KEYMGMT *keymgmt, + void *keydata_to, const void *keydata_from, + int selection); /* Pulling defines out of C source files */ diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h index 5144a15dc3..3314a0f665 100644 --- a/include/openssl/core_numbers.h +++ b/include/openssl/core_numbers.h @@ -418,7 +418,7 @@ OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_match, (const void *keydata1, const void *keydata2, int selection)) -/* Import and export functions, with ddiscovery */ +/* Import and export functions, with discovery */ # define OSSL_FUNC_KEYMGMT_IMPORT 40 # define OSSL_FUNC_KEYMGMT_IMPORT_TYPES 41 # define OSSL_FUNC_KEYMGMT_EXPORT 42 @@ -433,6 +433,12 @@ OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_export, OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_export_types, (int selection)) +/* Copy function, only works for matching keymgmt */ +# define OSSL_FUNC_KEYMGMT_COPY 44 +OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_copy, + ( void *keydata_to, const void *keydata_from, + int selection)) + /* Key Exchange */ # define OSSL_FUNC_KEYEXCH_NEWCTX 1