Hash functions.
Include: | #include <dmsdk/dlib/hash.h> |
TYPES | |
---|---|
dmhash_t | dmhash_t type definition |
STRUCTS | |
---|---|
struct HashState32 | Hash state used for 32-bit incremental hashing |
struct HashState64 | Hash state used for 64-bit incremental hashing |
void DM_HASH_REVERSE_MEM(symbol name, size_t size)
Allocate stack memory context for safely reversing hash values into strings
PARAMETERS
symbol |
name |
The name of the dmAllocator struct |
size_t |
size |
The max size of the stack allocated context |
uint32_t dmHashBuffer32(const void* buffer, uint32_t buffer_len)
Calculate 32-bit hash value from buffer
PARAMETERS
const void* |
buffer |
Buffer |
uint32_t |
buffer_len |
Length of buffer |
RETURNS
uint32_t |
hash value |
uint64_t dmHashBuffer64(const void* buffer, uint32_t buffer_len)
calculate 64-bit hash value from buffer
PARAMETERS
const void* |
buffer |
Buffer |
uint32_t |
buffer_len |
Length of buffer |
RETURNS
uint64_t |
hash value |
void dmHashClone32(HashState32* hash_state, HashState32* source_hash_state, bool reverse_hash)
Clone 32-bit incremental hash state
PARAMETERS
HashState32* |
hash_state |
Hash state |
HashState32* |
source_hash_state |
Source hash state |
bool |
reverse_hash |
true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH. Ignored if source state reverse hashing is disabled. |
void dmHashClone64(HashState64* hash_state, HashState64* source_hash_state, reverse_hash)
Clone 64-bit incremental hash state
PARAMETERS
HashState64* |
hash_state |
Hash state |
HashState64* |
source_hash_state |
Source hash state |
|
reverse_hash |
true bool to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH. Ignored if source state reverse hashing is disabled. |
uint32_t dmHashFinal32(HashState32* hash_state)
Finalize incremental hashing and release associated resources
PARAMETERS
HashState32* |
hash_state |
Hash state |
RETURNS
uint32_t |
the hash value |
uint64_t dmHashFinal64(HashState64* hash_state)
Finalize incremental hashing and release associated resources
PARAMETERS
HashState64* |
hash_state |
Hash state |
RETURNS
uint64_t |
The hash value |
void dmHashInit32(HashState32* hash_state, bool reverse_hash)
Initialize hash-state for 32-bit incremental hashing
PARAMETERS
HashState32* |
hash_state |
Hash state |
bool |
reverse_hash |
true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH |
void dmHashInit64(HashState64* hash_state, reverse_hash)
Initialize hash-state for 64-bit incremental hashing
PARAMETERS
HashState64* |
hash_state |
Hash state |
|
reverse_hash |
true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH |
void dmHashRelease32(HashState32* hash_state)
Release incremental hashing resources Used to release assocciated resources for intermediate incremental hash states.
PARAMETERS
HashState32* |
hash_state |
Hash state |
void dmHashRelease64(HashState64* hash_state)
Release incremental hashing resources Used to release assocciated resources for intermediate incremental hash states.
PARAMETERS
HashState64* |
hash_state |
Hash state |
const char* dmHashReverseSafe32(uint32_t hash)
Returns the original string used to produce a hash.
Always returns a null terminated string. Returns "
PARAMETERS
uint32_t |
hash |
hash value |
RETURNS
const char* |
Original string value or " |
const char* dmHashReverseSafe32(uint32_t hash, uint32_t* length)
Reverse hash lookup. Maps hash to original data. It is guaranteed that the returned buffer is null-terminated. If the buffer contains a valid c-string it can safely be used in printf and friends.
PARAMETERS
uint32_t |
hash |
hash to lookup |
uint32_t* |
length |
original data length. Optional argument and NULL-pointer is accepted. |
RETURNS
const char* |
pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled |
const char* dmHashReverseSafe32Alloc(dmAllocator* allocator, uint32_t hash)
Returns the original string used to produce a hash.
PARAMETERS
dmAllocator* |
allocator |
The reverse hash allocator |
uint32_t |
hash |
hash value |
RETURNS
const char* |
Original string value or " |
EXAMPLES
Get the string representaiton of a hash valueDM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe32Alloc(&hash_ctx, hash);
const char* dmHashReverseSafe64(uint64_t hash)
Returns the original string used to produce a hash.
Always returns a null terminated string. Returns "
PARAMETERS
uint64_t |
hash |
hash value |
RETURNS
const char* |
Original string value or " |
const char* dmHashReverseSafe64(uint64_t hash, uint32_t* length)
Reverse hash lookup. Maps hash to original data. It is guaranteed that the returned buffer is null-terminated. If the buffer contains a valid c-string it can safely be used in printf and friends.
PARAMETERS
uint64_t |
hash |
hash to lookup |
uint32_t* |
length |
original data length. Optional argument and NULL-pointer is accepted. |
RETURNS
const char* |
pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled |
const char* dmHashReverseSafe64Alloc(dmAllocator* allocator, uint64_t hash)
Returns the original string used to produce a hash.
PARAMETERS
dmAllocator* |
allocator |
The reverse hash allocator |
uint64_t |
hash |
hash value |
RETURNS
const char* |
Original string value or " |
EXAMPLES
Get the string representaiton of a hash valueDM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe64Alloc(&hash_ctx, hash);
uint32_t dmHashString32(const char* string)
Calculate 32-bit hash value from string
PARAMETERS
const char* |
string |
Null terminated string |
RETURNS
uint32_t |
hash value |
uint64_t dmHashString64(const char* string)
calculate 64-bit hash value from string
PARAMETERS
const char* |
string |
Null terminated string |
RETURNS
uint64_t |
hash value |
void dmHashUpdateBuffer32(HashState32* hash_state, const void* buffer, uint32_t buffer_len)
Incremental hashing
PARAMETERS
HashState32* |
hash_state |
Hash state |
const void* |
buffer |
Buffer |
uint32_t |
buffer_len |
Length of buffer |
void dmHashUpdateBuffer64(HashState64* hash_state, const void* buffer, uint32_t buffer_len)
Incremental hashing
PARAMETERS
HashState64* |
hash_state |
Hash state |
const void* |
buffer |
Buffer |
uint32_t |
buffer_len |
Length of buffer |
TYPE
struct HashState32
Hash state used for 32-bit incremental hashing
TYPE
struct HashState64
Hash state used for 64-bit incremental hashing
typedef uint64_t dmhash_t