diff options
author | Pauli <paul.dale@oracle.com> | 2018-09-04 07:35:45 +1000 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2018-09-04 07:35:45 +1000 |
commit | fc196a5eb97dc3a5465c37a6761428ddd81b023d (patch) | |
tree | 47b5116217bcab42d2b3e6fa1084cd67d7332480 /crypto | |
parent | 2d28a42f899c2f5e03b0e49a660ed3c1f744e7a3 (diff) |
Make OBJ_NAME case insensitive.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7089)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/include/internal/lhash.h | 15 | ||||
-rw-r--r-- | crypto/lhash/lhash.c | 23 | ||||
-rw-r--r-- | crypto/objects/o_names.c | 29 |
3 files changed, 52 insertions, 15 deletions
diff --git a/crypto/include/internal/lhash.h b/crypto/include/internal/lhash.h new file mode 100644 index 0000000000..200ba8685d --- /dev/null +++ b/crypto/include/internal/lhash.h @@ -0,0 +1,15 @@ +/* + * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef INTERNAL_LHASH_H +# define INTERNAL_LHASH_H + +unsigned long openssl_lh_strcasehash(const char *); + +#endif diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index f7ac9d02f5..8d9f933df3 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -13,6 +13,8 @@ #include <openssl/crypto.h> #include <openssl/lhash.h> #include <openssl/err.h> +#include "internal/ctype.h" +#include "internal/lhash.h" #include "lhash_lcl.h" /* @@ -349,6 +351,27 @@ unsigned long OPENSSL_LH_strhash(const char *c) return (ret >> 16) ^ ret; } +unsigned long openssl_lh_strcasehash(const char *c) +{ + unsigned long ret = 0; + long n; + unsigned long v; + int r; + + if (c == NULL || *c == '\0') + return ret; + + for (n = 0x100; *c != '\0'; n += 0x100) { + v = n | ossl_tolower(*c); + r = (int)((v >> 2) ^ v) & 0x0f; + ret = (ret << r) | (ret >> (32 - r)); + ret &= 0xFFFFFFFFL; + ret ^= v * v; + c++; + } + return (ret >> 16) ^ ret; +} + unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh) { return lh ? lh->num_items : 0; diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c index 8f7bc79346..c4355370cb 100644 --- a/crypto/objects/o_names.c +++ b/crypto/objects/o_names.c @@ -17,26 +17,25 @@ #include <openssl/safestack.h> #include <openssl/e_os2.h> #include "internal/thread_once.h" +#include "internal/lhash.h" #include "obj_lcl.h" +#include "e_os.h" /* * We define this wrapper for two reasons. Firstly, later versions of * DEC C add linkage information to certain functions, which makes it * tricky to use them as values to regular function pointers. - * Secondly, in the EDK2 build environment, the strcmp function is - * actually an external function (AsciiStrCmp) with the Microsoft ABI, - * so we can't transparently assign function pointers to it. - * Arguably the latter is a stupidity of the UEFI environment, but - * since the wrapper solves the DEC C issue too, let's just use the - * same solution. + * Secondly, in the EDK2 build environment, the strcasecmp function is + * actually an external function with the Microsoft ABI, so we can't + * transparently assign function pointers to it. */ #if defined(OPENSSL_SYS_VMS_DECC) || defined(OPENSSL_SYS_UEFI) -static int obj_strcmp(const char *a, const char *b) +static int obj_strcasecmp(const char *a, const char *b) { - return strcmp(a, b); + return strcasecmp(a, b); } #else -#define obj_strcmp strcmp +#define obj_strcasecmp strcasecmp #endif /* @@ -111,8 +110,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), ret = 0; goto out; } - name_funcs->hash_func = OPENSSL_LH_strhash; - name_funcs->cmp_func = obj_strcmp; + name_funcs->hash_func = openssl_lh_strcasehash; + name_funcs->cmp_func = obj_strcasecmp; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs); @@ -149,7 +148,7 @@ static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b) ret = sk_NAME_FUNCS_value(name_funcs_stack, a->type)->cmp_func(a->name, b->name); } else - ret = strcmp(a->name, b->name); + ret = strcasecmp(a->name, b->name); } return ret; } @@ -164,7 +163,7 @@ static unsigned long obj_name_hash(const OBJ_NAME *a) sk_NAME_FUNCS_value(name_funcs_stack, a->type)->hash_func(a->name); } else { - ret = OPENSSL_LH_strhash(a->name); + ret = openssl_lh_strcasehash(a->name); } ret ^= a->type; return ret; @@ -214,8 +213,6 @@ int OBJ_NAME_add(const char *name, int type, const char *data) if (!OBJ_NAME_init()) return 0; - CRYPTO_THREAD_write_lock(obj_lock); - alias = type & OBJ_NAME_ALIAS; type &= ~OBJ_NAME_ALIAS; @@ -230,6 +227,8 @@ int OBJ_NAME_add(const char *name, int type, const char *data) onp->type = type; onp->data = data; + CRYPTO_THREAD_write_lock(obj_lock); + ret = lh_OBJ_NAME_insert(names_lh, onp); if (ret != NULL) { /* free things */ |