From 67f36c7922fe5053549ec9aa7f60ed2c5c2d65b4 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 23 Nov 2017 14:08:11 +0100 Subject: nss: Export nscd hash function as __nss_hash [BZ #22459] --- nss/Makefile | 2 +- nss/Versions | 1 + nss/nss_hash.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 nss/nss_hash.c (limited to 'nss') diff --git a/nss/Makefile b/nss/Makefile index 26952112c1..f9ecea56a0 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -28,7 +28,7 @@ headers := nss.h routines = nsswitch getnssent getnssent_r digits_dots \ valid_field valid_list_field rewrite_field \ $(addsuffix -lookup,$(databases)) \ - compat-lookup + compat-lookup nss_hash # These are the databases that go through nss dispatch. # Caution: if you add a database here, you must add its real name diff --git a/nss/Versions b/nss/Versions index 7694998f1d..db8c887720 100644 --- a/nss/Versions +++ b/nss/Versions @@ -15,6 +15,7 @@ libc { __nss_passwd_lookup2; __nss_group_lookup2; __nss_hosts_lookup2; __nss_services_lookup2; __nss_next2; __nss_lookup; + __nss_hash; } } diff --git a/nss/nss_hash.c b/nss/nss_hash.c new file mode 100644 index 0000000000..5fb837a381 --- /dev/null +++ b/nss/nss_hash.c @@ -0,0 +1,79 @@ +/* Copyright (c) 1997-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Thorsten Kukuk , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* This is from libc/db/hash/hash_func.c, hash3 is static there */ +/* + * This is INCREDIBLY ugly, but fast. We break the string up into 8 byte + * units. On the first time through the loop we get the "leftover bytes" + * (strlen % 8). On every other iteration, we perform 8 HASHC's so we handle + * all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If + * this routine is heavily used enough, it's worth the ugly coding. + * + * OZ's original sdbm hash + */ +uint32_t +__nss_hash (const void *keyarg, size_t len) +{ + const unsigned char *key; + size_t loop; + uint32_t h; + +#define HASHC h = *key++ + 65599 * h + + h = 0; + key = keyarg; + if (len > 0) + { + loop = (len + 8 - 1) >> 3; + switch (len & (8 - 1)) + { + case 0: + do + { + HASHC; + /* FALLTHROUGH */ + case 7: + HASHC; + /* FALLTHROUGH */ + case 6: + HASHC; + /* FALLTHROUGH */ + case 5: + HASHC; + /* FALLTHROUGH */ + case 4: + HASHC; + /* FALLTHROUGH */ + case 3: + HASHC; + /* FALLTHROUGH */ + case 2: + HASHC; + /* FALLTHROUGH */ + case 1: + HASHC; + } + while (--loop); + } + } + return h; +} + +libc_hidden_def (__nss_hash) -- cgit v1.2.3-65-gdbad