SHA_FILE(3)

NAME
sha_file, sha_stream, sha_memory - Secure Hash Algorithm

SYNOPSIS
sha_file(char *filename, unsigned long *hash)
void sha_stream(FILE *stream, unsigned long *hash)
void sha_memory(char *mem, long length, unsigned long *hash)

DESCRIPTION
These functions calculate the NIST Secure Hash Algorithm defined in FIPS 180 as modified by NSA in Summer 1994. In each function the hash pointer identifies a user-allocated array of five longs for the hash output, for a total of 160 bits. The first argument in sha_file() is the name of the file to process. It returns 0 if successful, non-zero if the file could not be opened. The first argument of sha_stream() is a previously-opened stream (e.g. stdin). sha_memory() expects a pointer to the block of memory to be hashed, and the length in bytes of the block to be hashed.

NIST suggests using the Secure Hash Algorithm as a message digesting function, producing a message-dependent fixed-size block that may be securely signed with a digital signature system such as NIST's DSS. Quoting from the draft standard, "The SHA is designed to have the following properties: it is computationally infeasible to recover a message corresponding to a given message digest, or to find two different messages which produce the same message digest."

It may also be used as an ordinary file checksum.

LIMITATIONS
The sha_memory() call processes blocks only up to 4 gigabytes. For longer samples, the stream version of sha (1) will probably be most convenient, e.g.:

perl moby_data.pl | sha

BUGS
NIST defines SHA for arbitrary bit strings. This implementation operates only at the byte level.

SEE ALSO
sum(1), sha(1), FIPS 180

AUTHOR
Jim Gillogly