Repo-Init
 
Loading...
Searching...
No Matches
Hasher.hpp File Reference
#include <cstdint>
#include <cstdio>
Include dependency graph for Hasher.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

constexpr size_t constHasher (const char *s)
 
template<size_t N>
constexpr uint64_t constSeeder (const char(&entropy)[N], const uint64_t iv=0)
 

Function Documentation

◆ constHasher()

size_t constHasher ( const char * s)
constexpr

Calculates the compile-time hash value of a string.

Parameters
[in]sThe input string. Must be null-terminated.
Returns
The hash value of the input string.

Definition at line 13 of file Hasher.hpp.

13{ return (s && *s) ? (*s + 33 * constHasher(s + 1)) : 5381; }
constexpr size_t constHasher(const char *s)
Definition Hasher.hpp:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ constSeeder()

template<size_t N>
uint64_t constSeeder ( const char(&) entropy[N],
const uint64_t iv = 0 )
constexpr

Generates entropy using the input string and an initial value.

Parameters
[in]entropyThe input string used for generating entropy.
[in]ivThe initial value for the entropy generation.
Returns
The generated entropy value.

Definition at line 21 of file Hasher.hpp.

22{
23 auto value{iv};
24 for (size_t i{0}; i < N; i++)
25 {
26 // Xor 1st byte of seed with input byte
27 value = (value & (unsigned(~0) << 8)) | ((value & 0xFF) ^ entropy[i]);
28 // Rotl 1 byte
29 value = value << 8 | value >> ((sizeof(value) * 8) - 8);
30 }
31 return value ^ iv;
32}