[openssl] master update

Dr. Paul Dale pauli at openssl.org
Sat Jun 26 06:44:40 UTC 2021


The branch master has been updated
       via  92eb592b3b70a1f8e08b7160e54e367ba0d0aca2 (commit)
      from  56ba2b78eb68239166dc7e2373b34f3f10be7fc3 (commit)


- Log -----------------------------------------------------------------
commit 92eb592b3b70a1f8e08b7160e54e367ba0d0aca2
Author: Richard Levitte <levitte at openssl.org>
Date:   Thu Jun 24 18:44:26 2021 +0200

    ENCODER & DECODER: Allow en/decoders to have multiple names
    
    We had prepared for this a little bit, but apparently not completed it.
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15904)

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

Summary of changes:
 crypto/encode_decode/decoder_meth.c | 32 +++++++++++++++++++++++++++++---
 crypto/encode_decode/encoder_meth.c | 32 +++++++++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c
index 097605cfdc..8f0786c941 100644
--- a/crypto/encode_decode/decoder_meth.c
+++ b/crypto/encode_decode/decoder_meth.c
@@ -131,12 +131,25 @@ static void *get_decoder_from_store(void *store, void *data)
     void *method = NULL;
     int id;
 
-    if ((id = methdata->id) == 0) {
+    /*
+     * get_decoder_from_store() is only called to try and get the method
+     * that OSSL_DECODER_fetch() is asking for, and the name or name id are
+     * passed via methdata.
+     */
+    if ((id = methdata->id) == 0 && methdata->names != NULL) {
         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));
 
-        id = ossl_namemap_name2num(namemap, methdata->names);
+        if (namemap == 0)
+            return NULL;
+        id = ossl_namemap_name2num_n(namemap, names, l);
     }
 
+    if (id == 0)
+        return NULL;
+
     if (store == NULL
         && (store = get_decoder_store(methdata->libctx)) == NULL)
         return NULL;
@@ -154,9 +167,22 @@ static int put_decoder_in_store(void *store, void *method,
     struct decoder_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
     int id;
+    size_t l = 0;
+
+    /*
+     * put_decoder_in_store() is only called with an OSSL_DECODER method that
+     * was successfully created by construct_decoder() below, which means that
+     * all the names should already be stored in the namemap with the same
+     * numeric identity, so just use the first to get that identity.
+     */
+    if (names != NULL) {
+        const char *q = strchr(names, NAME_SEPARATOR);
+
+        l = (q == NULL ? strlen(names) : (size_t)(q - names));
+    }
 
     if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
-        || (id = ossl_namemap_name2num(namemap, names)) == 0)
+        || (id = ossl_namemap_name2num_n(namemap, names, l)) == 0)
         return 0;
 
     if (store == NULL && (store = get_decoder_store(methdata->libctx)) == NULL)
diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c
index 823def8843..9f7ecc82cb 100644
--- a/crypto/encode_decode/encoder_meth.c
+++ b/crypto/encode_decode/encoder_meth.c
@@ -131,12 +131,25 @@ static void *get_encoder_from_store(void *store, void *data)
     void *method = NULL;
     int id;
 
-    if ((id = methdata->id) == 0) {
+    /*
+     * get_encoder_from_store() is only called to try and get the method
+     * that OSSL_ENCODER_fetch() is asking for, and the name or name id are
+     * passed via methdata.
+     */
+    if ((id = methdata->id) == 0 && methdata->names != NULL) {
         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));
 
-        id = ossl_namemap_name2num(namemap, methdata->names);
+        if (namemap == 0)
+            return NULL;
+        id = ossl_namemap_name2num_n(namemap, methdata->names, l);
     }
 
+    if (id == 0)
+        return NULL;
+
     if (store == NULL
         && (store = get_encoder_store(methdata->libctx)) == NULL)
         return NULL;
@@ -154,9 +167,22 @@ static int put_encoder_in_store(void *store, void *method,
     struct encoder_data_st *methdata = data;
     OSSL_NAMEMAP *namemap;
     int id;
+    size_t l = 0;
+
+    /*
+     * put_encoder_in_store() is only called with an OSSL_ENCODER method that
+     * was successfully created by construct_encoder() below, which means that
+     * all the names should already be stored in the namemap with the same
+     * numeric identity, so just use the first to get that identity.
+     */
+    if (names != NULL) {
+        const char *q = strchr(names, NAME_SEPARATOR);
+
+        l = (q == NULL ? strlen(names) : (size_t)(q - names));
+    }
 
     if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
-        || (id = ossl_namemap_name2num(namemap, names)) == 0)
+        || (id = ossl_namemap_name2num_n(namemap, names, l)) == 0)
         return 0;
 
     if (store == NULL && (store = get_encoder_store(methdata->libctx)) == NULL)


More information about the openssl-commits mailing list