3 ms·
The "ZOMGBadHash" isn't unique to that codebase - it's the hash specified by the ELF ABI (see http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash ht
by caf 10y ago
The "ZOMGBadHash" isn't unique to that codebase - it's the hash specified by the ELF ABI (see http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#h... ).
It's not just a random mush of xors and shifts, it's:
- Add the next character value to the current value;
- Left-shift the current value by 4 (because most of the entropy in plain text ASCII is in the lower 4 bits);
- XOR the top 4 bits into the bottom four bits of the current value, because they're going to get shifted out next time; then clear the top four bits.
It's still not a great hash function (obviously). Part of the issue is that with a 32-bit unsigned int it's effectively only a 28 bit hash.