Secure Hash Algorithm (SHA-1) Reference implementation in C/C++ with comments
The SHA hash functions are a collection of cryptographic hash functions designed by the National Security Agency (NSA) of the US Govt. and published by the National Institute of Standards and Technology (NIST), USA. Hash algorithms compute a fixed-length digital representation (called message digest or signature or hash) of an input message of any length. SHA-1 produces a message digest that is 160 bits long
A hash function is called secure when it is computationally infeasible to:
1) find a message that corresponds to a given hash, and
2) find two different messages that produce the same hash.
Also, any change to a message will most probably result in a different hash.
The implementations given here is in C / C++. It is given as an aid for beginners to get acquainted with the algorithm and can be used as a base for actual implementation. The main feature of this SHA-1 implementation is not efficiency; It is simplicity and readability.
Get the source codes here:
Comments are provided as needed to understand the program. But the user must read sufficient SHA documentation to understand the underlying theory correctly. It is not possible to describe the design of the SHA algorithm in detail here. For the complete description of the algorithm, point your browser to:
(The document also contains description of SHA-2 variants viz. SHA-224, SHA-256, SHA-384, and SHA-512)
Find the Wikipedia page of SHA at:
SHA-1 is employed in several widely used security applications and protocols, including TLS and SSL, PGP, SSH, S/MIME, and IPsec. It was considered to be the successor to MD5, an earlier, widely-used hash function. The other variants of the algorithm collectively called SHA-2 are also in wide use now.
No license. This is an open source and free website. Use the resources as you like. Please link to this page and give credits if you can. And promote open source.
Author: Niyaz PK