From bee5d6cd3fa2f8bcc7e1153e4dc26aa26144bee0 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 5 Feb 2020 12:53:14 +0100 Subject: [PATCH] KEYMGMT: Add a keydata matching function Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/11158) --- crypto/evp/evp_local.h | 1 + crypto/evp/keymgmt_meth.c | 14 ++++++++++++++ doc/man7/provider-keymgmt.pod | 8 ++++++++ include/crypto/evp.h | 3 +++ include/openssl/core_numbers.h | 6 ++++++ 5 files changed, 32 insertions(+) diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index 9b4ab29fda..9d37dce20c 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -85,6 +85,7 @@ struct evp_keymgmt_st { OSSL_OP_keymgmt_query_operation_name_fn *query_operation_name; OSSL_OP_keymgmt_has_fn *has; OSSL_OP_keymgmt_validate_fn *validate; + OSSL_OP_keymgmt_match_fn *match; /* Import and export routines */ OSSL_OP_keymgmt_import_fn *import; diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 3fcc073a5a..9dd53f9dc2 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -95,6 +95,10 @@ static void *keymgmt_from_dispatch(int name_id, if (keymgmt->validate == NULL) keymgmt->validate = OSSL_get_OP_keymgmt_validate(fns); break; + case OSSL_FUNC_KEYMGMT_MATCH: + if (keymgmt->match == NULL) + keymgmt->match = OSSL_get_OP_keymgmt_match(fns); + break; case OSSL_FUNC_KEYMGMT_IMPORT: if (keymgmt->import == NULL) { importfncnt++; @@ -290,6 +294,16 @@ int evp_keymgmt_validate(const EVP_KEYMGMT *keymgmt, void *keydata, return keymgmt->validate(keydata, selection); } +int evp_keymgmt_match(const EVP_KEYMGMT *keymgmt, + const void *keydata1, const void *keydata2, + int selection) +{ + /* We assume no match if the implementation doesn't have a function */ + if (keymgmt->match == NULL) + return 0; + return keymgmt->match(keydata1, keydata2, selection); +} + int evp_keymgmt_import(const EVP_KEYMGMT *keymgmt, void *keydata, int selection, const OSSL_PARAM params[]) { diff --git a/doc/man7/provider-keymgmt.pod b/doc/man7/provider-keymgmt.pod index 5141ffdebc..e51ef74099 100644 --- a/doc/man7/provider-keymgmt.pod +++ b/doc/man7/provider-keymgmt.pod @@ -26,6 +26,8 @@ provider-keymgmt - The KEYMGMT library E-E provider functions /* Key object content checks */ int OP_keymgmt_has(void *keydata, int selection); + int OP_keymgmt_match(const void *keydata1, const void *keydata2, + int selection); /* Discovery of supported operations */ const char *OP_keymgmt_query_operation_name(int operation_id); @@ -84,6 +86,7 @@ macros in L, as follows: OP_keymgmt_has OSSL_FUNC_KEYMGMT_HAS OP_keymgmt_validate OSSL_FUNC_KEYMGMT_VALIDATE + OP_keymgmt_match OSSL_FUNC_KEYMGMT_MATCH OP_keymgmt_import OSSL_FUNC_KEYMGMT_IMPORT OP_keymgmt_import_types OSSL_FUNC_KEYMGMT_IMPORT_TYPES @@ -239,6 +242,11 @@ B (or B for short) is expected to check that the pairwise consistency of I is valid. +OP_keymgmt_match() should check if the data subset indicated by +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 OP_keymgmt_import() should import data indicated by I into diff --git a/include/crypto/evp.h b/include/crypto/evp.h index bd624575bb..74d0c4b345 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -638,6 +638,9 @@ const OSSL_PARAM *evp_keymgmt_settable_params(const EVP_KEYMGMT *keymgmt); int evp_keymgmt_has(const EVP_KEYMGMT *keymgmt, void *keyddata, int selection); int evp_keymgmt_validate(const EVP_KEYMGMT *keymgmt, void *keydata, int selection); +int evp_keymgmt_match(const EVP_KEYMGMT *keymgmt, + const void *keydata1, const void *keydata2, + int selection); int evp_keymgmt_import(const EVP_KEYMGMT *keymgmt, void *keydata, int selection, const OSSL_PARAM params[]); diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h index 3fd462a8d6..5144a15dc3 100644 --- a/include/openssl/core_numbers.h +++ b/include/openssl/core_numbers.h @@ -412,6 +412,12 @@ OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_has, (void *keydata, int selection)) # define OSSL_FUNC_KEYMGMT_VALIDATE 22 OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_validate, (void *keydata, int selection)) +/* Key checks - matching */ +# define OSSL_FUNC_KEYMGMT_MATCH 23 +OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_match, + (const void *keydata1, const void *keydata2, + int selection)) + /* Import and export functions, with ddiscovery */ # define OSSL_FUNC_KEYMGMT_IMPORT 40 # define OSSL_FUNC_KEYMGMT_IMPORT_TYPES 41 -- 2.25.1