58 lines
2.5 KiB
C
58 lines
2.5 KiB
C
#ifndef VESSEL_HASHING_H_
|
|
#define VESSEL_HASHING_H_
|
|
|
|
#include "conf.h"
|
|
|
|
#include "def.h"
|
|
|
|
/* Implements some useful hashing functions. */
|
|
|
|
size_t vs_u64_to_hash_size(uint64_t num);
|
|
uint64_t vs_fasthash(const void *src, size_t size) __attribute__((pure));
|
|
uint64_t vs_murmurhash(const void *src, size_t size, uint64_t seed) __attribute__((pure));
|
|
uint64_t vs_fnv1a(const void *src, size_t size) __attribute__((pure));
|
|
uint64_t vs_djb2(const void *src, size_t size) __attribute__((pure));
|
|
uint64_t vs_xxhash3(const void *data, size_t size, uint64_t seed) __attribute__((pure));
|
|
uint64_t vs_siphash64(const void *src,
|
|
size_t size,
|
|
const uint64_t seed[2],
|
|
uint8_t compress_rounds,
|
|
uint8_t final_rounds);
|
|
uint64_t vs_crc64(const void *data, size_t size, uint64_t previous_crc) __attribute__((pure));
|
|
|
|
#define VS_BLAKE2S_STATE_SIZE 8
|
|
#define VS_BLAKE2S_INPUT_SIZE 64
|
|
#define VS_BLAKE2S_OUTPUT_SIZE_MAX 32
|
|
|
|
/* It's wrong but at least it's consistent. Call it the Vessel hash format
|
|
* :troll: */
|
|
|
|
#define VS_PR_IX_BLAK_E2S256 "%016jx%016jx%016jx%016jx"
|
|
#define VS_BLAK_E2S256(ctx) \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest)), \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest + 8)), \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest + 16)), \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest + 24))
|
|
|
|
#define VS_PR_IX_BLAK_E2S128 "%016jx%016jx"
|
|
#define VS_BLAK_E2S128(ctx) \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest)), \
|
|
VS_TO_ULE64(*(const uint64_t *)((ctx).digest + 8))
|
|
|
|
typedef struct {
|
|
uint32_t state[VS_BLAKE2S_STATE_SIZE]; /* Hash state */
|
|
uint8_t input[VS_BLAKE2S_INPUT_SIZE]; /* Input block */
|
|
uint8_t idx; /* Index within the input block */
|
|
uint64_t inputs; /* Input count */
|
|
uint8_t outlen; /* Output length */
|
|
uint32_t work[16],
|
|
message[16]; /* Block information: vorking vector (v) and message block (m) */
|
|
uint8_t digest[VS_BLAKE2S_OUTPUT_SIZE_MAX]; /* Output hash */
|
|
} vs_Blake2sCtx;
|
|
|
|
bool vs_Blake2sCtx_init(vs_Blake2sCtx *ctx, uint8_t outlen, const void *key, uint8_t keylen);
|
|
bool vs_Blake2sCtx_update(vs_Blake2sCtx *ctx, const void *data, size_t size);
|
|
bool vs_Blake2sCtx_final(vs_Blake2sCtx *ctx);
|
|
bool vs_Blake2sCtx_to_hex(vs_Blake2sCtx *ctx, void *out);
|
|
|
|
#endif /* VESSEL_HASHING_H_ */
|