SHA256, SHA384 and SHA512 in C

This code implements the new versions of the US
NIST Secure Hash Algorithms (SHA) in C.
   
The code is primarily designed to offer SHA256 but
SHA384 and SHA512 are also supported.  SHA256 employs only
operations using 32-bit words and will hence be efficient
on Pentium family processors. But SHA384 and SHA512
both use variables that are 64-bits long and will hence
be slower on 32-bit machines.
   
The SHA256 interface is as follows (the SHA384 and SHA512 API's are similar):
   
typedef struct /* type to hold the SHA256 context */
	{
		uint32_t count[2];
		uint32_t hash[8];
		uint32_t wdat[16];
	}	sha256_ctx;
void sha256_begin(sha256_ctx ctx[1]);
void sha256_hash(const unsigned char data[], unsigned long len, sha256_ctx ctx[1]);
void sha256_end(unsigned char hval[], sha256_ctx ctx[1]);
     
The first call initialises a hash computation, the second
adds data to the hash and the third call returns the
final digest value as an array of bytes.
   
The performance of this code on a 1.2GHz PIII processor is
as follows for a hash of 100,000,000 characters:
   
Code                   SHA256     SHA384     SHA512
ANSI C                 4.7 sec    6.1 sec    6.1 sec
Microsoft Visual C     3.5 sec    5.8 sec    5.9 sec
   
Here are the files for the implementation:
   
	sha2.h the header file
	sha2.c the C source code
	uitypes.h a header file that defines fixed width unsigned integer types
	test.c a C test file
   
Please ensure that you set the platform byte order before compiling this code.



This code thanks to Brian Gladman:

	http://fp.gladman.plus.com/cryptography_technology/sha/index.htm