2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2000-2003 The OpenLDAP Foundation.
5 * Portions Copyright 2000-2003 Kurt D. Zeilenga.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 /* This implements the Fowler / Noll / Vo (FNV-1) hash algorithm.
18 * A summary of the algorithm can be found at:
19 * http://www.isthe.com/chongo/tech/comp/fnv/index.html
24 #include <lutil_hash.h>
26 /* offset and prime for 32-bit FNV-1 */
27 #define HASH_OFFSET 0x811c9dc5U
28 #define HASH_PRIME 16777619
35 lutil_HASHInit( struct lutil_HASHContext *ctx )
37 ctx->hash = HASH_OFFSET;
45 struct lutil_HASHContext *ctx,
46 const unsigned char *buf,
50 const unsigned char *p, *e;
70 lutil_HASHFinal( unsigned char *digest, struct lutil_HASHContext *ctx )
72 ber_uint_t h = ctx->hash;
74 digest[0] = h & 0xffU;
75 digest[1] = (h>>8) & 0xffU;
76 digest[2] = (h>>16) & 0xffU;
77 digest[3] = (h>>24) & 0xffU;