128ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper/* GNU-style Hash function used in ELF implementations.
21ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaard   Copyright (C) 2006, 2015 Red Hat, Inc.
3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is part of elfutils.
428ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper   Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
528ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is free software; you can redistribute it and/or modify
7de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   it under the terms of either
828ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU Lesser General Public License as published by the Free
10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 3 of the License, or (at
11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or
14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU General Public License as published by the Free
16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 2 of the License, or (at
17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or both in parallel, as here.
20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
21de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   elfutils is distributed in the hope that it will be useful, but
2228ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
2328ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2428ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper   General Public License for more details.
2528ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   You should have received copies of the GNU General Public License and
27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   the GNU Lesser General Public License along with this program.  If
28de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   not, see <http://www.gnu.org/licenses/>.  */
2928ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
3028ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper#ifdef HAVE_CONFIG_H
3128ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper# include <config.h>
3228ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper#endif
3328ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
3428ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper#include <libelfP.h>
3528ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
3628ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper/* Get the implementation.  */
3728ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper#include <dl-hash.h>
3828ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
3928ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepperunsigned long int
401ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaardelf_gnu_hash (const char *string)
4128ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper{
4228ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper  uint_fast32_t h = 5381;
4328ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper  for (unsigned char c = *string; c != '\0'; c = *++string)
4428ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper    h = h * 33 + c;
4528ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper  return h & 0xffffffff;
4628ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper}
47