This commit is contained in:
1 parent
8b3b1816b3
commit
f73a870a34
12 files changed
+31
-164
No files matched your search
@@ -44,6 +44,10 @@ wp_intern inline b8 checkRounds(const WpSipHasherData *params);
|
||||
v2 = wpMiscUtilsRotl64(v2, 32); \
|
||||
} while (0)
|
||||
|
||||
WpHasher wpSipHasher(WpSipHasherData *data) {
|
||||
return (WpHasher){ .func = wpSipHasher128, .data = (void *)data };
|
||||
}
|
||||
|
||||
WpU128Hash wpSipHasher128(WpStream *bytes, void *hasher_data) {
|
||||
WpSipHasherData *data = (WpSipHasherData *)hasher_data;
|
||||
validateSipHasherData(data);
|
||||
@@ -52,20 +56,15 @@ WpU128Hash wpSipHasher128(WpStream *bytes, void *hasher_data) {
|
||||
return output;
|
||||
}
|
||||
|
||||
u64 wpSipHasher64(WpStream *bytes, void *hasher_data) {
|
||||
WpSipHasherData *data = (WpSipHasherData *)hasher_data;
|
||||
validateSipHasherData(data);
|
||||
u64 output = 0;
|
||||
siphash(bytes, data, (u8 *)&output, sizeof(u64));
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the 128-variant of the siphash algorithm
|
||||
*/
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8 *out,
|
||||
u64 outlen) {
|
||||
const u8 *kk = (const u8 *)¶ms->key;
|
||||
u64 inlen = bytes->count * bytes->item_size;
|
||||
|
||||
wpRuntimeAssert((outlen == 8) || (outlen == 16), "outlen should be 8 or 16");
|
||||
wpRuntimeAssert(outlen == 16, "outlen should be 16");
|
||||
|
||||
u64 v0 = wpU64Const(0x736f6d6570736575);
|
||||
u64 v1 = wpU64Const(0x646f72616e646f6d);
|
||||
@@ -82,9 +81,7 @@ wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8
|
||||
v1 ^= k1;
|
||||
v0 ^= k0;
|
||||
|
||||
if (outlen == 16) {
|
||||
v1 ^= 0xee;
|
||||
}
|
||||
v1 ^= 0xee;
|
||||
|
||||
u8 *data;
|
||||
while (wpStreamHasCount(bytes, sizeof(u64))) {
|
||||
@@ -134,11 +131,7 @@ wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8
|
||||
|
||||
v0 ^= b;
|
||||
|
||||
if (outlen == 16) {
|
||||
v2 ^= 0xee;
|
||||
} else {
|
||||
v2 ^= 0xff;
|
||||
}
|
||||
v2 ^= 0xee;
|
||||
|
||||
for (i = 0; i < params->finalisation; ++i) {
|
||||
_sipRound;
|
||||
@@ -147,10 +140,6 @@ wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8
|
||||
b = v0 ^ v1 ^ v2 ^ v3;
|
||||
_u64To8LE(out, b);
|
||||
|
||||
if (outlen == 8) {
|
||||
return;
|
||||
}
|
||||
|
||||
v1 ^= 0xdd;
|
||||
|
||||
for (i = 0; i < params->finalisation; ++i) {
|
||||
|
||||
Reference in new issue
Block a user