File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 1616#include <stdio.h>
1717#include <time.h>
1818
19- // Simple placeholder hash function (not cryptographic, just consistent)
2019void fossil_jellyfish_hash (const char * input , const char * output , uint8_t * hash_out ) {
21- // Enhanced: Use a simple FNV-1a-like mixing over input and output
2220 const uint32_t FNV_PRIME = 0x01000193 ;
2321 uint32_t hash = 0x811c9dc5 ;
2422 size_t in_len = strlen (input );
2523 size_t out_len = strlen (output );
2624
25+ // Mix in lengths
26+ hash ^= in_len ;
27+ hash *= FNV_PRIME ;
28+ hash ^= out_len ;
29+ hash *= FNV_PRIME ;
30+
2731 // Mix input
2832 for (size_t i = 0 ; i < in_len ; ++ i ) {
2933 hash ^= (uint8_t )input [i ];
3034 hash *= FNV_PRIME ;
35+ hash ^= (hash >> 5 );
3136 }
37+
3238 // Mix output
3339 for (size_t i = 0 ; i < out_len ; ++ i ) {
3440 hash ^= (uint8_t )output [i ];
3541 hash *= FNV_PRIME ;
42+ hash ^= (hash >> 5 );
3643 }
3744
38- // Spread hash into hash_out buffer
45+ // Final mix
46+ hash ^= (hash << 7 );
47+ hash ^= (hash >> 3 );
48+
49+ // Spread into output
50+ uint32_t h = hash ;
3951 for (size_t i = 0 ; i < FOSSIL_JELLYFISH_HASH_SIZE ; ++ i ) {
40- hash ^= (hash >> 13 );
41- hash *= FNV_PRIME ;
42- hash_out [i ] = (uint8_t )((hash >> (8 * (i % 4 ))) & 0xFF );
52+ h ^= (h >> 13 );
53+ h *= FNV_PRIME ;
54+ h ^= (h << 11 );
55+ hash_out [i ] = (uint8_t )((h >> (8 * (i % 4 ))) & 0xFF );
4356 }
4457}
4558
You can’t perform that action at this time.
0 commit comments