[openssl] master update

Matt Caswell matt at openssl.org
Wed Jun 16 12:00:18 UTC 2021


The branch master has been updated
       via  6882652e65d39310c98ba506ceb55a87c702d419 (commit)
      from  99325852207e3f8ae970799235de169b40eded75 (commit)


- Log -----------------------------------------------------------------
commit 6882652e65d39310c98ba506ceb55a87c702d419
Author: Richard Levitte <levitte at openssl.org>
Date:   Tue Jun 15 10:18:19 2021 +0200

    CORE: Do a bit of cleanup of core fetching
    
    Some data, like the library context, were passed both through higher
    level callback structures and through arguments to those same higher
    level callbacks.  This is a bit unnecessary, so we rearrange the
    callback arguments to simply pass that callback structure and rely on
    the higher level fetching functionality to pick out what data they
    need from that structure.
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15750)

-----------------------------------------------------------------------

Summary of changes:
 crypto/core_fetch.c                 | 14 +++++---------
 crypto/encode_decode/decoder_meth.c | 22 ++++++++++------------
 crypto/encode_decode/encoder_meth.c | 22 ++++++++++------------
 crypto/evp/evp_fetch.c              | 23 ++++++++++-------------
 crypto/store/store_meth.c           | 22 ++++++++++------------
 include/internal/core.h             |  7 +++----
 6 files changed, 48 insertions(+), 62 deletions(-)

diff --git a/crypto/core_fetch.c b/crypto/core_fetch.c
index fade75f4c9..d315599ce6 100644
--- a/crypto/core_fetch.c
+++ b/crypto/core_fetch.c
@@ -84,8 +84,7 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
 
     if (data->force_store || !no_store) {
         /* If we haven't been told not to store, add to the global store */
-        data->mcm->put(data->libctx, NULL, method, provider,
-                       data->operation_id, algo->algorithm_names,
+        data->mcm->put(NULL, method, provider, algo->algorithm_names,
                        algo->property_definition, data->mcm_data);
     } else {
         /*
@@ -97,8 +96,7 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
         if ((data->store = data->mcm->get_tmp_store(data->mcm_data)) == NULL)
             return;
 
-        data->mcm->put(data->libctx, data->store, method, provider,
-                       data->operation_id, algo->algorithm_names,
+        data->mcm->put(data->store, method, provider, algo->algorithm_names,
                        algo->property_definition, data->mcm_data);
     }
 
@@ -112,12 +110,10 @@ void *ossl_method_construct(OSSL_LIB_CTX *libctx, int operation_id,
 {
     void *method = NULL;
 
-    if ((method = mcm->get(libctx, NULL, mcm_data)) == NULL) {
+    if ((method = mcm->get(NULL, mcm_data)) == NULL) {
         struct construct_data_st cbdata;
 
-        cbdata.libctx = libctx;
         cbdata.store = NULL;
-        cbdata.operation_id = operation_id;
         cbdata.force_store = force_store;
         cbdata.mcm = mcm;
         cbdata.mcm_data = mcm_data;
@@ -129,11 +125,11 @@ void *ossl_method_construct(OSSL_LIB_CTX *libctx, int operation_id,
 
         /* If there is a temporary store, try there first */
         if (cbdata.store != NULL)
-            method = mcm->get(libctx, cbdata.store, mcm_data);
+            method = mcm->get(cbdata.store, mcm_data);
 
         /* If no method was found yet, try the global store */
         if (method == NULL)
-            method = mcm->get(libctx, NULL, mcm_data);
+            method = mcm->get(NULL, mcm_data);
     }
 
     return method;
diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c
index 0ec886bb29..097605cfdc 100644
--- a/crypto/encode_decode/decoder_meth.c
+++ b/crypto/encode_decode/decoder_meth.c
@@ -87,7 +87,6 @@ static const OSSL_LIB_CTX_METHOD decoder_store_method = {
 /* Data to be passed through ossl_method_construct() */
 struct decoder_data_st {
     OSSL_LIB_CTX *libctx;
-    OSSL_METHOD_CONSTRUCT_METHOD *mcm;
     int id;                      /* For get_decoder_from_store() */
     const char *names;           /* For get_decoder_from_store() */
     const char *propquery;       /* For get_decoder_from_store() */
@@ -126,21 +125,20 @@ static OSSL_METHOD_STORE *get_decoder_store(OSSL_LIB_CTX *libctx)
 }
 
 /* Get decoder methods from a store, or put one in */
-static void *get_decoder_from_store(OSSL_LIB_CTX *libctx, void *store,
-                                    void *data)
+static void *get_decoder_from_store(void *store, void *data)
 {
     struct decoder_data_st *methdata = data;
     void *method = NULL;
     int id;
 
     if ((id = methdata->id) == 0) {
-        OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+        OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
 
         id = ossl_namemap_name2num(namemap, methdata->names);
     }
 
     if (store == NULL
-        && (store = get_decoder_store(libctx)) == NULL)
+        && (store = get_decoder_store(methdata->libctx)) == NULL)
         return NULL;
 
     if (!ossl_method_store_fetch(store, id, methdata->propquery, &method))
@@ -148,19 +146,20 @@ static void *get_decoder_from_store(OSSL_LIB_CTX *libctx, void *store,
     return method;
 }
 
-static int put_decoder_in_store(OSSL_LIB_CTX *libctx, void *store,
-                                void *method, const OSSL_PROVIDER *prov,
-                                int operation_id, const char *names,
-                                const char *propdef, void *unused)
+static int put_decoder_in_store(void *store, void *method,
+                                const OSSL_PROVIDER *prov,
+                                const char *names, const char *propdef,
+                                void *data)
 {
+    struct decoder_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
     int id;
 
-    if ((namemap = ossl_namemap_stored(libctx)) == NULL
+    if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
         || (id = ossl_namemap_name2num(namemap, names)) == 0)
         return 0;
 
-    if (store == NULL && (store = get_decoder_store(libctx)) == NULL)
+    if (store == NULL && (store = get_decoder_store(methdata->libctx)) == NULL)
         return 0;
 
     return ossl_method_store_add(store, prov, id, propdef, method,
@@ -350,7 +349,6 @@ inner_ossl_decoder_fetch(struct decoder_data_st *methdata, int id,
             destruct_decoder
         };
 
-        methdata->mcm = &mcm;
         methdata->id = id;
         methdata->names = name;
         methdata->propquery = properties;
diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c
index 9c17b3637e..823def8843 100644
--- a/crypto/encode_decode/encoder_meth.c
+++ b/crypto/encode_decode/encoder_meth.c
@@ -87,7 +87,6 @@ static const OSSL_LIB_CTX_METHOD encoder_store_method = {
 /* Data to be passed through ossl_method_construct() */
 struct encoder_data_st {
     OSSL_LIB_CTX *libctx;
-    OSSL_METHOD_CONSTRUCT_METHOD *mcm;
     int id;                      /* For get_encoder_from_store() */
     const char *names;           /* For get_encoder_from_store() */
     const char *propquery;       /* For get_encoder_from_store() */
@@ -126,21 +125,20 @@ static OSSL_METHOD_STORE *get_encoder_store(OSSL_LIB_CTX *libctx)
 }
 
 /* Get encoder methods from a store, or put one in */
-static void *get_encoder_from_store(OSSL_LIB_CTX *libctx, void *store,
-                                    void *data)
+static void *get_encoder_from_store(void *store, void *data)
 {
     struct encoder_data_st *methdata = data;
     void *method = NULL;
     int id;
 
     if ((id = methdata->id) == 0) {
-        OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+        OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
 
         id = ossl_namemap_name2num(namemap, methdata->names);
     }
 
     if (store == NULL
-        && (store = get_encoder_store(libctx)) == NULL)
+        && (store = get_encoder_store(methdata->libctx)) == NULL)
         return NULL;
 
     if (!ossl_method_store_fetch(store, id, methdata->propquery, &method))
@@ -148,19 +146,20 @@ static void *get_encoder_from_store(OSSL_LIB_CTX *libctx, void *store,
     return method;
 }
 
-static int put_encoder_in_store(OSSL_LIB_CTX *libctx, void *store,
-                                void *method, const OSSL_PROVIDER *prov,
-                                int operation_id, const char *names,
-                                const char *propdef, void *unused)
+static int put_encoder_in_store(void *store, void *method,
+                                const OSSL_PROVIDER *prov,
+                                const char *names, const char *propdef,
+                                void *data)
 {
+    struct encoder_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
     int id;
 
-    if ((namemap = ossl_namemap_stored(libctx)) == NULL
+    if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
         || (id = ossl_namemap_name2num(namemap, names)) == 0)
         return 0;
 
-    if (store == NULL && (store = get_encoder_store(libctx)) == NULL)
+    if (store == NULL && (store = get_encoder_store(methdata->libctx)) == NULL)
         return 0;
 
     return ossl_method_store_add(store, prov, id, propdef, method,
@@ -360,7 +359,6 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id,
             destruct_encoder
         };
 
-        methdata->mcm = &mcm;
         methdata->id = id;
         methdata->names = name;
         methdata->propquery = properties;
diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c
index 2ad9bf7dca..3067928030 100644
--- a/crypto/evp/evp_fetch.c
+++ b/crypto/evp/evp_fetch.c
@@ -44,7 +44,6 @@ static const OSSL_LIB_CTX_METHOD evp_method_store_method = {
 /* Data to be passed through ossl_method_construct() */
 struct evp_method_data_st {
     OSSL_LIB_CTX *libctx;
-    OSSL_METHOD_CONSTRUCT_METHOD *mcm;
     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() */
@@ -116,8 +115,7 @@ static uint32_t evp_method_id(int name_id, unsigned int operation_id)
             | (operation_id & METHOD_ID_OPERATION_MASK));
 }
 
-static void *get_evp_method_from_store(OSSL_LIB_CTX *libctx, void *store,
-                                       void *data)
+static void *get_evp_method_from_store(void *store, void *data)
 {
     struct evp_method_data_st *methdata = data;
     void *method = NULL;
@@ -130,7 +128,7 @@ static void *get_evp_method_from_store(OSSL_LIB_CTX *libctx, void *store,
      * as the name or name id are passed via methdata.
      */
     if ((name_id = methdata->name_id) == 0 && methdata->names != NULL) {
-        OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+        OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
         const char *names = methdata->names;
         const char *q = strchr(names, NAME_SEPARATOR);
         size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
@@ -145,7 +143,7 @@ static void *get_evp_method_from_store(OSSL_LIB_CTX *libctx, void *store,
         return NULL;
 
     if (store == NULL
-        && (store = get_evp_method_store(libctx)) == NULL)
+        && (store = get_evp_method_store(methdata->libctx)) == NULL)
         return NULL;
 
     if (!ossl_method_store_fetch(store, meth_id, methdata->propquery,
@@ -154,10 +152,10 @@ static void *get_evp_method_from_store(OSSL_LIB_CTX *libctx, void *store,
     return method;
 }
 
-static int put_evp_method_in_store(OSSL_LIB_CTX *libctx, void *store,
-                                   void *method, const OSSL_PROVIDER *prov,
-                                   int operation_id, const char *names,
-                                   const char *propdef, void *data)
+static int put_evp_method_in_store(void *store, void *method,
+                                   const OSSL_PROVIDER *prov,
+                                   const char *names, const char *propdef,
+                                   void *data)
 {
     struct evp_method_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
@@ -177,13 +175,13 @@ static int put_evp_method_in_store(OSSL_LIB_CTX *libctx, void *store,
         l = (q == NULL ? strlen(names) : (size_t)(q - names));
     }
 
-    if ((namemap = ossl_namemap_stored(libctx)) == NULL
+    if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
         || (name_id = ossl_namemap_name2num_n(namemap, names, l)) == 0
-        || (meth_id = evp_method_id(name_id, operation_id)) == 0)
+        || (meth_id = evp_method_id(name_id, methdata->operation_id)) == 0)
         return 0;
 
     if (store == NULL
-        && (store = get_evp_method_store(libctx)) == NULL)
+        && (store = get_evp_method_store(methdata->libctx)) == NULL)
         return 0;
 
     return ossl_method_store_add(store, prov, meth_id, propdef, method,
@@ -308,7 +306,6 @@ inner_evp_generic_fetch(struct evp_method_data_st *methdata, int operation_id,
             destruct_evp_method
         };
 
-        methdata->mcm = &mcm;
         methdata->operation_id = operation_id;
         methdata->name_id = name_id;
         methdata->names = name;
diff --git a/crypto/store/store_meth.c b/crypto/store/store_meth.c
index 720b70c0e0..e316f4f139 100644
--- a/crypto/store/store_meth.c
+++ b/crypto/store/store_meth.c
@@ -90,7 +90,6 @@ static const OSSL_LIB_CTX_METHOD loader_store_method = {
 /* Data to be passed through ossl_method_construct() */
 struct loader_data_st {
     OSSL_LIB_CTX *libctx;
-    OSSL_METHOD_CONSTRUCT_METHOD *mcm;
     int scheme_id;               /* For get_loader_from_store() */
     const char *scheme;          /* For get_loader_from_store() */
     const char *propquery;       /* For get_loader_from_store() */
@@ -129,21 +128,20 @@ static OSSL_METHOD_STORE *get_loader_store(OSSL_LIB_CTX *libctx)
 }
 
 /* Get loader methods from a store, or put one in */
-static void *get_loader_from_store(OSSL_LIB_CTX *libctx, void *store,
-                                   void *data)
+static void *get_loader_from_store(void *store, void *data)
 {
     struct loader_data_st *methdata = data;
     void *method = NULL;
     int id;
 
     if ((id = methdata->scheme_id) == 0) {
-        OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+        OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
 
         id = ossl_namemap_name2num(namemap, methdata->scheme);
     }
 
     if (store == NULL
-        && (store = get_loader_store(libctx)) == NULL)
+        && (store = get_loader_store(methdata->libctx)) == NULL)
         return NULL;
 
     if (!ossl_method_store_fetch(store, id, methdata->propquery, &method))
@@ -151,19 +149,20 @@ static void *get_loader_from_store(OSSL_LIB_CTX *libctx, void *store,
     return method;
 }
 
-static int put_loader_in_store(OSSL_LIB_CTX *libctx, void *store,
-                               void *method, const OSSL_PROVIDER *prov,
-                               int operation_id, const char *scheme,
-                               const char *propdef, void *unused)
+static int put_loader_in_store(void *store, void *method,
+                               const OSSL_PROVIDER *prov,
+                               const char *scheme, const char *propdef,
+                               void *data)
 {
+    struct loader_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
     int id;
 
-    if ((namemap = ossl_namemap_stored(libctx)) == NULL
+    if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
         || (id = ossl_namemap_name2num(namemap, scheme)) == 0)
         return 0;
 
-    if (store == NULL && (store = get_loader_store(libctx)) == NULL)
+    if (store == NULL && (store = get_loader_store(methdata->libctx)) == NULL)
         return 0;
 
     return ossl_method_store_add(store, prov, id, propdef, method,
@@ -318,7 +317,6 @@ inner_loader_fetch(struct loader_data_st *methdata, int id,
             destruct_loader
         };
 
-        methdata->mcm = &mcm;
         methdata->scheme_id = id;
         methdata->scheme = scheme;
         methdata->propquery = properties;
diff --git a/include/internal/core.h b/include/internal/core.h
index d8395a2c92..035b726894 100644
--- a/include/internal/core.h
+++ b/include/internal/core.h
@@ -31,11 +31,10 @@ typedef struct ossl_method_construct_method_st {
     /* Get a temporary store */
     void *(*get_tmp_store)(void *data);
     /* Get an already existing method from a store */
-    void *(*get)(OSSL_LIB_CTX *libctx, void *store, void *data);
+    void *(*get)(void *store, void *data);
     /* Store a method in a store */
-    int (*put)(OSSL_LIB_CTX *libctx, void *store, void *method,
-               const OSSL_PROVIDER *prov, int operation_id, const char *name,
-               const char *propdef, void *data);
+    int (*put)(void *store, void *method, const OSSL_PROVIDER *prov,
+               const char *name, const char *propdef, void *data);
     /* Construct a new method */
     void *(*construct)(const OSSL_ALGORITHM *algodef, OSSL_PROVIDER *prov,
                        void *data);


More information about the openssl-commits mailing list