If I have a hash function that generates a 32 bit result with a good distribution (say murmur3):
var h32 = hash32(str, seed); // returns a 32bit hex string (8 chars): '0123abcd'
it will still generate collisions with a probability of 50% when I have 77163 samples.
Can I create a 64 bit hash with equally good distribution by simply concatenating the result strings of two calls with different seed?
For example
h64 = hash32(str, seed1) + hash32(str, seed2); // '0123abcd8d4f614a'
or by modifying the input slightly on the second call
h64 = hash32(str) + hash32(str + 'x'); // '0123abcd8d4f614a'
Or put it another way:
If hash32('foo') == hash32('bar')
, can I assume that hash32('foo'+'x') == hash32('bar'+'x')
is completely independent / unlikely?
UPDATE: thinking about it, this will probably not work if the hash algorithm works incrementally character-by-character, so this will not help either:
h64 = hash32(str) + hash32(str + str);
So I rather ask for a way to 'build a 64-bit hash if only a 32-bit hash function is available.'
UPDATE 2
I am aware that no one would use 32-bit in a crypto context. My question is about doubling the length, when I only have a method that returns a given length. And doing it in a way that improves collision behavior as one would expect from a native 64-bit method (or at least similar).
So this is a general question (replace '32' with any number if you like).
It has a real background though: I use JavaScript, which not easily supports 64-bit math and I already have a performant, small hash32()
implementation using murmur 3.
The question would probably be better suited on StackOverflow, but the accepted answer hits the spot.