Latest update.

This commit is contained in:
2019-05-23 12:02:56 +09:00
parent a7bf77581f
commit 64d458de91
185 changed files with 5859 additions and 2853 deletions
+27 -34
View File
@@ -47,6 +47,7 @@ typedef struct {
} ALGORITHM;
struct ossl_method_store_st {
OPENSSL_CTX *ctx;
size_t nelem;
SPARSE_ARRAY_OF(ALGORITHM) *algs;
OSSL_PROPERTY_LIST *global_properties;
@@ -82,29 +83,10 @@ int ossl_property_unlock(OSSL_METHOD_STORE *p)
return p != 0 ? CRYPTO_THREAD_unlock(p->lock) : 0;
}
int ossl_method_store_init(void)
static openssl_ctx_run_once_fn do_method_store_init;
int do_method_store_init(OPENSSL_CTX *ctx)
{
if (ossl_property_string_init()
&& ossl_prop_defn_init()
&& ossl_property_parse_init())
return 1;
ossl_method_store_cleanup();
return 0;
}
void ossl_method_store_cleanup(void)
{
ossl_property_string_cleanup();
ossl_prop_defn_cleanup();
}
static CRYPTO_ONCE method_store_init_flag = CRYPTO_ONCE_STATIC_INIT;
DEFINE_RUN_ONCE_STATIC(do_method_store_init)
{
return OPENSSL_init_crypto(0, NULL)
&& ossl_method_store_init()
&& OPENSSL_atexit(&ossl_method_store_cleanup);
return ossl_property_parse_init(ctx);
}
static unsigned long query_hash(const QUERY *a)
@@ -141,15 +123,22 @@ static void alg_cleanup(ossl_uintmax_t idx, ALGORITHM *a)
}
}
OSSL_METHOD_STORE *ossl_method_store_new(void)
/*
* The OPENSSL_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 *res;
if (!RUN_ONCE(&method_store_init_flag, do_method_store_init))
return 0;
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;
if ((res->algs = ossl_sa_ALGORITHM_new()) == NULL) {
OPENSSL_free(res);
return NULL;
@@ -212,10 +201,11 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store,
*/
ossl_property_write_lock(store);
ossl_method_cache_flush(store, nid);
if ((impl->properties = ossl_prop_defn_get(properties)) == NULL) {
if ((impl->properties = ossl_parse_property(properties)) == NULL)
if ((impl->properties = ossl_prop_defn_get(store->ctx, properties)) == NULL) {
impl->properties = ossl_parse_property(store->ctx, properties);
if (impl->properties == NULL)
goto err;
ossl_prop_defn_set(properties, impl->properties);
ossl_prop_defn_set(store->ctx, properties, impl->properties);
}
alg = ossl_method_store_retrieve(store, nid);
@@ -287,7 +277,7 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid,
IMPLEMENTATION *impl;
OSSL_PROPERTY_LIST *pq = NULL, *p2;
int ret = 0;
int j;
int j, best = -1, score, optional;
if (nid <= 0 || method == NULL || store == NULL)
return 0;
@@ -310,7 +300,7 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid,
}
goto fin;
}
pq = ossl_parse_query(prop_query);
pq = ossl_parse_query(store->ctx, prop_query);
if (pq == NULL)
goto fin;
if (store->global_properties != NULL) {
@@ -320,13 +310,16 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid,
ossl_property_free(pq);
pq = p2;
}
optional = ossl_property_has_optional(pq);
for (j = 0; j < sk_IMPLEMENTATION_num(alg->impls); j++) {
impl = sk_IMPLEMENTATION_value(alg->impls, j);
if (ossl_property_match(pq, impl->properties)) {
score = ossl_property_match_count(pq, impl->properties);
if (score > best) {
*method = impl->method;
ret = 1;
goto fin;
if (!optional)
goto fin;
best = score;
}
}
fin:
@@ -350,7 +343,7 @@ int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store,
ossl_property_unlock(store);
return 1;
}
store->global_properties = ossl_parse_query(prop_query);
store->global_properties = ossl_parse_query(store->ctx, prop_query);
ret = store->global_properties != NULL;
ossl_property_unlock(store);
return ret;