Commit 6949ab9d authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Replace indexing hash with 32-bit FNV-1... should be much faster than MD5

parent adf79551
/* $OpenLDAP$ */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted only
* as authorized by the OpenLDAP Public License. A copy of this
* license is available at http://www.OpenLDAP.org/license.html or
* in file LICENSE in the top-level directory of the distribution.
*/
/* See hash.c for explanation and copyright information. */
#ifndef _LUTIL_HASH_H_
#define _LUTIL_HASH_H_
#include <lber_types.h>
LDAP_BEGIN_DECL
#define LUTIL_HASH_BYTES 4
struct lutil_HASHContext {
ber_uint_t hash;
};
LDAP_LUTIL_F( void )
lutil_HASHInit LDAP_P((
struct lutil_HASHContext *context));
LDAP_LUTIL_F( void )
lutil_HASHUpdate LDAP_P((
struct lutil_HASHContext *context,
unsigned char const *buf,
ber_len_t len));
LDAP_LUTIL_F( void )
lutil_HASHFinal LDAP_P((
unsigned char digest[LUTIL_HASH_BYTES],
struct lutil_HASHContext *context));
typedef struct lutil_HASHContext lutil_HASH_CTX;
LDAP_END_DECL
#endif /* _LUTIL_HASH_H_ */
......@@ -13,11 +13,11 @@ NT_OBJS = ntservice.o slapdmsg.res
UNIX_SRCS = detach.c
UNIX_OBJS = detach.o
SRCS = base64.c debug.c entropy.c sasl.c signal.c \
SRCS = base64.c debug.c entropy.c sasl.c signal.c hash.c \
md5.c passwd.c sha1.c getpass.c lockf.c utils.c sockpair.c \
@LIBSRCS@ $(@PLAT@_SRCS)
OBJS = base64.o debug.o entropy.o sasl.o signal.o \
OBJS = base64.o debug.o entropy.o sasl.o signal.o hash.o \
md5.o passwd.o sha1.o getpass.o lockf.o utils.o sockpair.o \
@LIBOBJS@ $(@PLAT@_OBJS)
......
/* $OpenLDAP$ */
/* This implements the Fowler / Noll / Vo (FNV-1) hash algorithm.
* A summary of the algorithm can be found at:
* http://www.isthe.com/chongo/tech/comp/fnv/index.html
*/
#include "portable.h"
#include <ac/string.h>
/* include socket.h to get sys/types.h and/or winsock2.h */
#include <ac/socket.h>
#include <lutil_hash.h>
/* offset and prime for 32-bit FNV-1 */
#define HASH_OFFSET 0x811c9dc5
#define HASH_PRIME 16777619
/*
* Initialize context
*/
void
lutil_HASHInit( struct lutil_HASHContext *ctx )
{
ctx->hash = HASH_OFFSET;
}
/*
* Update hash
*/
void
lutil_HASHUpdate(
struct lutil_HASHContext *ctx,
const unsigned char *buf,
ber_len_t len
)
{
const unsigned char *p, *e;
ber_uint_t h;
p = buf;
e = &buf[len];
h = ctx->hash;
while( p < e ) {
h *= HASH_PRIME;
h ^= *p++;
}
ctx->hash = h;
}
/*
* Save hash
*/
void
lutil_HASHFinal( unsigned char *digest, struct lutil_HASHContext *ctx )
{
ber_uint_t h = ctx->hash;
digest[0] = h & 0xff;
digest[1] = (h>>8) & 0xff;
digest[2] = (h>>16) & 0xff;
digest[3] = (h>>24) & 0xff;
}
......@@ -15,14 +15,24 @@
#include "slap.h"
#include "ldap_pvt.h"
#include "lutil_md5.h"
#ifdef USE_MD5
#include "lutil_md5.h"
/* We should replace MD5 with a faster hash */
#define HASH_BYTES LUTIL_MD5_BYTES
#define HASH_CONTEXT lutil_MD5_CTX
#define HASH_Init(c) lutil_MD5Init(c)
#define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
#define HASH_Final(d,c) lutil_MD5Final(d,c)
#else
#include "lutil_hash.h"
/* We should replace MD5 with a faster hash */
#define HASH_BYTES LUTIL_HASH_BYTES
#define HASH_CONTEXT lutil_HASH_CTX
#define HASH_Init(c) lutil_HASHInit(c)
#define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
#define HASH_Final(d,c) lutil_HASHFinal(d,c)
#endif
/* recycled validatation routines */
#define berValidate blobValidate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment