Hey folks, just finished my SHA-1 implementation (started out life as part of an RNG; I figured a fast hash would be nice to have for filesharing apps).

Performance: ~740 (!) clocks / block; I've reached my hard drive's maximum throughput of 42 MB/S with 40% CPU load (test system: Athlon XP 1600+, 80 GB Seagate Barracuda IV, Win2k SP3). Overall, it's 33% faster than cygwin's sha1sum, with average 45% CPU load, vs. 75%.

- 2 deep asynchronous reads of 256 KB at a time
- each subround loop is unrolled 5x; variables A-E are kept in registers, and are renamed after each step (=> no copying necessary, only 1 memory hit)

Grab it at www.stud.uni-karlsruhe.de/~urkt/ (near bottom of page).

Hope it's useful to someone :)
Posted on 2003-01-21 21:13:15 by Jan Wassenberg
Jan, to widen the usage of such a lovely piece of code, I've translated it into MASM syntax - hope you don't mind. :) All the features of the original preserved. Note: _DATA segment needs to be PAGE aligned for ALIGN 64 to work - everybody does that, right. :tongue:
Posted on 2003-01-22 00:52:42 by bitRAKE
Great Job :alright:
Posted on 2003-01-22 07:58:34 by roticv
Error in sha1.cpp: I made "just a small change" :rolleyes: to the I/O completion routine, loading 'pos' into a register; I forgot that it was necessary to write it back to memory, leading to incorrect results for files of size != 64*n. This slipped through because all my test files were, as luck would have it, multiples of 64 bytes. Not good. Fixed now. My bad.

bitRAKE: I wish all the assemblers out there were at least a little compatible - making stupid cosmetic changes like ENDM <-> %endmacro sucks (while I'm at it, I wouldn't mind winning the lottery...). I much prefer NASM (and I'm surprised that MASM supports token merging), but thanks for the conversion - looks like lots of guys here use MASM. BTW - the asm code is meant to be called from the main C program; maybe I'll make a 100% assembly routine.

roticv: Thanks :)
Posted on 2003-01-22 08:34:39 by Jan Wassenberg
Jan, I used NASM for a while, but wanted to move towards windows programming and MASM is better, imho. Now with the existance of FASM and GAS supporting Intel syntax there is no use for NASM to me. There was a time when NASM really filled a whole, but that time has passed. Luckily, I worked with it long enough to translate the syntax into FASM/MASM.
Posted on 2003-01-24 20:28:40 by bitRAKE
Update: rewrote everything in asm, FASM style.
If anyone wants to use this in an app, just link to sha1.o; specify the equivalent of
extern "C" void __stdcall sha1(char* filename, unsigned char* digest /* [20] */);
in your favorite language.
New asm source, object code and test program at www.stud.uni-karlsruhe.de/~urkt.

bitRAKE: I dislike MASM's red tape (and hate 'HL' asm), but FASM seems quite OK. Didn't know about GAS supporting Intel syntax (AT&T is icky ;)) - I'll give that a try as well.
Posted on 2003-01-25 19:19:47 by Jan Wassenberg