2 .\" ----------------------------------------------------------------------------
3 .\" "THE BEER-WARE LICENSE" (Revision 42):
4 .\" <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 .\" can do whatever you want with this stuff. If we meet some day, and you think
6 .\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 .\" ----------------------------------------------------------------------------
9 .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
10 .\" $FreeBSD: src/lib/libmd/sha.3,v 1.19 2005/06/16 19:01:06 ru Exp $
30 .Nd calculate the FIPS 160 and 160-1 ``SHA'' message digests
37 .Fn SHA_Init "SHA_CTX *context"
39 .Fn SHA_Update "SHA_CTX *context" "const void *data" "size_t len"
41 .Fn SHA_Final "unsigned char digest[20]" "SHA_CTX *context"
43 .Fn SHA_End "SHA_CTX *context" "char *buf"
45 .Fn SHA_File "const char *filename" "char *buf"
47 .Fn SHA_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
49 .Fn SHA_Data "const void *data" "unsigned int len" "char *buf"
51 .Fn SHA1_Init "SHA_CTX *context"
53 .Fn SHA1_Update "SHA_CTX *context" "const void *data" "size_t len"
55 .Fn SHA1_Final "unsigned char digest[20]" "SHA_CTX *context"
57 .Fn SHA1_End "SHA_CTX *context" "char *buf"
59 .Fn SHA1_File "const char *filename" "char *buf"
61 .Fn SHA1_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
63 .Fn SHA1_Data "const void *data" "unsigned int len" "char *buf"
69 functions calculate a 160-bit cryptographic checksum (digest)
70 for any number of input bytes.
71 A cryptographic checksum is a one-way
72 hash function; that is, it is computationally impractical to find
73 the input corresponding to a particular output.
77 of the input-data, which does not disclose the actual input.
82 is the original Secure Hash Algorithm specified in
85 It was quickly proven insecure, and has been superseded by
88 is included for compatibility purposes only.
95 functions are the core functions.
100 run over the data with
102 and finally extract the result using
108 which converts the return value to a 41-character
109 (including the terminating '\e0')
111 string which represents the 160 bits in hexadecimal.
114 calculates the digest of a file, and uses
116 to return the result.
117 If the file cannot be opened, a null pointer is returned.
121 but it only calculates the digest over a byte-range of the file specified,
129 parameter is specified as 0, or more than the length of the remaining part
132 calculates the digest from
136 calculates the digest of a chunk of data in memory, and uses
138 to return the result.
147 argument can be a null pointer, in which case the returned string
150 and subsequently must be explicitly deallocated using
155 argument is non-null it must point to at least 41 characters of buffer space.
163 These functions appeared in
166 The core hash routines were implemented by Eric Young based on the
171 No method is known to exist which finds two files having the same hash value,
172 nor to find a file with a specific hash value.
173 There is on the other hand no guarantee that such a method does not exist.
177 (Intel) implementation of
179 makes heavy use of the
181 instruction, which is not present on the original 80386.
184 on those processors will cause an illegal instruction trap.
185 (Arguably, the kernel should simply emulate this instruction.)