libgslutil  1.2.3
Functions
Hash/CRC implementations

Functions

uint32_t gsl_string_hash (const char *data, int len)
 Compute string hash. More...
 
uint32_t gsl_memory_hash (const struct iovec *datv, int datvcnt)
 Compute memory vector hash. More...
 
uint32_t gsl_crc32 (uint32_t seed, const char *data, uint32_t len))
 Compute CRC32 checksum. More...
 
void gsl_sha256 (const char *data, uint32_t len, char *sha))
 Compute SHA-256 hash. More...
 
struct gsl_sha256_ctx * gsl_sha256_alloc (void))
 Allocate SHA-256 incremental hash object.
 
void gsl_sha256_incr_hash (struct gsl_sha256_ctx *ctx, const char *data, uint32_t len))
 Perform incremental hash of data block. More...
 
void gsl_sha256_finish (struct gsl_sha256_ctx *ctx, char *sha))
 Finalise incremental hash, free hash object. More...
 

Detailed Description

A set of hash functions and CRC computations.

Function Documentation

◆ gsl_string_hash()

uint32_t gsl_string_hash ( const char *  data,
int  len 
)

Compute string hash.

Parameters
dataPointer to data or C string.
lenSize of data in bytes, or -1 for C strings.
Returns
32-bit hash of data

This function computes a string hash using the LOOKUP3 hash from Bob Jenkins. This hash is intended as a fairly collision-resistant way of hashing ASCII strings. It is also a fast hash for arbitrary binary data. The 32-bit return value may be truncated to a smaller length as necessary.

If data is a C string, pass -1 in len to compute over the length of the string. Otherwise, pass the number of bytes to compute the hash over in len.

◆ gsl_memory_hash()

uint32_t gsl_memory_hash ( const struct iovec *  datv,
int  datvcnt 
)

Compute memory vector hash.

Parameters
datvPointer to array of memory regions.
datvcntNumber of entries in datv.
Returns
32-bit hash of data

This function computes a hash using the LOOKUP3 hash from Bob Jenkins. The 32-bit return value may be truncated to a smaller length as necessary.

See also
gsl_string_hash() for a simpler interface.

◆ gsl_crc32()

uint32_t gsl_crc32 ( uint32_t  seed,
const char *  data,
uint32_t  len 
)

Compute CRC32 checksum.

Parameters
seedInitial seed value.
dataPointer to data.
lenSize of data in bytes.
Returns
CRC32 of data.

This function computes the CRC32 of the given data. You can perform incremental CRC by passing the result of one CRC operation as the seed value of the next.

When seed starts at 0xFFFFFFFF and the final result is XORed with 0xFFFFFFFF, this implementation is compatible with CRC-32-IEEE 802.3 (used in Ethernet et al.).

◆ gsl_sha256()

void gsl_sha256 ( const char *  data,
uint32_t  len,
char *  sha 
)

Compute SHA-256 hash.

Parameters
dataPointer to data.
lenSize of data in bytes.
shaA 32-byte buffer into which the digest will be written.

This function computes the SHA-256 hash of the given data.

◆ gsl_sha256_incr_hash()

void gsl_sha256_incr_hash ( struct gsl_sha256_ctx *  ctx,
const char *  data,
uint32_t  len 
)

Perform incremental hash of data block.

Parameters
ctxSHA-256 incremental hash object.
dataPointer to data.
lenSize of data in bytes.

◆ gsl_sha256_finish()

void gsl_sha256_finish ( struct gsl_sha256_ctx *  ctx,
char *  sha 
)

Finalise incremental hash, free hash object.

Parameters
ctxSHA-256 incremental hash object. Will be freed.
shaA 32-byte buffer into which the digest will be written.