Skip to content

Commit

Permalink
Expanding trace of providers algorithms fetching/caching/etc
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Jan 23, 2025
1 parent 8900cdf commit be2dfab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crypto/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "crypto/cryptlib.h"
#include <openssl/conf.h>
#include <openssl/trace.h>
#include "internal/thread_once.h"
#include "internal/property.h"
#include "internal/cryptlib.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ static int context_init(OSSL_LIB_CTX *ctx)
ctx->evp_method_store = ossl_method_store_new(ctx);
if (ctx->evp_method_store == NULL)
goto err;
OSSL_TRACE1(QUERY, "context_init: allocating store %p\n", ctx->evp_method_store);

#ifndef FIPS_MODULE
/* P2. Must be freed before the provider store is freed */
Expand Down
4 changes: 4 additions & 0 deletions crypto/core_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stddef.h>

#include <openssl/core.h>
#include <openssl/trace.h>
#include "internal/cryptlib.h"
#include "internal/core.h"
#include "internal/property.h"
Expand Down Expand Up @@ -110,6 +111,9 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
== NULL)
return;

OSSL_TRACE2(QUERY,
"ossl_method_construct_this: putting an algo to the store %p with no_store %d\n",
data->store, no_store);
/*
* Note regarding putting the method in stores:
*
Expand Down
17 changes: 16 additions & 1 deletion crypto/evp/evp_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ static void *get_tmp_evp_method_store(void *data)
{
struct evp_method_data_st *methdata = data;

if (methdata->tmp_store == NULL)
if (methdata->tmp_store == NULL) {
methdata->tmp_store = ossl_method_store_new(methdata->libctx);
OSSL_TRACE1(QUERY, "Allocating a new tmp_store %p\n", (void *)methdata->tmp_store);
} else {
OSSL_TRACE1(QUERY, "Using the existing tmp_store %p\n", (void *)methdata->tmp_store);
}
return methdata->tmp_store;
}

static void dealloc_tmp_evp_method_store(void *store)
{
OSSL_TRACE1(QUERY, "Deallocating the tmp_store %p\n", store);
if (store != NULL)
ossl_method_store_free(store);
}
Expand Down Expand Up @@ -184,10 +189,15 @@ static int put_evp_method_in_store(void *store, void *method,
|| (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
return 0;

OSSL_TRACE1(QUERY, "put_evp_method_in_store: original store: %p\n", store);
if (store == NULL
&& (store = get_evp_method_store(methdata->libctx)) == NULL)
return 0;

OSSL_TRACE5(QUERY,
"put_evp_method_in_store: "
"store: %p, names: %s, operation_id %d, method_id: %d, properties: %s\n",
store, names, methdata->operation_id, meth_id, propdef ? propdef : "<null>");
return ossl_method_store_add(store, prov, meth_id, propdef, method,
methdata->refcnt_up_method,
methdata->destruct_method);
Expand Down Expand Up @@ -357,6 +367,11 @@ inner_evp_generic_fetch(struct evp_method_data_st *methdata,
ossl_lib_ctx_get_descriptor(methdata->libctx),
name == NULL ? "<null>" : name, name_id,
properties == NULL ? "<null>" : properties);
} else {
OSSL_TRACE4(QUERY, "%s, Algorithm (%s : %d), Properties (%s)\n",
ossl_lib_ctx_get_descriptor(methdata->libctx),
name == NULL ? "<null>" : name, name_id,
properties == NULL ? "<null>" : properties);
}

return method;
Expand Down
4 changes: 4 additions & 0 deletions crypto/property/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov,
alg->nid = nid;
if (!ossl_method_store_insert(store, alg))
goto err;
OSSL_TRACE2(QUERY, "Inserted an alg with nid %d into the store %p\n", nid, store);
}

/* Push onto stack if there isn't one there already */
Expand Down Expand Up @@ -639,11 +640,14 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store,
if (!ossl_property_read_lock(store))
return 0;

OSSL_TRACE2(QUERY, "Retrieving by nid %d from store %p\n", nid, store);
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL) {
ossl_property_unlock(store);
OSSL_TRACE2(QUERY, "Failed to retrieve by nid %d from store %p\n", nid, store);
return 0;
}
OSSL_TRACE2(QUERY, "Retrieved by nid %d from store %p\n", nid, store);

/*
* If a property query string is provided, convert it to an
Expand Down

0 comments on commit be2dfab

Please sign in to comment.