NODE d6704c71Public domain SHA-1 in C
Steve Reid <steve@edmweb.com>Fri, 27 Sep 1996 10:16:02 +0800
-----BEGIN PGP SIGNED MESSAGE-----
I've written an implementation of SHA-1 in C. Public domain, so you can
hack it to your hearts content and/or use it however you want. You can
download it from
http://www.edmweb.com/steve/sha1.c
It's not hard to use. Allocate a SHA1_CTX, initialize it with SHA1Init()
run over the data with SHA1Update() and finally extract the result using
SHA1Final(). Or just compile the program as-is and use it to hash files.
It's reasonably fast (the 80 core SHA operations look good) but I'm
certain that there's room for improvement.
Tested under FreeBSD 2.1.0-RELEASE on an i486SX. The three test vectors
from FIPS PUB 180-1 hash correctly.
=====================================================================
| Steve Reid - SysAdmin & Pres, EDM Web (http://www.edmweb.com/) |
| Email: steve@edmweb.com Home Page: http://www.edmweb.com/steve/ |
| PGP (2048/9F317269) Fingerprint: 11C89D1CD67287E68C09EC52443F8830 |
| -- Disclaimer: JMHO, YMMV, TANSTAAFL, IANAL. -- |
===================================================================:)
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
iQEVAwUBMksSsNtVWdufMXJpAQFV3AgApaK+upwWtBJZUwq5Pr4cpvjWQcxFHxv6
XEoZmwgwzR94lpjdEK5GPXt7U9HTp+xiwiaeQ7Hjg+iuR/qtofwZlZhQ5EmyBl2M
8rnFSRgwR4NH1y2PwAxQKSo2SaHU8JZ3X3D6Yk1WXAqk90vN8dzQAIa8B409IuhM
tBPixrS6d0KsySSOHQkWO7Mqij43wZOnrgikJF3IDCvSf0us8gGC9wZjdIax3Rgr
soswtQvT6QpZDZ/+39UiA2RSMFuER/S3NbZZSJdfIGK1XzUeU2MUC4NmURlc/ntz
3B1pd+jovxuHW1D/TQ2jHSIdg1Yol/zeu1OeuuhL37QOQAVkupgVUA==
=B73M
-----END PGP SIGNATURE-----
NODE 2cf0b4caRe: Public domain SHA-1 in C
Eric Young <eay@mincom.oz.au>Fri, 27 Sep 1996 13:28:21 +0800
On Thu, 26 Sep 1996, Steve Reid wrote:
> I've written an implementation of SHA-1 in C. Public domain, so you can
> hack it to your hearts content and/or use it however you want. You can
> download it from
> http://www.edmweb.com/steve/sha1.c
...
> It's reasonably fast (the 80 core SHA operations look good) but I'm
> certain that there's room for improvement.
Some times for this implementation
sha1 over a ~ 6 meg file, sparc 10
user time 5.23s 5.23s 5.14s
Replace your 'getc() into 256 byte buffer' loop with a 'read 16k at a
time' (I actually put your functions into my sha1 digest program).
user time 3.79s 3.75s 3.72s
Use sha1 from SSLeay.
user time 2.32s 2.34s 2.24s
Using gcc -O3 -fomit-frame-pointer for all builds and I left out by
B_ENDIAN advisory define; all permutations
produced the same digest, so the 2 SHA1 implementations conform :-).
The key thing that speeds up the SSLeay sha1 is the avoidance of copying
in the SHA1Update() type function. Have a look if you like
(crypto/sha/sha_dgst.c.
The actually SHA1 digesting on 64 bytes is probably identical. For most
message digests, it appears the bigest problem is shoveling data into the
algorithm fast enough.
eric
PS The MD2, MD5, SHA1 etc implemented in SSLeay are all stand alone
functions/libraries than can be compiled and used outside of the
SSLeay library build environment. This also applies to the IDEA,
DES (libdes), RC2 and RC4 cipher subroutines present in the library.
For those on the cipherpunks list (which I don't frequent any-more), the
current version is SSLeay 0.6.4, it can be built as a shared library under
unix and will build as thread safe DLL's under Windows 3.1/95/NT. It is
thread safe under unix as well (only really tested under Solaris 2.5.1).
http://www.psy.uq.oz.au/~ftp/Crypto
ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL
ftp://ftp.psy.uq.oz.au/pub/Crypto/SSLapps
--
Eric Young | BOOL is tri-state according to Bill Gates.
AARNet: eay@mincom.oz.au | RTFM Win32 GetMessage().