/*
- * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
} ALGORITHM;
struct ossl_method_store_st {
- OPENSSL_CTX *ctx;
+ OSSL_LIB_CTX *ctx;
size_t nelem;
SPARSE_ARRAY_OF(ALGORITHM) *algs;
int need_flush;
}
}
-static void *ossl_ctx_global_properties_new(OPENSSL_CTX *ctx)
+static void *ossl_ctx_global_properties_new(OSSL_LIB_CTX *ctx)
{
return OPENSSL_zalloc(sizeof(OSSL_PROPERTY_LIST **));
}
-static const OPENSSL_CTX_METHOD ossl_ctx_global_properties_method = {
+static const OSSL_LIB_CTX_METHOD ossl_ctx_global_properties_method = {
ossl_ctx_global_properties_new,
ossl_ctx_global_properties_free,
};
-OSSL_PROPERTY_LIST **ossl_ctx_global_properties(OPENSSL_CTX *libctx,
+OSSL_PROPERTY_LIST **ossl_ctx_global_properties(OSSL_LIB_CTX *libctx,
int loadconfig)
{
#ifndef FIPS_MODULE
if (loadconfig && !OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL))
return NULL;
#endif
- return openssl_ctx_get_data(libctx, OPENSSL_CTX_GLOBAL_PROPERTIES,
- &ossl_ctx_global_properties_method);
+ return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES,
+ &ossl_ctx_global_properties_method);
}
static int ossl_method_up_ref(METHOD *method)
(*method->free)(method->method);
}
-int ossl_property_read_lock(OSSL_METHOD_STORE *p)
+static __owur int ossl_property_read_lock(OSSL_METHOD_STORE *p)
{
return p != NULL ? CRYPTO_THREAD_read_lock(p->lock) : 0;
}
-int ossl_property_write_lock(OSSL_METHOD_STORE *p)
+static __owur int ossl_property_write_lock(OSSL_METHOD_STORE *p)
{
return p != NULL ? CRYPTO_THREAD_write_lock(p->lock) : 0;
}
-int ossl_property_unlock(OSSL_METHOD_STORE *p)
+static int ossl_property_unlock(OSSL_METHOD_STORE *p)
{
return p != 0 ? CRYPTO_THREAD_unlock(p->lock) : 0;
}
}
/*
- * The OPENSSL_CTX param here allows access to underlying property data needed
+ * The OSSL_LIB_CTX param here allows access to underlying property data needed
* for computation
*/
-OSSL_METHOD_STORE *ossl_method_store_new(OPENSSL_CTX *ctx)
+OSSL_METHOD_STORE *ossl_method_store_new(OSSL_LIB_CTX *ctx)
{
OSSL_METHOD_STORE *res;
* A write lock is used unconditionally because we wend our way down to the
* property string code which isn't locking friendly.
*/
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store)) {
+ OPENSSL_free(impl);
+ return 0;
+ }
ossl_method_cache_flush(store, nid);
if ((impl->properties = ossl_prop_defn_get(store->ctx, properties)) == NULL) {
impl->properties = ossl_parse_property(store->ctx, properties);
if (nid <= 0 || method == NULL || store == NULL)
return 0;
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
ossl_method_cache_flush(store, nid);
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL) {
int j, best = -1, score, optional;
#ifndef FIPS_MODULE
- OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+ if (!OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL))
+ return 0;
#endif
if (nid <= 0 || method == NULL || store == NULL)
* This only needs to be a read lock, because queries never create property
* names or value and thus don't modify any of the property string layer.
*/
- ossl_property_read_lock(store);
+ if (!ossl_property_read_lock(store))
+ return 0;
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL) {
ossl_property_unlock(store);
}
if (prop_query != NULL)
- p2 = pq = ossl_parse_query(store->ctx, prop_query);
- plp = ossl_ctx_global_properties(store->ctx, 1);
+ p2 = pq = ossl_parse_query(store->ctx, prop_query, 0);
+ plp = ossl_ctx_global_properties(store->ctx, 0);
if (plp != NULL && *plp != NULL) {
if (pq == NULL) {
pq = *plp;
}
}
-void ossl_method_store_flush_cache(OSSL_METHOD_STORE *store, int all)
+int ossl_method_store_flush_cache(OSSL_METHOD_STORE *store, int all)
{
void *arg = (all != 0 ? store->algs : NULL);
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
ossl_sa_ALGORITHM_doall_arg(store->algs, &impl_cache_flush_alg, arg);
store->nelem = 0;
ossl_property_unlock(store);
+ return 1;
}
IMPLEMENT_LHASH_DOALL_ARG(QUERY, IMPL_CACHE_FLUSH);
if (nid <= 0 || store == NULL)
return 0;
- ossl_property_read_lock(store);
+ if (!ossl_property_read_lock(store))
+ return 0;
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL)
goto err;
if (prop_query == NULL)
return 1;
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
if (store->need_flush)
ossl_method_cache_flush_some(store);
alg = ossl_method_store_retrieve(store, nid);