This commit is contained in:
1 parent
9055c5c825
commit
5e67c596b9
43 files changed
+476
-450
No files matched your search
@@ -5,10 +5,10 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
#define _u32To8LE(p, v) \
|
||||
(p)[0] = (u8)((v)); \
|
||||
@@ -46,17 +46,17 @@ wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
void wpSipHasher128(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher128IO *io = (WpSipHasher128IO *)hasher_io;
|
||||
_validate128IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
validate128IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
}
|
||||
|
||||
void wpSipHasher64(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher64IO *io = (WpSipHasher64IO *)hasher_io;
|
||||
_validate64IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
validate64IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
}
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
u64 outlen) {
|
||||
const u8 *kk = (const u8 *)¶ms->key;
|
||||
u64 inlen = bytes->count * bytes->item_size;
|
||||
@@ -157,19 +157,19 @@ wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params,
|
||||
_u64To8LE(out + 8, b);
|
||||
}
|
||||
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io) {
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_128_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 128 IO");
|
||||
}
|
||||
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io) {
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_64_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 64 IO");
|
||||
}
|
||||
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params) {
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params) {
|
||||
b8 rounds24 = params->compression == 2 && params->finalisation == 4;
|
||||
b8 rounds48 = params->compression == 4 && params->finalisation == 8;
|
||||
return rounds24 || rounds48;
|
||||
|
||||
Reference in new issue
Block a user