Packetizer Logo
 

Secure Hashing Algorithm (SHA-1)

A C and C++ Reference 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.

All downloads 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: DA58FA3C 0501283F 09385A91 2C844B1B 82AFEF34

The fingerprint for the C (sha1-c.zip) file is: 43A368A6 4FEEF833 9CCF389A 5CE9F1B4 C5D5637A

Windows binaries are in the sha1_windows.zip file. The fingerprint is for that file is: 2FED8316 1FC9F7C3 ECD88DBE F0DD75AD F103AA44

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. The most significant advantage of the code found here is that it is entirely free and may be used in commercial products without a fee.