diff options
author | Richard Levitte <levitte@openssl.org> | 2020-02-02 18:56:07 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-02-07 09:37:56 +0100 |
commit | b305452f69fc97c586f2f9310014e332ae1d5cd5 (patch) | |
tree | 1214a4da68c682b9b4be9e43cd3607c1b5de8c2a /crypto/evp/pmeth_gn.c | |
parent | 68552cdef7631191e77315e0faeb42c6893cafe3 (diff) |
Redesign the KEYMGMT libcrypto <-> provider interface - the basics
The KEYMGMT libcrypto <-> provider interface currently makes a few
assumptions:
1. provider side domain parameters and key data isn't mutable. In
other words, as soon as a key has been created in any (loaded,
imported data, ...), it's set in stone.
2. provider side domain parameters can be strictly separated from the
key data.
This does work for the most part, but there are places where that's a
bit too rigid for the functionality that the EVP_PKEY API delivers.
Key data needs to be mutable to allow the flexibility that functions
like EVP_PKEY_copy_parameters promise, as well as to provide the
combinations of data that an EVP_PKEY is generally assumed to be able
to hold:
- domain parameters only
- public key only
- public key + private key
- domain parameters + public key
- domain parameters + public key + private key
To remedy all this, we:
1. let go of the distinction between domain parameters and key
material proper in the libcrypto <-> provider interface.
As a consequence, functions that still need it gain a selection
argument, which is a set of bits that indicate what parts of the
key object are to be considered in a specific call. This allows
a reduction of very similar functions into one.
2. Rework the libcrypto <-> provider interface so provider side key
objects are created and destructed with a separate function, and
get their data filled and extracted in through import and export.
(future work will see other key object constructors and other
functions to fill them with data)
Fixes #10979
squash! Redesign the KEYMGMT libcrypto <-> provider interface - the basics
Remedy 1 needs a rewrite:
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11006)
Diffstat (limited to 'crypto/evp/pmeth_gn.c')
-rw-r--r-- | crypto/evp/pmeth_gn.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 904b36e737..4bea1a1b86 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -208,7 +208,8 @@ int EVP_PKEY_key_fromdata_init(EVP_PKEY_CTX *ctx) int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, OSSL_PARAM params[]) { - void *provdata = NULL; + void *keydata = NULL; + int selection; if (ctx == NULL || (ctx->operation & EVP_PKEY_OP_TYPE_FROMDATA) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); @@ -226,13 +227,16 @@ int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, OSSL_PARAM params[]) return -1; } - provdata = - evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, params, - ctx->operation == EVP_PKEY_OP_PARAMFROMDATA); + if (ctx->operation == EVP_PKEY_OP_PARAMFROMDATA) + selection = OSSL_KEYMGMT_SELECT_ALL_PARAMETERS; + else + selection = OSSL_KEYMGMT_SELECT_KEYPAIR; + keydata = evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, selection, + params); - if (provdata == NULL) + if (keydata == NULL) return 0; - /* provdata is cached in *ppkey, so we need not bother with it further */ + /* keydata is cached in *ppkey, so we need not bother with it further */ return 1; } @@ -247,7 +251,8 @@ const OSSL_PARAM *EVP_PKEY_param_fromdata_settable(EVP_PKEY_CTX *ctx) { /* We call fromdata_init to get ctx->keymgmt populated */ if (fromdata_init(ctx, EVP_PKEY_OP_UNDEFINED)) - return evp_keymgmt_importdomparam_types(ctx->keymgmt); + return evp_keymgmt_import_types(ctx->keymgmt, + OSSL_KEYMGMT_SELECT_ALL_PARAMETERS); return NULL; } @@ -255,6 +260,7 @@ const OSSL_PARAM *EVP_PKEY_key_fromdata_settable(EVP_PKEY_CTX *ctx) { /* We call fromdata_init to get ctx->keymgmt populated */ if (fromdata_init(ctx, EVP_PKEY_OP_UNDEFINED)) - return evp_keymgmt_importdomparam_types(ctx->keymgmt); + return evp_keymgmt_import_types(ctx->keymgmt, + OSSL_KEYMGMT_SELECT_KEYPAIR); return NULL; } |