Skip to content

Commit 1ce4a80

Browse files
update hash function
1 parent cdba587 commit 1ce4a80

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

code/logic/jellyfish.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,28 @@
1818

1919
// Simple placeholder hash function (not cryptographic, just consistent)
2020
void fossil_jellyfish_hash(const char *input, const char *output, uint8_t *hash_out) {
21-
size_t len = strlen(input) + strlen(output);
21+
// Enhanced: Use a simple FNV-1a-like mixing over input and output
22+
const uint32_t FNV_PRIME = 0x01000193;
23+
uint32_t hash = 0x811c9dc5;
24+
size_t in_len = strlen(input);
25+
size_t out_len = strlen(output);
26+
27+
// Mix input
28+
for (size_t i = 0; i < in_len; ++i) {
29+
hash ^= (uint8_t)input[i];
30+
hash *= FNV_PRIME;
31+
}
32+
// Mix output
33+
for (size_t i = 0; i < out_len; ++i) {
34+
hash ^= (uint8_t)output[i];
35+
hash *= FNV_PRIME;
36+
}
37+
38+
// Spread hash into hash_out buffer
2239
for (size_t i = 0; i < FOSSIL_JELLYFISH_HASH_SIZE; ++i) {
23-
hash_out[i] = (uint8_t)((input[i % strlen(input)] ^ output[i % strlen(output)] ^ (int)i) + i * 31);
40+
hash ^= (hash >> 13);
41+
hash *= FNV_PRIME;
42+
hash_out[i] = (uint8_t)((hash >> (8 * (i % 4))) & 0xFF);
2443
}
2544
}
2645

0 commit comments

Comments
 (0)