This commit is contained in:
1 parent
17be4841e6
commit
9881c0ac9a
6 files changed
+62
-62
No files matched your search
@@ -6,9 +6,9 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void validateSipHasherData(const WpSipHasherData *io);
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherData *params);
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherCtx *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void validateSipHasherCtx(const WpSipHasherCtx *io);
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherCtx *params);
|
||||
|
||||
#define _u32To8LE(p, v) \
|
||||
(p)[0] = (u8)((v)); \
|
||||
@@ -44,13 +44,13 @@ wp_intern inline b8 checkRounds(const WpSipHasherData *params);
|
||||
v2 = wpMiscUtilsRotl64(v2, 32); \
|
||||
} while (0)
|
||||
|
||||
WpHasher wpSipHasher(WpSipHasherData *data) {
|
||||
WpHasher wpSipHasher(WpSipHasherCtx *data) {
|
||||
return (WpHasher){ .func = wpSipHasher128, .data = (void *)data };
|
||||
}
|
||||
|
||||
WpU128Hash wpSipHasher128(WpStream *bytes, void *hasher_data) {
|
||||
WpSipHasherData *data = (WpSipHasherData *)hasher_data;
|
||||
validateSipHasherData(data);
|
||||
WpSipHasherCtx *data = (WpSipHasherCtx *)hasher_data;
|
||||
validateSipHasherCtx(data);
|
||||
WpU128Hash output = {0};
|
||||
siphash(bytes, data, (u8 *)&output.hash, sizeof(u64) * 2);
|
||||
return output;
|
||||
@@ -59,7 +59,7 @@ WpU128Hash wpSipHasher128(WpStream *bytes, void *hasher_data) {
|
||||
/**
|
||||
* Implementation of the 128-variant of the siphash algorithm
|
||||
*/
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8 *out,
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherCtx *params, u8 *out,
|
||||
u64 outlen) {
|
||||
const u8 *kk = (const u8 *)¶ms->key;
|
||||
u64 inlen = bytes->count * bytes->item_size;
|
||||
@@ -150,14 +150,14 @@ wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8
|
||||
_u64To8LE(out + 8, b);
|
||||
}
|
||||
|
||||
wp_intern inline void validateSipHasherData(const WpSipHasherData *data) {
|
||||
b8 magic_match = data->magic == WP_SIP_HASHER_MAGIC;
|
||||
b8 rounds = checkRounds(data);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash data");
|
||||
wp_intern inline void validateSipHasherCtx(const WpSipHasherCtx *ctx) {
|
||||
b8 magic_match = ctx->magic == WP_SIP_HASHER_MAGIC;
|
||||
b8 rounds = checkRounds(ctx);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash context");
|
||||
}
|
||||
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherData *data) {
|
||||
b8 rounds24 = data->compression == 2 && data->finalisation == 4;
|
||||
b8 rounds48 = data->compression == 4 && data->finalisation == 8;
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherCtx *ctx) {
|
||||
b8 rounds24 = ctx->compression == 2 && ctx->finalisation == 4;
|
||||
b8 rounds48 = ctx->compression == 4 && ctx->finalisation == 8;
|
||||
return rounds24 || rounds48;
|
||||
}
|
||||
Reference in new issue
Block a user