cvs commit: src/lib/libmd Makefile sha256.3 sha256.h sha256c.c shadriver.c src/sbin/md5 Makefile md5.c

Colin Percival cperciva at freebsd.org
Thu Mar 10 00:18:09 PST 2005


Peter Jeremy wrote:
> Three almost,
> but not totally, identical versions of foo() means three times as much
> maintenance effort and a non-zero probability of someone forgetting
> to make a change to one of the versions.

Absolutely -- but this isn't particularly relevant for hash functions,
since hash functions don't get upgraded to newer versions or have new
features added.  (Ok, they do, but they get a new name and the old
versions are left unchanged.)

>> These hash
>>functions are designed for 32-bit processors in a manner which makes it
>>fairly hard for the compiler to get things wrong.
> 
> It's not so much getting things wrong as being able to get the right
> answer quicker.  It may not be obvious to the compiler that
> 	a = (a << 5) | (a >> 27);
> can be replaced by
> 	rotl	a,5

It is obvious to the compiler.  That's a very common idiom and one of
the first things that compilers recognize.  Gcc gets this right, and
I doubt many people are going to be using a compiler which is worse
at optimization than gcc.

Colin Percival


More information about the cvs-all mailing list