summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-07-09 17:31:24 +0200
committerRichard Levitte <levitte@openssl.org>2019-07-22 06:18:58 +0200
commitd0ea49a820e02713bbe8892a333f2552da633b16 (patch)
treec250dc8d1703bb6942f3f6bf0ebaf4e2f3a25f24 /crypto
parent70a1f7b4d7a0611508f45ef884472b9d84cbe108 (diff)
Adapt int_ctx_new() to use with providers
This affects all its callers: EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(). They are now possible to called with "zero" values, i.e.: EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(NULL, NULL); or EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(0, NULL); This is suitable for provider use, as the key functionality is tied with its keys, and the operation time is determined by the init functions the EVP_PKEY_CTX is used with. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9312)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/pmeth_lib.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 169b0565a4..cc26f06d9b 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -1,3 +1,4 @@
+
/*
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
*
@@ -106,8 +107,17 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
{
EVP_PKEY_CTX *ret;
- const EVP_PKEY_METHOD *pmeth;
+ const EVP_PKEY_METHOD *pmeth = NULL;
+
+ /*
+ * When using providers, the context is bound to the algo implementation
+ * later.
+ */
+ if (pkey == NULL && e == NULL && id == -1)
+ goto common;
+ /* TODO(3.0) Legacy code should be removed when all is provider based */
+ /* BEGIN legacy */
if (id == -1) {
if (pkey == NULL)
return 0;
@@ -143,7 +153,9 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
return NULL;
}
+ /* END legacy */
+ common:
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) {
#ifndef OPENSSL_NO_ENGINE
@@ -159,7 +171,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
if (pkey != NULL)
EVP_PKEY_up_ref(pkey);
- if (pmeth->init) {
+ if (pmeth != NULL && pmeth->init) {
if (pmeth->init(ret) <= 0) {
ret->pmeth = NULL;
EVP_PKEY_CTX_free(ret);