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 RETURNS
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 RETURNS
Returns the original string used to produce a hash.
PARAMETERS RETURNS EXAMPLES
Returns the original string used to produce a hash.
Always returns a null terminated string. Returns " PARAMETERS RETURNS
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 RETURNS
Returns the original string used to produce a hash.
PARAMETERS RETURNS EXAMPLES
Calculate 32-bit hash value from string
PARAMETERS RETURNS
calculate 64-bit hash value from string
PARAMETERS RETURNS
Incremental hashing
PARAMETERS
Incremental hashing
PARAMETERS
TYPE Hash state used for 32-bit incremental hashing
TYPEuint32_t
hash
hash value
const char*
Original string value or "
dmHashReverseSafe32
const char* dmHashReverseSafe32(uint32_t hash, uint32_t* length)
uint32_t
hash
hash to lookup uint32_t*
length
original data length. Optional argument and NULL-pointer is accepted.
const char*
pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled
dmHashReverseSafe32Alloc
const char* dmHashReverseSafe32Alloc(dmAllocator* allocator, uint32_t hash)
dmAllocator*
allocator
The reverse hash allocator uint32_t
hash
hash value
const char*
Original string value or "
DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe32Alloc(&hash_ctx, hash);
dmHashReverseSafe64
const char* dmHashReverseSafe64(uint64_t hash)
uint64_t
hash
hash value
const char*
Original string value or "
dmHashReverseSafe64
const char* dmHashReverseSafe64(uint64_t hash, uint32_t* length)
uint64_t
hash
hash to lookup uint32_t*
length
original data length. Optional argument and NULL-pointer is accepted.
const char*
pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled
dmHashReverseSafe64Alloc
const char* dmHashReverseSafe64Alloc(dmAllocator* allocator, uint64_t hash)
dmAllocator*
allocator
The reverse hash allocator uint64_t
hash
hash value
const char*
Original string value or "
DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe64Alloc(&hash_ctx, hash);
dmHashString32
uint32_t dmHashString32(const char* string)
const char*
string
Null terminated string
uint32_t
hash value
dmHashString64
uint64_t dmHashString64(const char* string)
const char*
string
Null terminated string
uint64_t
hash value
dmHashUpdateBuffer32
void dmHashUpdateBuffer32(HashState32* hash_state, const void* buffer, uint32_t buffer_len)
HashState32*
hash_state
Hash state const void*
buffer
Buffer uint32_t
buffer_len
Length of buffer
dmHashUpdateBuffer64
void dmHashUpdateBuffer64(HashState64* hash_state, const void* buffer, uint32_t buffer_len)
HashState64*
hash_state
Hash state const void*
buffer
Buffer uint32_t
buffer_len
Length of buffer Structs
HashState32
struct HashState32
HashState64
struct HashState64
Hash state used for 64-bit incremental hashing
typedef uint64_t dmhash_t