hexagram/src/hash.c
2019-05-18 19:48:28 -05:00

30 lines
526 B
C

#include <stdlib.h>
#include <string.h>
#include <hexagram/hash.h>
int hexagram_hash(void *data, size_t size, uint32_t *hash) {
uint32_t value = 0x00;
size_t i;
if (data == NULL) {
goto error_null_data;
}
for (i=0; i<size; i++) {
value += ((uint8_t *)data)[i];
value += (value << 10);
value ^= (value >> 6);
}
value += (value << 3);
value ^= (value >> 11);
value += (value << 15);
*hash = value;
return 0;
error_null_data:
return -1;
}