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
+81
View File
@@ -2,6 +2,7 @@
#include "test_hasher.h"
#include "MurmurHash3.h"
#include "siphash.h"
#include "wapp.h"
WpTestFuncResult test_murmur3(void) {
@@ -39,3 +40,83 @@ WpTestFuncResult test_murmur3(void) {
return wpTesterResult(result);
}
WpTestFuncResult test_siphash_128(void) {
b8 result = true;
WpStr8 str = wpStr8Lit("Hello world");
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
u64 num = 287324;
WpSipHasherKey key = { 238742, 671734 };
WpSipHasher128IO io = wpSip24Hasher128IO(key);
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
WpU8Stream num_bytes = wpStream(u8, (u8 *)&num, sizeof(u64));
u64 hash[2] = {0};
// Sring hash
wpSipHasher128(&str_bytes, (void *)&io);
siphash((void *)str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
(u8 *)hash, sizeof(u64) * 2);
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
// Array hash
wpSipHasher128(&arr_bytes, (void *)&io);
siphash((void *)arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
(u8 *)hash, sizeof(u64) * 2);
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
// Number hash
wpSipHasher128(&num_bytes, (void *)&io);
siphash((void *)num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
(u8 *)hash, sizeof(u64) * 2);
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
return wpTesterResult(result);
}
WpTestFuncResult test_siphash_64(void) {
b8 result = true;
WpStr8 str = wpStr8Lit("Hello world");
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
u64 num = 287324;
WpSipHasherKey key = { 238742, 671734 };
WpSipHasher64IO io = wpSip24Hasher64IO(key);
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
WpU8Stream num_bytes = wpStream(u8, (u8 *)&num, sizeof(u64));
u64 hash = {0};
// Sring hash
wpSipHasher64(&str_bytes, (void *)&io);
siphash((void *)str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
(u8 *)&hash, sizeof(u64));
result = result && io.hash == hash;
// Array hash
wpSipHasher64(&arr_bytes, (void *)&io);
siphash((void *)arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
(u8 *)&hash, sizeof(u64));
result = result && io.hash == hash;
// Number hash
wpSipHasher64(&num_bytes, (void *)&io);
siphash((void *)num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
(u8 *)&hash, sizeof(u64));
result = result && io.hash == hash;
return wpTesterResult(result);
}