#include <stdarg.h>
#include <openssl/crypto.h>
#include "internal/property.h"
-#include "internal/ctype.h"
+#include "crypto/ctype.h"
#include <openssl/lhash.h>
#include <openssl/rand.h>
#include "internal/thread_once.h"
-#include "internal/lhash.h"
-#include "internal/sparse_array.h"
+#include "crypto/lhash.h"
+#include "crypto/sparse_array.h"
#include "property_lcl.h"
/* The number of elements in the query cache before we initiate a flush */
#define IMPL_CACHE_FLUSH_THRESHOLD 500
typedef struct {
+ const OSSL_PROVIDER *provider;
OSSL_PROPERTY_LIST *properties;
void *method;
void (*method_destruct)(void *);
return p != 0 ? CRYPTO_THREAD_unlock(p->lock) : 0;
}
-static openssl_ctx_run_once_fn do_method_store_init;
-int do_method_store_init(OPENSSL_CTX *ctx)
-{
- return ossl_property_parse_init(ctx);
-}
-
static unsigned long query_hash(const QUERY *a)
{
return OPENSSL_LH_strhash(a->query);
{
OSSL_METHOD_STORE *res;
- if (!openssl_ctx_run_once(ctx,
- OPENSSL_CTX_METHOD_STORE_RUN_ONCE_INDEX,
- do_method_store_init))
- return NULL;
-
res = OPENSSL_zalloc(sizeof(*res));
if (res != NULL) {
res->ctx = ctx;
return ossl_sa_ALGORITHM_set(store->algs, alg->nid, alg);
}
-int ossl_method_store_add(OSSL_METHOD_STORE *store,
- int nid, const char *properties,
- void *method, void (*method_destruct)(void *))
+int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov,
+ int nid, const char *properties, void *method,
+ int (*method_up_ref)(void *),
+ void (*method_destruct)(void *))
{
ALGORITHM *alg = NULL;
IMPLEMENTATION *impl;
int ret = 0;
+ int i;
if (nid <= 0 || method == NULL || store == NULL)
return 0;
impl = OPENSSL_malloc(sizeof(*impl));
if (impl == NULL)
return 0;
+ if (method_up_ref != NULL && !method_up_ref(method)) {
+ OPENSSL_free(impl);
+ return 0;
+ }
+ impl->provider = prov;
impl->method = method;
impl->method_destruct = method_destruct;
goto err;
}
- /* Push onto stack */
- if (sk_IMPLEMENTATION_push(alg->impls, impl))
+ /* Push onto stack if there isn't one there already */
+ for (i = 0; i < sk_IMPLEMENTATION_num(alg->impls); i++) {
+ const IMPLEMENTATION *tmpimpl = sk_IMPLEMENTATION_value(alg->impls, i);
+
+ if (tmpimpl->provider == impl->provider
+ && tmpimpl->properties == impl->properties)
+ break;
+ }
+ if (i == sk_IMPLEMENTATION_num(alg->impls)
+ && sk_IMPLEMENTATION_push(alg->impls, impl))
ret = 1;
ossl_property_unlock(store);
if (ret == 0)
int ret = 0;
int j, best = -1, score, optional;
+#ifndef FIPS_MODE
+ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+#endif
+
if (nid <= 0 || method == NULL || store == NULL)
return 0;
state.nelem = 0;
if ((state.seed = OPENSSL_rdtsc()) == 0)
state.seed = 1;
- ossl_sa_ALGORITHM_doall_arg(store->algs, &impl_cache_flush_one_alg, &state);
store->need_flush = 0;
+ ossl_sa_ALGORITHM_doall_arg(store->algs, &impl_cache_flush_one_alg, &state);
store->nelem = state.nelem;
}