Sdk hash api documentation

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
FUNCTIONS
void DM_HASH_REVERSE_MEM(symbol name, size_t size) Allocate stack memory context for safely reversing...
uint32_t dmHashBuffer32(const void* buffer, uint32_t buffer_len) Calculate 32-bit hash value from buffer
uint64_t dmHashBuffer64(const void* buffer, uint32_t buffer_len) calculate 64-bit hash value from buffer
void dmHashClone32(HashState32* hash_state, HashState32* source_hash_state, bool reverse_hash) Clone 32-bit incremental hash state
void dmHashClone64(HashState64* hash_state, HashState64* source_hash_state,  reverse_hash) Clone 64-bit incremental hash state
uint32_t dmHashFinal32(HashState32* hash_state) Finalize incremental hashing and release associate...
uint64_t dmHashFinal64(HashState64* hash_state) Finalize incremental hashing and release associate...
void dmHashInit32(HashState32* hash_state, bool reverse_hash) Initialize hash-state for 32-bit incremental hashi...
void dmHashInit64(HashState64* hash_state,  reverse_hash) Initialize hash-state for 64-bit incremental hashi...
void dmHashRelease32(HashState32* hash_state) Release incremental hashing resources Used to rele...
void dmHashRelease64(HashState64* hash_state) Release incremental hashing resources Used to rele...
const char* dmHashReverseSafe32(uint32_t hash) get string value from hash
const char* dmHashReverseSafe32(uint32_t hash, uint32_t* length) get string value from hash
const char* dmHashReverseSafe32Alloc(dmAllocator* allocator, uint32_t hash) get string value from hash
const char* dmHashReverseSafe64(uint64_t hash) get string value from hash
const char* dmHashReverseSafe64(uint64_t hash, uint32_t* length) get string value from hash
const char* dmHashReverseSafe64Alloc(dmAllocator* allocator, uint64_t hash) get string value from hash
uint32_t dmHashString32(const char* string) Calculate 32-bit hash value from string
uint64_t dmHashString64(const char* string) calculate 64-bit hash value from string
void dmHashUpdateBuffer32(HashState32* hash_state, const void* buffer, uint32_t buffer_len) Incremental hashing
void dmHashUpdateBuffer64(HashState64* hash_state, const void* buffer, uint32_t buffer_len) Incremental hashing

Functions

DM_HASH_REVERSE_MEM

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

dmHashBuffer32

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

dmHashBuffer64

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

dmHashClone32

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.

dmHashClone64

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.

dmHashFinal32

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

dmHashFinal64

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

dmHashInit32

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

dmHashInit64

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

dmHashRelease32

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

dmHashRelease64

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

dmHashReverseSafe32

const char* dmHashReverseSafe32(uint32_t hash)

Returns the original string used to produce a hash. Always returns a null terminated string. Returns "" if the original string wasn't found.

PARAMETERS

uint32_t hash hash value

RETURNS

const char* Original string value or "" if it wasn't found.

dmHashReverseSafe32

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

dmHashReverseSafe32Alloc

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 "" if it wasn't found, or "" if the allocator failed to allocate more memory. Always returns a null terminated string.

EXAMPLES

Get the string representaiton of a hash value
DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe32Alloc(&hash_ctx, hash);

dmHashReverseSafe64

const char* dmHashReverseSafe64(uint64_t hash)

Returns the original string used to produce a hash. Always returns a null terminated string. Returns "" if the original string wasn't found.

PARAMETERS

uint64_t hash hash value

RETURNS

const char* Original string value or "" if it wasn't found.

dmHashReverseSafe64

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

dmHashReverseSafe64Alloc

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 "" if it wasn't found, or "" if the allocator failed to allocate more memory. Always returns a null terminated string.

EXAMPLES

Get the string representaiton of a hash value
DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe64Alloc(&hash_ctx, hash);

dmHashString32

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

dmHashString64

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

dmHashUpdateBuffer32

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

dmHashUpdateBuffer64

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

Structs

HashState32

TYPE

struct HashState32

Hash state used for 32-bit incremental hashing


HashState64

TYPE

struct HashState64

Hash state used for 64-bit incremental hashing


Types

dmhash_t

typedef uint64_t dmhash_t