-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathhash.hpp
More file actions
86 lines (71 loc) · 2.16 KB
/
hash.hpp
File metadata and controls
86 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef HASHING_HPP
#define HASHING_HPP
#include <cstdint>
#include <string>
#include <bit>
namespace syscall::hashing
{
using Hash_t = uint64_t;
constexpr Hash_t getCompileTimeSeed()
{
Hash_t seed = 0;
const char* szCurrentTime = __TIME__;
const char* szCurrentDate = __DATE__;
for (int i = 0; szCurrentTime[i] != '\0'; ++i)
seed = std::rotr(seed, 3) + szCurrentTime[i];
for (int i = 0; szCurrentDate[i] != '\0'; ++i)
seed = std::rotr(seed, 5) + szCurrentDate[i];
return seed;
}
constexpr Hash_t currentSeed = getCompileTimeSeed();
constexpr Hash_t polyKey1 = 0xAF6F01BD5B2D7583ULL ^ currentSeed;
constexpr Hash_t polyKey2 = 0xB4F281729182741DULL ^ std::rotr(currentSeed, 7);
consteval Hash_t calculateHash(const char* szData)
{
Hash_t hash = polyKey1;
while (*szData)
{
hash ^= static_cast<Hash_t>(*szData++);
hash += std::rotr(hash, 11) + polyKey2;
}
return hash;
}
consteval Hash_t calculateHash(const char* szData, size_t uLength)
{
Hash_t hash = polyKey1;
for (size_t i = 0; i < uLength && szData[i]; ++i)
{
hash ^= static_cast<Hash_t>(szData[i]);
hash += std::rotr(hash, 11) + polyKey2;
}
return hash;
}
inline Hash_t calculateHashRuntime(const char* szData)
{
Hash_t hash = polyKey1;
while (*szData)
{
hash ^= static_cast<Hash_t>(*szData++);
hash += std::rotr(hash, 11) + polyKey2;
}
return hash;
}
inline Hash_t calculateHashRuntime(const char* szData, size_t uLength)
{
Hash_t hash = polyKey1;
for (size_t i = 0; i < uLength && szData[i]; ++i)
{
hash ^= static_cast<Hash_t>(szData[i]);
hash += std::rotr(hash, 11) + polyKey2;
}
return hash;
}
}
#ifdef SYSCALLS_NO_HASH
#define SYSCALL_ID(str) (str)
#define SYSCALL_ID_RT(str) (str)
#else
#define SYSCALL_ID(str) (syscall::hashing::calculateHash(str))
#define SYSCALL_ID_RT(str) (syscall::hashing::calculateHashRuntime(str))
#endif
#endif