2019-02-09 00:01:56 +08:00
|
|
|
/*
|
2022-05-03 18:52:38 +08:00
|
|
|
* Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2019-02-09 00:01:56 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2019-09-28 06:45:46 +08:00
|
|
|
#include <openssl/types.h>
|
2019-02-09 00:01:56 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/core.h>
|
|
|
|
#include "internal/cryptlib.h"
|
|
|
|
#include "internal/thread_once.h"
|
|
|
|
#include "internal/property.h"
|
|
|
|
#include "internal/core.h"
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
#include "internal/provider.h"
|
2019-05-04 18:56:32 +08:00
|
|
|
#include "internal/namemap.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "crypto/evp.h" /* evp_local.h needs it */
|
|
|
|
#include "evp_local.h"
|
2019-02-09 00:01:56 +08:00
|
|
|
|
2019-05-23 09:36:21 +08:00
|
|
|
#define NAME_SEPARATOR ':'
|
|
|
|
|
2019-02-09 00:01:56 +08:00
|
|
|
/* Data to be passed through ossl_method_construct() */
|
2019-10-24 23:04:01 +08:00
|
|
|
struct evp_method_data_st {
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *libctx;
|
2019-10-24 23:04:01 +08:00
|
|
|
int operation_id; /* For get_evp_method_from_store() */
|
|
|
|
int name_id; /* For get_evp_method_from_store() */
|
|
|
|
const char *names; /* For get_evp_method_from_store() */
|
|
|
|
const char *propquery; /* For get_evp_method_from_store() */
|
2020-08-29 15:46:24 +08:00
|
|
|
|
2021-06-14 15:25:53 +08:00
|
|
|
OSSL_METHOD_STORE *tmp_store; /* For get_tmp_evp_method_store() */
|
|
|
|
|
2021-03-03 01:15:32 +08:00
|
|
|
unsigned int flag_construct_error_occurred : 1;
|
2020-08-29 15:46:24 +08:00
|
|
|
|
2021-03-16 21:14:43 +08:00
|
|
|
void *(*method_from_algorithm)(int name_id, const OSSL_ALGORITHM *,
|
|
|
|
OSSL_PROVIDER *);
|
2019-02-09 00:01:56 +08:00
|
|
|
int (*refcnt_up_method)(void *method);
|
|
|
|
void (*destruct_method)(void *method);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic routines to fetch / create EVP methods with ossl_method_construct()
|
|
|
|
*/
|
2021-06-14 15:25:53 +08:00
|
|
|
static void *get_tmp_evp_method_store(void *data)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2021-06-14 15:25:53 +08:00
|
|
|
struct evp_method_data_st *methdata = data;
|
|
|
|
|
|
|
|
if (methdata->tmp_store == NULL)
|
|
|
|
methdata->tmp_store = ossl_method_store_new(methdata->libctx);
|
|
|
|
return methdata->tmp_store;
|
2019-02-09 00:01:56 +08:00
|
|
|
}
|
|
|
|
|
2019-10-24 23:04:01 +08:00
|
|
|
static void dealloc_tmp_evp_method_store(void *store)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
|
|
|
if (store != NULL)
|
|
|
|
ossl_method_store_free(store);
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
static OSSL_METHOD_STORE *get_evp_method_store(OSSL_LIB_CTX *libctx)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2022-03-14 16:13:12 +08:00
|
|
|
return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_EVP_METHOD_STORE_INDEX);
|
2019-02-09 00:01:56 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 17:44:08 +08:00
|
|
|
/*
|
2020-04-14 06:12:48 +08:00
|
|
|
* To identify the method in the EVP method store, we mix the name identity
|
|
|
|
* with the operation identity, under the assumption that we don't have more
|
2021-06-09 13:50:08 +08:00
|
|
|
* than 2^23 names or more than 2^8 operation types.
|
2019-06-07 17:44:08 +08:00
|
|
|
*
|
2021-06-09 13:50:08 +08:00
|
|
|
* The resulting identity is a 31-bit integer, composed like this:
|
2019-06-07 17:44:08 +08:00
|
|
|
*
|
2021-06-09 13:50:08 +08:00
|
|
|
* +---------23 bits--------+-8 bits-+
|
2019-06-07 17:44:08 +08:00
|
|
|
* | name identity | op id |
|
|
|
|
* +------------------------+--------+
|
2021-06-09 13:50:08 +08:00
|
|
|
*
|
|
|
|
* We limit this composite number to 31 bits, thus leaving the top uint32_t
|
|
|
|
* bit always zero, to avoid negative sign extension when downshifting after
|
|
|
|
* this number happens to be passed to an int (which happens as soon as it's
|
|
|
|
* passed to ossl_method_store_cache_set(), and it's in that form that it
|
|
|
|
* gets passed along to filter_on_operation_id(), defined further down.
|
2019-06-07 17:44:08 +08:00
|
|
|
*/
|
2021-06-09 13:50:08 +08:00
|
|
|
#define METHOD_ID_OPERATION_MASK 0x000000FF
|
|
|
|
#define METHOD_ID_OPERATION_MAX ((1 << 8) - 1)
|
|
|
|
#define METHOD_ID_NAME_MASK 0x7FFFFF00
|
|
|
|
#define METHOD_ID_NAME_OFFSET 8
|
|
|
|
#define METHOD_ID_NAME_MAX ((1 << 23) - 1)
|
2020-04-17 01:10:14 +08:00
|
|
|
static uint32_t evp_method_id(int name_id, unsigned int operation_id)
|
2019-06-07 17:44:08 +08:00
|
|
|
{
|
2021-06-09 13:50:08 +08:00
|
|
|
if (!ossl_assert(name_id > 0 && name_id <= METHOD_ID_NAME_MAX)
|
|
|
|
|| !ossl_assert(operation_id > 0
|
|
|
|
&& operation_id <= METHOD_ID_OPERATION_MAX))
|
2019-06-07 17:44:08 +08:00
|
|
|
return 0;
|
2021-06-09 13:50:08 +08:00
|
|
|
return (((name_id << METHOD_ID_NAME_OFFSET) & METHOD_ID_NAME_MASK)
|
|
|
|
| (operation_id & METHOD_ID_OPERATION_MASK));
|
2019-06-07 17:44:08 +08:00
|
|
|
}
|
|
|
|
|
2021-10-04 21:33:37 +08:00
|
|
|
static void *get_evp_method_from_store(void *store, const OSSL_PROVIDER **prov,
|
|
|
|
void *data)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2019-10-24 23:04:01 +08:00
|
|
|
struct evp_method_data_st *methdata = data;
|
2019-02-09 00:01:56 +08:00
|
|
|
void *method = NULL;
|
2021-06-09 13:50:08 +08:00
|
|
|
int name_id = 0;
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
uint32_t meth_id;
|
2019-02-09 00:01:56 +08:00
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
/*
|
2019-10-24 23:04:01 +08:00
|
|
|
* get_evp_method_from_store() is only called to try and get the method
|
|
|
|
* that evp_generic_fetch() is asking for, and the operation id as well
|
|
|
|
* as the name or name id are passed via methdata.
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
*/
|
2021-06-09 13:50:08 +08:00
|
|
|
if ((name_id = methdata->name_id) == 0 && methdata->names != NULL) {
|
2021-06-15 16:18:19 +08:00
|
|
|
OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
|
2019-05-23 09:36:21 +08:00
|
|
|
const char *names = methdata->names;
|
|
|
|
const char *q = strchr(names, NAME_SEPARATOR);
|
|
|
|
size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
|
|
|
|
if (namemap == 0)
|
|
|
|
return NULL;
|
2019-05-23 09:36:21 +08:00
|
|
|
name_id = ossl_namemap_name2num_n(namemap, names, l);
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_id == 0
|
2020-04-17 01:10:14 +08:00
|
|
|
|| (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
|
2019-02-09 00:01:56 +08:00
|
|
|
return NULL;
|
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
if (store == NULL
|
2021-06-15 16:18:19 +08:00
|
|
|
&& (store = get_evp_method_store(methdata->libctx)) == NULL)
|
2019-05-05 14:42:21 +08:00
|
|
|
return NULL;
|
|
|
|
|
2021-10-04 21:33:37 +08:00
|
|
|
if (!ossl_method_store_fetch(store, meth_id, methdata->propquery, prov,
|
2019-11-11 09:17:32 +08:00
|
|
|
&method))
|
|
|
|
return NULL;
|
2019-02-09 00:01:56 +08:00
|
|
|
return method;
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:18:19 +08:00
|
|
|
static int put_evp_method_in_store(void *store, void *method,
|
|
|
|
const OSSL_PROVIDER *prov,
|
|
|
|
const char *names, const char *propdef,
|
|
|
|
void *data)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2019-10-24 23:04:01 +08:00
|
|
|
struct evp_method_data_st *methdata = data;
|
2019-05-05 14:42:21 +08:00
|
|
|
OSSL_NAMEMAP *namemap;
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
int name_id;
|
|
|
|
uint32_t meth_id;
|
2019-05-23 09:36:21 +08:00
|
|
|
size_t l = 0;
|
2019-03-21 01:51:29 +08:00
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
/*
|
2019-10-24 23:04:01 +08:00
|
|
|
* put_evp_method_in_store() is only called with an EVP method that was
|
|
|
|
* successfully created by construct_method() below, which means that
|
|
|
|
* all the names should already be stored in the namemap with the same
|
|
|
|
* numeric identity, so just use the first to get that identity.
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
*/
|
2019-05-23 09:36:21 +08:00
|
|
|
if (names != NULL) {
|
|
|
|
const char *q = strchr(names, NAME_SEPARATOR);
|
|
|
|
|
|
|
|
l = (q == NULL ? strlen(names) : (size_t)(q - names));
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:18:19 +08:00
|
|
|
if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
|
2019-05-23 09:36:21 +08:00
|
|
|
|| (name_id = ossl_namemap_name2num_n(namemap, names, l)) == 0
|
2021-06-15 16:18:19 +08:00
|
|
|
|| (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
|
2019-03-21 01:51:29 +08:00
|
|
|
return 0;
|
2019-02-09 00:01:56 +08:00
|
|
|
|
|
|
|
if (store == NULL
|
2021-06-15 16:18:19 +08:00
|
|
|
&& (store = get_evp_method_store(methdata->libctx)) == NULL)
|
2019-02-09 00:01:56 +08:00
|
|
|
return 0;
|
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
return ossl_method_store_add(store, prov, meth_id, propdef, method,
|
2019-08-21 15:58:10 +08:00
|
|
|
methdata->refcnt_up_method,
|
|
|
|
methdata->destruct_method);
|
2019-02-09 00:01:56 +08:00
|
|
|
}
|
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
/*
|
|
|
|
* The core fetching functionality passes the name of the implementation.
|
|
|
|
* This function is responsible to getting an identity number for it.
|
|
|
|
*/
|
2019-11-19 16:55:56 +08:00
|
|
|
static void *construct_evp_method(const OSSL_ALGORITHM *algodef,
|
2019-10-24 23:04:01 +08:00
|
|
|
OSSL_PROVIDER *prov, void *data)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
/*
|
2019-10-24 23:04:01 +08:00
|
|
|
* This function is only called if get_evp_method_from_store() returned
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
* NULL, so it's safe to say that of all the spots to create a new
|
|
|
|
* namemap entry, this is it. Should the name already exist there, we
|
2019-11-09 07:18:05 +08:00
|
|
|
* know that ossl_namemap_add_name() will return its corresponding
|
|
|
|
* number.
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
*/
|
2019-10-24 23:04:01 +08:00
|
|
|
struct evp_method_data_st *methdata = data;
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
2019-11-19 16:55:56 +08:00
|
|
|
const char *names = algodef->algorithm_names;
|
2019-11-09 07:18:05 +08:00
|
|
|
int name_id = ossl_namemap_add_names(namemap, 0, names, NAME_SEPARATOR);
|
2020-08-29 15:46:24 +08:00
|
|
|
void *method;
|
2019-02-09 00:01:56 +08:00
|
|
|
|
2019-05-23 09:36:21 +08:00
|
|
|
if (name_id == 0)
|
|
|
|
return NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
|
2021-03-16 21:14:43 +08:00
|
|
|
method = methdata->method_from_algorithm(name_id, algodef, prov);
|
2020-08-29 15:46:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Flag to indicate that there was actual construction errors. This
|
|
|
|
* helps inner_evp_generic_fetch() determine what error it should
|
|
|
|
* record on inaccessible algorithms.
|
|
|
|
*/
|
|
|
|
if (method == NULL)
|
2021-03-03 01:15:32 +08:00
|
|
|
methdata->flag_construct_error_occurred = 1;
|
2020-08-29 15:46:24 +08:00
|
|
|
|
|
|
|
return method;
|
2019-02-09 00:01:56 +08:00
|
|
|
}
|
|
|
|
|
2019-10-24 23:04:01 +08:00
|
|
|
static void destruct_evp_method(void *method, void *data)
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2019-10-24 23:04:01 +08:00
|
|
|
struct evp_method_data_st *methdata = data;
|
2019-02-09 00:01:56 +08:00
|
|
|
|
|
|
|
methdata->destruct_method(method);
|
|
|
|
}
|
|
|
|
|
2019-10-24 23:04:01 +08:00
|
|
|
static void *
|
2021-09-30 15:32:57 +08:00
|
|
|
inner_evp_generic_fetch(struct evp_method_data_st *methdata,
|
|
|
|
OSSL_PROVIDER *prov, int operation_id,
|
2019-10-24 23:04:01 +08:00
|
|
|
int name_id, const char *name,
|
|
|
|
const char *properties,
|
|
|
|
void *(*new_method)(int name_id,
|
2021-03-16 21:14:43 +08:00
|
|
|
const OSSL_ALGORITHM *algodef,
|
2019-10-31 19:10:01 +08:00
|
|
|
OSSL_PROVIDER *prov),
|
2019-10-24 23:04:01 +08:00
|
|
|
int (*up_ref_method)(void *),
|
|
|
|
void (*free_method)(void *))
|
2019-02-09 00:01:56 +08:00
|
|
|
{
|
2021-06-14 15:25:53 +08:00
|
|
|
OSSL_METHOD_STORE *store = get_evp_method_store(methdata->libctx);
|
|
|
|
OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
|
2022-02-25 10:37:08 +08:00
|
|
|
const char *const propq = properties != NULL ? properties : "";
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
uint32_t meth_id = 0;
|
2019-02-09 00:01:56 +08:00
|
|
|
void *method = NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
int unsupported = 0;
|
2019-02-09 00:01:56 +08:00
|
|
|
|
2020-08-29 15:46:24 +08:00
|
|
|
if (store == NULL || namemap == NULL) {
|
2020-10-17 13:07:41 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_INVALID_ARGUMENT);
|
2019-04-18 18:23:21 +08:00
|
|
|
return NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
}
|
2019-04-18 18:23:21 +08:00
|
|
|
|
2019-06-07 17:44:08 +08:00
|
|
|
/*
|
|
|
|
* If there's ever an operation_id == 0 passed, we have an internal
|
|
|
|
* programming error.
|
|
|
|
*/
|
2020-08-29 15:46:24 +08:00
|
|
|
if (!ossl_assert(operation_id > 0)) {
|
2020-10-17 13:07:41 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
2019-06-07 17:44:08 +08:00
|
|
|
return NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
}
|
2019-06-07 17:44:08 +08:00
|
|
|
|
|
|
|
/*
|
2021-06-09 13:50:08 +08:00
|
|
|
* If we have been passed both a name_id and a name, we have an
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
* internal programming error.
|
|
|
|
*/
|
2021-06-09 13:50:08 +08:00
|
|
|
if (!ossl_assert(name_id == 0 || name == NULL)) {
|
2020-10-17 13:07:41 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
return NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
}
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
|
|
|
|
/* If we haven't received a name id yet, try to get one for the name */
|
2021-06-09 13:50:08 +08:00
|
|
|
if (name_id == 0 && name != NULL)
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
name_id = ossl_namemap_name2num(namemap, name);
|
|
|
|
|
|
|
|
/*
|
2019-10-24 23:04:01 +08:00
|
|
|
* If we have a name id, calculate a method id with evp_method_id().
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
*
|
2019-10-24 23:04:01 +08:00
|
|
|
* evp_method_id returns 0 if we have too many operations (more than
|
|
|
|
* about 2^8) or too many names (more than about 2^24). In that case,
|
|
|
|
* we can't create any new method.
|
2020-08-29 15:46:24 +08:00
|
|
|
* For all intents and purposes, this is an internal error.
|
2019-06-07 17:44:08 +08:00
|
|
|
*/
|
2020-08-29 15:46:24 +08:00
|
|
|
if (name_id != 0 && (meth_id = evp_method_id(name_id, operation_id)) == 0) {
|
2020-10-17 13:07:41 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
2019-06-07 17:44:08 +08:00
|
|
|
return NULL;
|
2020-08-29 15:46:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we haven't found the name yet, chances are that the algorithm to
|
|
|
|
* be fetched is unsupported.
|
|
|
|
*/
|
|
|
|
if (name_id == 0)
|
|
|
|
unsupported = 1;
|
2019-06-07 17:44:08 +08:00
|
|
|
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
if (meth_id == 0
|
2022-02-25 10:37:08 +08:00
|
|
|
|| !ossl_method_store_cache_get(store, prov, meth_id, propq, &method)) {
|
2019-02-09 00:01:56 +08:00
|
|
|
OSSL_METHOD_CONSTRUCT_METHOD mcm = {
|
2021-06-14 15:25:53 +08:00
|
|
|
get_tmp_evp_method_store,
|
2019-10-24 23:04:01 +08:00
|
|
|
get_evp_method_from_store,
|
|
|
|
put_evp_method_in_store,
|
|
|
|
construct_evp_method,
|
|
|
|
destruct_evp_method
|
2019-02-09 00:01:56 +08:00
|
|
|
};
|
2021-06-14 15:25:53 +08:00
|
|
|
|
|
|
|
methdata->operation_id = operation_id;
|
|
|
|
methdata->name_id = name_id;
|
|
|
|
methdata->names = name;
|
2022-02-25 10:37:08 +08:00
|
|
|
methdata->propquery = propq;
|
2021-06-14 15:25:53 +08:00
|
|
|
methdata->method_from_algorithm = new_method;
|
|
|
|
methdata->refcnt_up_method = up_ref_method;
|
|
|
|
methdata->destruct_method = free_method;
|
|
|
|
methdata->flag_construct_error_occurred = 0;
|
|
|
|
if ((method = ossl_method_construct(methdata->libctx, operation_id,
|
2021-10-04 21:33:37 +08:00
|
|
|
&prov, 0 /* !force_cache */,
|
2021-06-14 15:25:53 +08:00
|
|
|
&mcm, methdata)) != NULL) {
|
2019-06-07 17:44:08 +08:00
|
|
|
/*
|
|
|
|
* If construction did create a method for us, we know that
|
2019-10-24 23:04:01 +08:00
|
|
|
* there is a correct name_id and meth_id, since those have
|
|
|
|
* already been calculated in get_evp_method_from_store() and
|
|
|
|
* put_evp_method_in_store() above.
|
2019-06-07 17:44:08 +08:00
|
|
|
*/
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
if (name_id == 0)
|
|
|
|
name_id = ossl_namemap_name2num(namemap, name);
|
2020-04-17 01:10:14 +08:00
|
|
|
meth_id = evp_method_id(name_id, operation_id);
|
2021-06-09 13:50:08 +08:00
|
|
|
if (name_id != 0)
|
2022-02-25 10:37:08 +08:00
|
|
|
ossl_method_store_cache_set(store, prov, meth_id, propq,
|
2021-10-04 21:33:37 +08:00
|
|
|
method, up_ref_method, free_method);
|
2019-06-07 17:44:08 +08:00
|
|
|
}
|
2020-08-29 15:46:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we never were in the constructor, the algorithm to be fetched
|
|
|
|
* is unsupported.
|
|
|
|
*/
|
2021-06-14 15:25:53 +08:00
|
|
|
unsupported = !methdata->flag_construct_error_occurred;
|
2019-02-09 00:01:56 +08:00
|
|
|
}
|
|
|
|
|
2021-06-09 13:50:08 +08:00
|
|
|
if ((name_id != 0 || name != NULL) && method == NULL) {
|
2020-10-17 13:07:41 +08:00
|
|
|
int code = unsupported ? ERR_R_UNSUPPORTED : ERR_R_FETCH_FAILED;
|
2019-04-05 16:46:18 +08:00
|
|
|
|
2020-08-29 15:46:24 +08:00
|
|
|
if (name == NULL)
|
|
|
|
name = ossl_namemap_num2name(namemap, name_id, 0);
|
|
|
|
ERR_raise_data(ERR_LIB_EVP, code,
|
|
|
|
"%s, Algorithm (%s : %d), Properties (%s)",
|
2021-06-14 15:25:53 +08:00
|
|
|
ossl_lib_ctx_get_descriptor(methdata->libctx),
|
2022-03-12 22:39:01 +08:00
|
|
|
name == NULL ? "<null>" : name, name_id,
|
2020-08-29 15:46:24 +08:00
|
|
|
properties == NULL ? "<null>" : properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
return method;
|
2020-06-23 16:09:20 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
void *evp_generic_fetch(OSSL_LIB_CTX *libctx, int operation_id,
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
const char *name, const char *properties,
|
|
|
|
void *(*new_method)(int name_id,
|
2021-03-16 21:14:43 +08:00
|
|
|
const OSSL_ALGORITHM *algodef,
|
2019-10-31 19:10:01 +08:00
|
|
|
OSSL_PROVIDER *prov),
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
int (*up_ref_method)(void *),
|
|
|
|
void (*free_method)(void *))
|
|
|
|
{
|
2021-06-14 15:25:53 +08:00
|
|
|
struct evp_method_data_st methdata;
|
|
|
|
void *method;
|
|
|
|
|
|
|
|
methdata.libctx = libctx;
|
|
|
|
methdata.tmp_store = NULL;
|
2021-09-30 15:32:57 +08:00
|
|
|
method = inner_evp_generic_fetch(&methdata, NULL, operation_id,
|
|
|
|
0, name, properties,
|
2021-06-14 15:25:53 +08:00
|
|
|
new_method, up_ref_method, free_method);
|
|
|
|
dealloc_tmp_evp_method_store(methdata.tmp_store);
|
|
|
|
return method;
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* evp_generic_fetch_by_number() is special, and only returns methods for
|
|
|
|
* already known names, i.e. it refuses to work if no name_id can be found
|
|
|
|
* (it's considered an internal programming error).
|
|
|
|
* This is meant to be used when one method needs to fetch an associated
|
2021-09-30 15:44:10 +08:00
|
|
|
* method.
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
*/
|
2020-10-15 17:55:50 +08:00
|
|
|
void *evp_generic_fetch_by_number(OSSL_LIB_CTX *libctx, int operation_id,
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
int name_id, const char *properties,
|
|
|
|
void *(*new_method)(int name_id,
|
2021-03-16 21:14:43 +08:00
|
|
|
const OSSL_ALGORITHM *algodef,
|
2019-10-31 19:10:01 +08:00
|
|
|
OSSL_PROVIDER *prov),
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
int (*up_ref_method)(void *),
|
|
|
|
void (*free_method)(void *))
|
|
|
|
{
|
2021-06-14 15:25:53 +08:00
|
|
|
struct evp_method_data_st methdata;
|
|
|
|
void *method;
|
|
|
|
|
|
|
|
methdata.libctx = libctx;
|
|
|
|
methdata.tmp_store = NULL;
|
2021-09-30 15:32:57 +08:00
|
|
|
method = inner_evp_generic_fetch(&methdata, NULL, operation_id,
|
|
|
|
name_id, NULL, properties,
|
2021-06-14 15:25:53 +08:00
|
|
|
new_method, up_ref_method, free_method);
|
|
|
|
dealloc_tmp_evp_method_store(methdata.tmp_store);
|
|
|
|
return method;
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
}
|
|
|
|
|
2021-09-30 15:44:10 +08:00
|
|
|
/*
|
|
|
|
* evp_generic_fetch_from_prov() is special, and only returns methods from
|
|
|
|
* the given provider.
|
|
|
|
* This is meant to be used when one method needs to fetch an associated
|
|
|
|
* method.
|
|
|
|
*/
|
|
|
|
void *evp_generic_fetch_from_prov(OSSL_PROVIDER *prov, int operation_id,
|
|
|
|
const char *name, const char *properties,
|
|
|
|
void *(*new_method)(int name_id,
|
|
|
|
const OSSL_ALGORITHM *algodef,
|
|
|
|
OSSL_PROVIDER *prov),
|
|
|
|
int (*up_ref_method)(void *),
|
|
|
|
void (*free_method)(void *))
|
|
|
|
{
|
|
|
|
struct evp_method_data_st methdata;
|
|
|
|
void *method;
|
|
|
|
|
|
|
|
methdata.libctx = ossl_provider_libctx(prov);
|
|
|
|
methdata.tmp_store = NULL;
|
|
|
|
method = inner_evp_generic_fetch(&methdata, prov, operation_id,
|
|
|
|
0, name, properties,
|
|
|
|
new_method, up_ref_method, free_method);
|
|
|
|
dealloc_tmp_evp_method_store(methdata.tmp_store);
|
|
|
|
return method;
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:29:01 +08:00
|
|
|
int evp_method_store_flush(OSSL_LIB_CTX *libctx)
|
2020-08-09 16:06:52 +08:00
|
|
|
{
|
|
|
|
OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
|
|
|
|
|
|
|
|
if (store != NULL)
|
2021-03-30 08:29:01 +08:00
|
|
|
return ossl_method_store_flush_cache(store, 1);
|
|
|
|
return 1;
|
2020-08-09 16:06:52 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
static int evp_set_parsed_default_properties(OSSL_LIB_CTX *libctx,
|
2020-08-01 00:29:21 +08:00
|
|
|
OSSL_PROPERTY_LIST *def_prop,
|
2021-05-11 23:50:27 +08:00
|
|
|
int loadconfig,
|
|
|
|
int mirrored)
|
2019-04-05 16:46:18 +08:00
|
|
|
{
|
2019-10-24 23:04:01 +08:00
|
|
|
OSSL_METHOD_STORE *store = get_evp_method_store(libctx);
|
2020-08-01 00:29:21 +08:00
|
|
|
OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
|
2020-06-12 08:34:46 +08:00
|
|
|
|
2021-05-08 00:59:47 +08:00
|
|
|
if (plp != NULL && store != NULL) {
|
2021-05-11 23:50:27 +08:00
|
|
|
#ifndef FIPS_MODULE
|
2021-05-08 00:59:47 +08:00
|
|
|
char *propstr = NULL;
|
|
|
|
size_t strsz;
|
|
|
|
|
2021-05-11 23:50:27 +08:00
|
|
|
if (mirrored) {
|
|
|
|
if (ossl_global_properties_no_mirrored(libctx))
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* These properties have been explicitly set on this libctx, so
|
|
|
|
* don't allow any mirroring from a parent libctx.
|
|
|
|
*/
|
|
|
|
ossl_global_properties_stop_mirroring(libctx);
|
|
|
|
}
|
|
|
|
|
2021-05-08 00:59:47 +08:00
|
|
|
strsz = ossl_property_list_to_string(libctx, def_prop, NULL, 0);
|
|
|
|
if (strsz > 0)
|
|
|
|
propstr = OPENSSL_malloc(strsz);
|
|
|
|
if (propstr == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ossl_property_list_to_string(libctx, def_prop, propstr,
|
|
|
|
strsz) == 0) {
|
|
|
|
OPENSSL_free(propstr);
|
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ossl_provider_default_props_update(libctx, propstr);
|
|
|
|
OPENSSL_free(propstr);
|
2021-05-11 23:50:27 +08:00
|
|
|
#endif
|
|
|
|
ossl_property_free(*plp);
|
|
|
|
*plp = def_prop;
|
2020-06-12 08:34:46 +08:00
|
|
|
if (store != NULL)
|
2021-03-30 08:29:01 +08:00
|
|
|
return ossl_method_store_flush_cache(store, 0);
|
2020-06-12 08:34:46 +08:00
|
|
|
}
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
2019-04-05 16:46:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-07-13 12:53:44 +08:00
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq,
|
2021-05-11 23:50:27 +08:00
|
|
|
int loadconfig, int mirrored)
|
2020-06-12 08:34:46 +08:00
|
|
|
{
|
|
|
|
OSSL_PROPERTY_LIST *pl = NULL;
|
|
|
|
|
2021-03-13 08:34:49 +08:00
|
|
|
if (propq != NULL && (pl = ossl_parse_query(libctx, propq, 1)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
|
2020-06-12 08:34:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-11 23:50:27 +08:00
|
|
|
if (!evp_set_parsed_default_properties(libctx, pl, loadconfig, mirrored)) {
|
2021-05-07 23:42:53 +08:00
|
|
|
ossl_property_free(pl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2020-06-12 08:34:46 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
int EVP_set_default_properties(OSSL_LIB_CTX *libctx, const char *propq)
|
2020-08-01 00:29:21 +08:00
|
|
|
{
|
2021-05-11 23:50:27 +08:00
|
|
|
return evp_set_default_properties_int(libctx, propq, 1, 0);
|
2020-08-01 00:29:21 +08:00
|
|
|
}
|
2020-05-02 12:17:54 +08:00
|
|
|
|
2021-07-27 23:59:59 +08:00
|
|
|
static int evp_default_properties_merge(OSSL_LIB_CTX *libctx, const char *propq,
|
|
|
|
int loadconfig)
|
2020-05-02 12:17:54 +08:00
|
|
|
{
|
2021-07-27 23:59:59 +08:00
|
|
|
OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
|
2020-06-12 08:34:46 +08:00
|
|
|
OSSL_PROPERTY_LIST *pl1, *pl2;
|
|
|
|
|
|
|
|
if (propq == NULL)
|
|
|
|
return 1;
|
|
|
|
if (plp == NULL || *plp == NULL)
|
2021-07-27 23:59:59 +08:00
|
|
|
return evp_set_default_properties_int(libctx, propq, 0, 0);
|
2021-03-13 08:34:49 +08:00
|
|
|
if ((pl1 = ossl_parse_query(libctx, propq, 1)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR);
|
2020-06-12 08:34:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pl2 = ossl_property_merge(pl1, *plp);
|
|
|
|
ossl_property_free(pl1);
|
|
|
|
if (pl2 == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
|
2020-06-12 08:34:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-11 23:50:27 +08:00
|
|
|
if (!evp_set_parsed_default_properties(libctx, pl2, 0, 0)) {
|
2021-05-07 23:42:53 +08:00
|
|
|
ossl_property_free(pl2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2020-05-02 12:17:54 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
static int evp_default_property_is_enabled(OSSL_LIB_CTX *libctx,
|
2020-05-02 12:17:54 +08:00
|
|
|
const char *prop_name)
|
|
|
|
{
|
2020-08-01 00:29:21 +08:00
|
|
|
OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, 1);
|
2020-05-02 12:17:54 +08:00
|
|
|
|
2020-06-12 08:34:46 +08:00
|
|
|
return plp != NULL && ossl_property_is_enabled(libctx, prop_name, *plp);
|
2020-05-02 12:17:54 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *libctx)
|
2020-05-02 12:17:54 +08:00
|
|
|
{
|
|
|
|
return evp_default_property_is_enabled(libctx, "fips");
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:59:59 +08:00
|
|
|
int evp_default_properties_enable_fips_int(OSSL_LIB_CTX *libctx, int enable,
|
|
|
|
int loadconfig)
|
2020-05-02 12:17:54 +08:00
|
|
|
{
|
|
|
|
const char *query = (enable != 0) ? "fips=yes" : "-fips";
|
|
|
|
|
2021-07-27 23:59:59 +08:00
|
|
|
return evp_default_properties_merge(libctx, query, loadconfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
int EVP_default_properties_enable_fips(OSSL_LIB_CTX *libctx, int enable)
|
|
|
|
{
|
|
|
|
return evp_default_properties_enable_fips_int(libctx, enable, 1);
|
2020-05-02 12:17:54 +08:00
|
|
|
}
|
|
|
|
|
2021-05-08 00:59:47 +08:00
|
|
|
char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig)
|
|
|
|
{
|
|
|
|
OSSL_PROPERTY_LIST **plp = ossl_ctx_global_properties(libctx, loadconfig);
|
|
|
|
char *propstr = NULL;
|
|
|
|
size_t sz;
|
|
|
|
|
2021-05-24 07:35:08 +08:00
|
|
|
if (plp == NULL)
|
|
|
|
return OPENSSL_strdup("");
|
|
|
|
|
2021-05-08 00:59:47 +08:00
|
|
|
sz = ossl_property_list_to_string(libctx, *plp, NULL, 0);
|
|
|
|
if (sz == 0) {
|
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
propstr = OPENSSL_malloc(sz);
|
|
|
|
if (propstr == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ossl_property_list_to_string(libctx, *plp, propstr, sz) == 0) {
|
|
|
|
ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
|
|
|
|
OPENSSL_free(propstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return propstr;
|
|
|
|
}
|
2020-05-02 12:17:54 +08:00
|
|
|
|
2021-06-09 13:50:08 +08:00
|
|
|
struct filter_data_st {
|
|
|
|
int operation_id;
|
2019-07-13 12:53:44 +08:00
|
|
|
void (*user_fn)(void *method, void *arg);
|
|
|
|
void *user_arg;
|
|
|
|
};
|
|
|
|
|
2021-06-09 13:50:08 +08:00
|
|
|
static void filter_on_operation_id(int id, void *method, void *arg)
|
2019-07-13 12:53:44 +08:00
|
|
|
{
|
2021-06-09 13:50:08 +08:00
|
|
|
struct filter_data_st *data = arg;
|
2019-07-13 12:53:44 +08:00
|
|
|
|
2021-06-09 13:50:08 +08:00
|
|
|
if ((id & METHOD_ID_OPERATION_MASK) == data->operation_id)
|
2019-07-13 12:53:44 +08:00
|
|
|
data->user_fn(method, data->user_arg);
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
void evp_generic_do_all(OSSL_LIB_CTX *libctx, int operation_id,
|
2019-07-13 12:53:44 +08:00
|
|
|
void (*user_fn)(void *method, void *arg),
|
|
|
|
void *user_arg,
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
void *(*new_method)(int name_id,
|
2021-03-16 21:14:43 +08:00
|
|
|
const OSSL_ALGORITHM *algodef,
|
2019-10-31 19:10:01 +08:00
|
|
|
OSSL_PROVIDER *prov),
|
2021-06-09 13:50:08 +08:00
|
|
|
int (*up_ref_method)(void *),
|
2019-07-13 12:53:44 +08:00
|
|
|
void (*free_method)(void *))
|
|
|
|
{
|
2021-06-09 13:50:08 +08:00
|
|
|
struct evp_method_data_st methdata;
|
|
|
|
struct filter_data_st data;
|
|
|
|
|
|
|
|
methdata.libctx = libctx;
|
|
|
|
methdata.tmp_store = NULL;
|
2021-09-30 15:32:57 +08:00
|
|
|
(void)inner_evp_generic_fetch(&methdata, NULL, operation_id, 0, NULL, NULL,
|
2021-06-09 13:50:08 +08:00
|
|
|
new_method, up_ref_method, free_method);
|
2019-07-13 12:53:44 +08:00
|
|
|
|
2021-06-09 13:50:08 +08:00
|
|
|
data.operation_id = operation_id;
|
2019-07-13 12:53:44 +08:00
|
|
|
data.user_fn = user_fn;
|
|
|
|
data.user_arg = user_arg;
|
2021-06-09 13:50:08 +08:00
|
|
|
if (methdata.tmp_store != NULL)
|
|
|
|
ossl_method_store_do_all(methdata.tmp_store, &filter_on_operation_id,
|
|
|
|
&data);
|
|
|
|
ossl_method_store_do_all(get_evp_method_store(libctx),
|
|
|
|
&filter_on_operation_id, &data);
|
|
|
|
dealloc_tmp_evp_method_store(methdata.tmp_store);
|
2019-07-13 12:53:44 +08:00
|
|
|
}
|
In provider implemented methods, save the name number, not the name string
Multiple names per implementation is already supported in the namemap,
but hasn't been used yet. However, as soon as we have multiple names,
we will get an issue with what name should be saved in the method.
The solution is to not save the name itself, but rather the number
it's associated with. This number is supposed to be unique for each
set of names, and we assume that algorithm names are globally unique,
i.e. there can be no name overlap between different algorithm types.
Incidently, it was also found that the 'get' function used by
ossl_construct_method() doesn't need all the parameters it was given;
most of what it needs, it can now get through the data structure given
by the caller of ossl_construct_method(). As a consequence,
ossl_construct_method() itself doesn't need all the parameters it was
given either.
There are some added internal functions that are expected to disappear
as soon as legacy code is removed, such as evp_first_name() and
ossl_namemap_num2name().
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9897)
2019-09-14 22:22:19 +08:00
|
|
|
|
2020-01-15 08:04:37 +08:00
|
|
|
int evp_is_a(OSSL_PROVIDER *prov, int number,
|
|
|
|
const char *legacy_name, const char *name)
|
2019-09-14 22:35:08 +08:00
|
|
|
{
|
2020-01-15 08:04:37 +08:00
|
|
|
/*
|
|
|
|
* For a |prov| that is NULL, the library context will be NULL
|
|
|
|
*/
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
|
2019-09-14 22:35:08 +08:00
|
|
|
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
|
|
|
|
2020-01-15 08:04:37 +08:00
|
|
|
if (prov == NULL)
|
|
|
|
number = ossl_namemap_name2num(namemap, legacy_name);
|
2019-09-14 22:35:08 +08:00
|
|
|
return ossl_namemap_name2num(namemap, name) == number;
|
|
|
|
}
|
2019-09-22 02:57:51 +08:00
|
|
|
|
2021-02-20 01:03:43 +08:00
|
|
|
int evp_names_do_all(OSSL_PROVIDER *prov, int number,
|
|
|
|
void (*fn)(const char *name, void *data),
|
|
|
|
void *data)
|
2019-09-22 02:57:51 +08:00
|
|
|
{
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
|
2019-09-22 02:57:51 +08:00
|
|
|
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
|
|
|
|
2021-02-20 01:03:43 +08:00
|
|
|
return ossl_namemap_doall_names(namemap, number, fn, data);
|
2019-09-22 02:57:51 +08:00
|
|
|
}
|