FNV32 hash in C

This code is in the NYSL( public domain ).


#define FNV_32_PRIME ((uint32)0x01000193)
#define uint32 unsigned int

uint32 dkcFNV32_INL(const void *buf,size_t len,uint32 hval)
{
unsigned char *bp = (unsigned char *)buf; /* start of buffer */
unsigned char *be = bp + len; /* beyond end of buffer */

/*
* FNV-1 hash each octet in the buffer
*/

while (bp < be) {

/* multiply by the 32 bit FNV magic prime mod 2^32 */
#if defined(NO_FNV_GCC_OPTIMIZATION)
hval *= FNV_32_PRIME;
#else
hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
#endif

/* xor the bottom with the current octet */
hval ^= (uint32)*bp++;
}

return hval;
}