Add implementation for siphash
Release / release (push) Successful in 4s

This commit is contained in:
2026-08-31 02:15:01 +01:00
parent bca2e720ad
commit 900c16415b
13 changed files with 848 additions and 2 deletions
+103
View File
@@ -0,0 +1,103 @@
// vim:fileencoding=utf-8:foldmethod=marker
/**
* Implementations of the SipHash-2-4-128, SipHash4-8-128, SipHash-2-4-64 and SipHash4-8-64
* algorithms based on https://github.com/veorq/SipHash/blob/master/siphash.c
*/
#ifndef SIPHASH_H
#define SIPHASH_H
#include "../../stream/stream.h"
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef WP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WP_PLATFORM_CPP
#define WP_SIP_HASHER_128_MAGIC ((u64)0x5750534950313238)
#define WP_SIP_HASHER_64_MAGIC ((u64)0x57505349503634)
typedef struct {
u64 lo;
u64 hi;
} WpSipHasherKey;
typedef struct {
WpSipHasherKey key;
u64 magic;
u64 compression;
u64 finalisation;
} WpSipHasherParams;
typedef struct {
WpSipHasherParams params;
u64 hash[2];
} WpSipHasher128IO;
typedef struct {
WpSipHasherParams params;
u64 hash;
} WpSipHasher64IO;
#ifdef WP_PLATFORM_CPP
#define wpSip24Hasher128IO(KEY) (WpSipHasher128IO{ \
WpSipHasherParams{KEY, WP_SIP_HASHER_128_MAGIC, 2, 4}, \
{}, \
})
#define wpSip48Hasher128IO(KEY) (WpSipHasher128IO{ \
WpSipHasherParams{KEY, WP_SIP_HASHER_128_MAGIC, 4, 8}, \
{}, \
})
#define wpSip24Hasher64IO(KEY) (WpSipHasher64IO{ \
WpSipHasherParams{KEY, WP_SIP_HASHER_64_MAGIC, 2, 4}, \
0, \
})
#define wpSip48Hasher64IO(KEY) (WpSipHasher64IO{ \
WpSipHasherParams{KEY, WP_SIP_HASHER_64_MAGIC, 4, 8}, \
0, \
})
#else
#define wpSip24Hasher128IO(KEY) ((WpSipHasher128IO){ \
.params = (WpSipHasherParams){ \
.key = KEY, \
.magic = WP_SIP_HASHER_128_MAGIC, \
.compression = 2, \
.finalisation = 4, \
} \
})
#define wpSip48Hasher128IO(KEY) ((WpSipHasher128IO){ \
.params = (WpSipHasherParams){ \
.key = KEY, \
.magic = WP_SIP_HASHER_128_MAGIC, \
.compression = 4, \
.finalisation = 8, \
} \
})
#define wpSip24Hasher64IO(KEY) ((WpSipHasher64IO){ \
.params = (WpSipHasherParams){ \
.key = KEY, \
.magic = WP_SIP_HASHER_64_MAGIC, \
.compression = 2, \
.finalisation = 4, \
} \
})
#define wpSip48Hasher64IO(KEY) ((WpSipHasher64IO){ \
.params = (WpSipHasherParams){ \
.key = KEY, \
.magic = WP_SIP_HASHER_64_MAGIC, \
.compression = 4, \
.finalisation = 8, \
} \
})
#endif
void wpSipHasher128(WpU8Stream *bytes, void *hasher_io);
void wpSipHasher64(WpU8Stream *bytes, void *hasher_io);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WP_PLATFORM_CPP
#endif // !SIPHASH_H