52 lines
1.7 KiB
Text
52 lines
1.7 KiB
Text
The SHA (Secure Hash Algorithm) library.
|
|
SHA is a message digest algorithm that can be used to condense an arbitrary
|
|
length message down to a 20 byte hash. The functions all need to be passed
|
|
a SHA_CTX which is used to hold the SHA context during multiple SHA_Update()
|
|
function calls. The normal method of use for this library is as follows
|
|
This library contains both SHA and SHA-1 digest algorithms. SHA-1 is
|
|
an update to SHA (which should really be called SHA-0 now) which
|
|
tweaks the algorithm slightly. The SHA-1 algorithm is used by simply
|
|
using SHA1_Init(), SHA1_Update(), SHA1_Final() and SHA1() instead of the
|
|
SHA*() calls
|
|
|
|
SHA_Init(...);
|
|
SHA_Update(...);
|
|
...
|
|
SHA_Update(...);
|
|
SHA_Final(...);
|
|
|
|
This library requires the inclusion of 'sha.h'.
|
|
|
|
The functions are as follows:
|
|
|
|
void SHA_Init(
|
|
SHA_CTX *c);
|
|
This function needs to be called to initiate a SHA_CTX structure for
|
|
use.
|
|
|
|
void SHA_Update(
|
|
SHA_CTX *c;
|
|
unsigned char *data;
|
|
unsigned long len);
|
|
This updates the message digest context being generated with 'len'
|
|
bytes from the 'data' pointer. The number of bytes can be any
|
|
length.
|
|
|
|
void SHA_Final(
|
|
unsigned char *md;
|
|
SHA_CTX *c;
|
|
This function is called when a message digest of the data digested
|
|
with SHA_Update() is wanted. The message digest is put in the 'md'
|
|
array and is SHA_DIGEST_LENGTH (20) bytes long.
|
|
|
|
unsigned char *SHA(
|
|
unsigned char *d;
|
|
unsigned long n;
|
|
unsigned char *md;
|
|
This function performs a SHA_Init(), followed by a SHA_Update()
|
|
followed by a SHA_Final() (using a local SHA_CTX).
|
|
The resulting digest is put into 'md' if it is not NULL.
|
|
Regardless of the value of 'md', the message
|
|
digest is returned from the function. If 'md' was NULL, the message
|
|
digest returned is being stored in a static structure.
|
|
|