PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches

Non-cryptographic hash. More...

Macros

#define HASH_INIT   5381U
 Initial value for hash_update().
 

Functions

uint32_t hash (const uint8_t *bytes, const uint32_t length)
 Hash bytes with the DJB2 algorithm.
 
uint32_t hash_update (uint32_t h, const void *data, size_t len)
 Continue a DJB2 hash with more data.
 

Detailed Description

Non-cryptographic hash.

Macro Definition Documentation

◆ HASH_INIT

#define HASH_INIT   5381U

Initial value for hash_update().

Function Documentation

◆ hash()

uint32_t hash ( const uint8_t *  bytes,
const uint32_t  length 
)

Hash bytes with the DJB2 algorithm.

Parameters
bytesData.
lengthLength of bytes.
Returns
Hash, 5381 for empty data.

◆ hash_update()

uint32_t hash_update ( uint32_t  h,
const void *  data,
size_t  len 
)

Continue a DJB2 hash with more data.

Hashing data in chunks gives the same result as hash() on all of it:

uint32_t h = hash_update(HASH_INIT, &hdr, sizeof(hdr));
h = hash_update(h, payload, payload_len);
uint32_t hash_update(uint32_t h, const void *data, size_t len)
Continue a DJB2 hash with more data.
#define HASH_INIT
Initial value for hash_update().
Definition hash.h:26
Parameters
hRunning hash, HASH_INIT to start.
dataData.
lenLength of data.
Returns
Updated hash.