BSD license compatible hash algorithm?
Ivan Voras
ivoras at freebsd.org
Fri Dec 28 04:36:01 PST 2007
Garrett Cooper wrote:
> Looks promising, but how difficult would it be to port the code to
> other platforms (Win32 for instance?).
The hash algorithm itself as implemented in hash.h is pretty much a
text-book hash algorithm (D.J.Bernstein's):
#ifndef HASHINIT
#define HASHINIT 5381
#define HASHSTEP(x,c) (((x << 5) + x) + (c))
#endif
/*
* Return a 32-bit hash of the given buffer. The init
* value should be 0, or the previous hash value to extend
* the previous hash.
*/
static __inline uint32_t
hash32_buf(const void *buf, size_t len, uint32_t hash)
{
const unsigned char *p = buf;
while (len--)
hash = HASHSTEP(hash, *p++);
return hash;
}
It apparently has some weaknesses if used on binary (non-text) data but
I don't see why it wouldn't work on Windows.
More information about the freebsd-hackers
mailing list