From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 28 12:36:01 2007 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07DC716A420 for ; Fri, 28 Dec 2007 12:36:01 +0000 (UTC) (envelope-from freebsd-hackers@m.gmane.org) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mx1.freebsd.org (Postfix) with ESMTP id ABADB13C447 for ; Fri, 28 Dec 2007 12:36:00 +0000 (UTC) (envelope-from freebsd-hackers@m.gmane.org) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1J8ERN-0007jP-EN for freebsd-hackers@freebsd.org; Fri, 28 Dec 2007 12:35:53 +0000 Received: from 78-1-126-123.adsl.net.t-com.hr ([78.1.126.123]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Dec 2007 12:35:53 +0000 Received: from ivoras by 78-1-126-123.adsl.net.t-com.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Dec 2007 12:35:53 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-hackers@freebsd.org From: Ivan Voras Date: Fri, 28 Dec 2007 13:35:43 +0100 Lines: 31 Message-ID: References: <5950EE0C-383D-4D6B-9991-A0DEABD2ADE4@u.washington.edu> <20071228003716.GB48997@lor.one-eyed-alien.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 78-1-126-123.adsl.net.t-com.hr User-Agent: Thunderbird 2.0.0.9 (X11/20071122) In-Reply-To: Sender: news Subject: Re: BSD license compatible hash algorithm? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Dec 2007 12:36:01 -0000 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.