Latest update (add quic)
This commit is contained in:
+87
-35
@@ -119,7 +119,7 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
|
||||
* If |to| is a legacy key and |from| isn't, we must downgrade |from|.
|
||||
* If that fails, this function fails.
|
||||
*/
|
||||
if (to->type != EVP_PKEY_NONE && from->keymgmt != NULL)
|
||||
if (evp_pkey_is_legacy(to) && evp_pkey_is_provided(from))
|
||||
if (!evp_pkey_downgrade((EVP_PKEY *)from))
|
||||
return 0;
|
||||
|
||||
@@ -135,15 +135,15 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
|
||||
* like evp_keymgmt_util_copy() and evp_pkey_export_to_provider() called
|
||||
* further down help us find out if they are the same or not.
|
||||
*/
|
||||
if (to->type == EVP_PKEY_NONE && to->keymgmt == NULL) {
|
||||
if (from->type != EVP_PKEY_NONE) {
|
||||
if (evp_pkey_is_blank(to)) {
|
||||
if (evp_pkey_is_legacy(from)) {
|
||||
if (EVP_PKEY_set_type(to, from->type) == 0)
|
||||
return 0;
|
||||
} else {
|
||||
if (EVP_PKEY_set_type_by_keymgmt(to, from->keymgmt) == 0)
|
||||
return 0;
|
||||
}
|
||||
} else if (to->type != EVP_PKEY_NONE) {
|
||||
} else if (evp_pkey_is_legacy(to)) {
|
||||
if (to->type != from->type) {
|
||||
EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);
|
||||
goto err;
|
||||
@@ -156,7 +156,7 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_missing_parameters(to)) {
|
||||
if (EVP_PKEY_cmp_parameters(to, from) == 1)
|
||||
if (EVP_PKEY_parameters_eq(to, from) == 1)
|
||||
return 1;
|
||||
EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS);
|
||||
return 0;
|
||||
@@ -272,7 +272,14 @@ static int evp_pkey_cmp_any(const EVP_PKEY *a, const EVP_PKEY *b,
|
||||
return evp_keymgmt_match(keymgmt1, keydata1, keydata2, selection);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
{
|
||||
return EVP_PKEY_parameters_eq(a, b);
|
||||
}
|
||||
#endif
|
||||
|
||||
int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
{
|
||||
/*
|
||||
* TODO: clean up legacy stuff from this function when legacy support
|
||||
@@ -290,7 +297,14 @@ int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
{
|
||||
return EVP_PKEY_eq(a, b);
|
||||
}
|
||||
#endif
|
||||
|
||||
int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
{
|
||||
/*
|
||||
* TODO: clean up legacy stuff from this function when legacy support
|
||||
@@ -581,7 +595,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
|
||||
prov == NULL ? NULL : ossl_provider_library_context(prov);
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
EVP_MAC *cmac = EVP_MAC_fetch(libctx, OSSL_MAC_NAME_CMAC, NULL);
|
||||
EVP_MAC_CTX *cmctx = cmac != NULL ? EVP_MAC_CTX_new(cmac) : NULL;
|
||||
EVP_MAC_CTX *cmctx = cmac != NULL ? EVP_MAC_new_ctx(cmac) : NULL;
|
||||
OSSL_PARAM params[4];
|
||||
size_t paramsn = 0;
|
||||
|
||||
@@ -606,7 +620,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
|
||||
(char *)priv, len);
|
||||
params[paramsn] = OSSL_PARAM_construct_end();
|
||||
|
||||
if (!EVP_MAC_CTX_set_params(cmctx, params)) {
|
||||
if (!EVP_MAC_set_ctx_params(cmctx, params)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, EVP_R_KEY_SETUP_FAILED);
|
||||
goto err;
|
||||
}
|
||||
@@ -616,7 +630,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
|
||||
|
||||
err:
|
||||
EVP_PKEY_free(ret);
|
||||
EVP_MAC_CTX_free(cmctx);
|
||||
EVP_MAC_free_ctx(cmctx);
|
||||
EVP_MAC_free(cmac);
|
||||
return NULL;
|
||||
# else
|
||||
@@ -1201,6 +1215,18 @@ int EVP_PKEY_supports_digest_nid(EVP_PKEY *pkey, int nid)
|
||||
int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
|
||||
const unsigned char *pt, size_t ptlen)
|
||||
{
|
||||
if (pkey->ameth == NULL) {
|
||||
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
|
||||
if (pkey->keymgmt == NULL || pkey->keydata == NULL)
|
||||
return 0;
|
||||
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_TLS_ENCODED_PT,
|
||||
(unsigned char *)pt, ptlen);
|
||||
return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params);
|
||||
}
|
||||
|
||||
if (ptlen > INT_MAX)
|
||||
return 0;
|
||||
if (evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_SET1_TLS_ENCPT, ptlen,
|
||||
@@ -1212,6 +1238,33 @@ int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
|
||||
size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (pkey->ameth == NULL) {
|
||||
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
|
||||
if (pkey->keymgmt == NULL || pkey->keydata == NULL)
|
||||
return 0;
|
||||
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_TLS_ENCODED_PT,
|
||||
NULL, 0);
|
||||
if (!evp_keymgmt_get_params(pkey->keymgmt, pkey->keydata, params))
|
||||
return 0;
|
||||
|
||||
*ppt = OPENSSL_malloc(params[0].return_size);
|
||||
if (*ppt == NULL)
|
||||
return 0;
|
||||
|
||||
params[0] =
|
||||
OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_TLS_ENCODED_PT,
|
||||
*ppt, params[0].return_size);
|
||||
if (!evp_keymgmt_get_params(pkey->keymgmt, pkey->keydata, params))
|
||||
return 0;
|
||||
|
||||
return params[0].return_size;
|
||||
}
|
||||
|
||||
|
||||
rv = evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_GET1_TLS_ENCPT, 0, ppt);
|
||||
if (rv <= 0)
|
||||
return 0;
|
||||
@@ -1357,19 +1410,17 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str,
|
||||
pkey->engine = e;
|
||||
|
||||
/*
|
||||
* The EVP_PKEY_ASN1_METHOD |pkey_id| serves different purposes,
|
||||
* depending on if we're setting this key to contain a legacy or
|
||||
* a provider side "origin" key. For a legacy key, we assign it
|
||||
* to the |type| field, but for a provider side key, we assign it
|
||||
* to the |save_type| field, because |type| is supposed to be set
|
||||
* to EVP_PKEY_NONE in that case.
|
||||
* The EVP_PKEY_ASN1_METHOD |pkey_id| retains its legacy key purpose
|
||||
* for any key type that has a legacy implementation, regardless of
|
||||
* if the internal key is a legacy or a provider side one. When
|
||||
* there is no legacy implementation for the key, the type becomes
|
||||
* EVP_PKEY_KEYMGMT, which indicates that one should be cautious
|
||||
* with functions that expect legacy internal keys.
|
||||
*/
|
||||
if (ameth != NULL) {
|
||||
if (keymgmt != NULL)
|
||||
pkey->save_type = ameth->pkey_id;
|
||||
else if (pkey->ameth != NULL)
|
||||
pkey->type = ameth->pkey_id;
|
||||
}
|
||||
if (ameth != NULL)
|
||||
pkey->type = ameth->pkey_id;
|
||||
else
|
||||
pkey->type = EVP_PKEY_KEYMGMT;
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
@@ -1453,7 +1504,6 @@ void evp_pkey_free_legacy(EVP_PKEY *x)
|
||||
ENGINE_finish(x->pmeth_engine);
|
||||
x->pmeth_engine = NULL;
|
||||
# endif
|
||||
x->type = EVP_PKEY_NONE;
|
||||
}
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
@@ -1472,6 +1522,7 @@ static void evp_pkey_free_it(EVP_PKEY *x)
|
||||
x->keymgmt = NULL;
|
||||
x->keydata = NULL;
|
||||
}
|
||||
x->type = EVP_PKEY_NONE;
|
||||
}
|
||||
|
||||
void EVP_PKEY_free(EVP_PKEY *x)
|
||||
@@ -1661,32 +1712,33 @@ int evp_pkey_downgrade(EVP_PKEY *pk)
|
||||
{
|
||||
EVP_KEYMGMT *keymgmt = pk->keymgmt;
|
||||
void *keydata = pk->keydata;
|
||||
int type = pk->save_type;
|
||||
int type = pk->type;
|
||||
const char *keytype = NULL;
|
||||
|
||||
/* If this isn't a provider side key, we're done */
|
||||
if (keymgmt == NULL)
|
||||
return 1;
|
||||
|
||||
/* Get the key type name for error reporting */
|
||||
if (type != EVP_PKEY_NONE)
|
||||
keytype = OBJ_nid2sn(type);
|
||||
else
|
||||
keytype =
|
||||
evp_first_name(EVP_KEYMGMT_provider(keymgmt), keymgmt->name_id);
|
||||
keytype = evp_first_name(EVP_KEYMGMT_provider(keymgmt), keymgmt->name_id);
|
||||
|
||||
/*
|
||||
* |save_type| was set when any of the EVP_PKEY_set_type functions
|
||||
* was called. It was set to EVP_PKEY_NONE if the key type wasn't
|
||||
* recognised to be any of the legacy key types, and the downgrade
|
||||
* isn't possible.
|
||||
* If the type is EVP_PKEY_NONE, then we have a problem somewhere else
|
||||
* in our code. If it's not one of the well known EVP_PKEY_xxx values,
|
||||
* it should at least be EVP_PKEY_KEYMGMT at this point.
|
||||
* TODO(3.0) remove this check when we're confident that the rest of the
|
||||
* code treats this correctly.
|
||||
*/
|
||||
if (type == EVP_PKEY_NONE) {
|
||||
ERR_raise_data(ERR_LIB_EVP, EVP_R_UNKNOWN_KEY_TYPE,
|
||||
"key type = %s, can't downgrade", keytype);
|
||||
if (!ossl_assert(type != EVP_PKEY_NONE)) {
|
||||
ERR_raise_data(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR,
|
||||
"keymgmt key type = %s but legacy type = EVP_PKEY_NONE",
|
||||
keytype);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Prefer the legacy key type name for error reporting */
|
||||
if (type != EVP_PKEY_KEYMGMT)
|
||||
keytype = OBJ_nid2sn(type);
|
||||
|
||||
/*
|
||||
* To be able to downgrade, we steal the provider side "origin" keymgmt
|
||||
* and keydata. We've already grabbed the pointers, so all we need to
|
||||
|
||||
Reference in New Issue
Block a user