10/07/2007

Secure Hashing Algorithm

A C and C++ Implementation

The Secure Hashing Standard, defined in FIPS PUB 180-1, defines the Secure Hashing Algorithm (SHA-1). SHA-1 can be used to produce a message digest for a given message. Essentially, this is a 160-bit number that represents the message.

In theory, no two messages would ever share the same message digest. What this means is that the message digest can serve as a fingerprint for a file or other source of data. SHA-1 is used by Digital Signature Standard (DSS), which is a standard used for digitally signing documents or other data.

From this page, you can download the C++ and the C the implementations of SHA-1. This is the same source base from which the code in RFC 3174 was based. While the RFC has remained static, this code base has been modified (ever so slightly) and any reported bug fixes will be put into this source repository. (To date, none have been reported, though the code has been used widely.)

Along with the class that implements the SHA-1 algorithm, there are also utilities to produce fingerprints of files, compare files based on fingerprints, and exercise the class itself.

You can also download binary versions for Linux and Windows. These include the utilities "sha" and "shacmp" for displaying fingerprints of files (sha) and also comparing the fingerprints of two files (shacmp).

The fingerprint for the C++ (sha1.zip) file is: 46067CBB 52E86D16 2C66818E EBD0B682 886F4B12

The fingerprint for the C (sha1-c.zip) file is: 569BE022 AEF78867 3263F05E 07B015F2 9D7D5553

The fingerprint for the Linux binaries (sha1_linux.tgz) file is: CA4CC3EA C3E92261 18196B13 1C138DF3 A4C6E0DB

Windows binaries are in the sha1.zip file.

Finally, we should point out that this is not an optimized version of the SHA-1 algorithm. It is written so that the algorithm can be easily compared against the FIPS document. No effort has been made to improve performance in any way.

If you are looking for an optimized version, may we suggest you use Christophe Devine's code. It can be found here. Our preliminary testing shows that it is significantly faster than the reference implementation found on this page.

If you have any questions or comments, feel free to contact Paul Jones.

No comments: