1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 04:24:59 +00:00
serenity/Userland/Libraries/LibELF/Hashes.h
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

44 lines
831 B
C++

/*
* Copyright (c) 2019-2020, Andrew Kaster <andrewdkaster@gmail.com>
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/StringView.h>
namespace ELF {
constexpr u32 compute_sysv_hash(const StringView& name)
{
// SYSV ELF hash algorithm
// Note that the GNU HASH algorithm has less collisions
u32 hash = 0;
for (auto ch : name) {
hash = hash << 4;
hash += ch;
const u32 top_nibble_of_hash = hash & 0xf0000000u;
hash ^= top_nibble_of_hash >> 24;
hash &= ~top_nibble_of_hash;
}
return hash;
}
constexpr u32 compute_gnu_hash(const StringView& name)
{
// GNU ELF hash algorithm
u32 hash = 5381;
for (auto ch : name)
hash = hash * 33 + ch;
return hash;
}
}