2 .\" ----------------------------------------------------------------------------
3 .\" "THE BEER-WARE LICENSE" (Revision 42):
4 .\" <phk@login.dkuug.dk> 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.4.2.5 2001/12/17 10:08:31 ru Exp $
11 .\" $DragonFly: src/lib/libmd/sha.3,v 1.3 2006/02/17 19:35:07 swildner Exp $
29 .Nd calculate the FIPS 160 and 160-1 ``SHA'' message digests
36 .Fn SHA_Init "SHA_CTX *context"
38 .Fn SHA_Update "SHA_CTX *context" "const unsigned char *data" "unsigned int len"
40 .Fn SHA_Final "unsigned char digest[20]" "SHA_CTX *context"
42 .Fn SHA_End "SHA_CTX *context" "char *buf"
44 .Fn SHA_File "const char *filename" "char *buf"
46 .Fn SHA_Data "const unsigned char *data" "unsigned int len" "char *buf"
48 .Fn SHA1_Init "SHA_CTX *context"
50 .Fn SHA1_Update "SHA_CTX *context" "const unsigned char *data" "unsigned int len"
52 .Fn SHA1_Final "unsigned char digest[20]" "SHA_CTX *context"
54 .Fn SHA1_End "SHA_CTX *context" "char *buf"
56 .Fn SHA1_File "const char *filename" "char *buf"
58 .Fn SHA1_Data "const unsigned char *data" "unsigned int len" "char *buf"
64 functions calculate a 160-bit cryptographic checksum (digest)
65 for any number of input bytes. A cryptographic checksum is a one-way
66 hash function; that is, it is computationally impractical to find
67 the input corresponding to a particular output. This net result is
68 a ``fingerprint'' of the input-data, which doesn't disclose the actual
74 is the original Secure Hash Algorithm specified in
76 160. It was quickly proven insecure, and has been superseded by
79 is included for compatibility purposes only.
86 functions are the core functions. Allocate an SHA_CTX, initialize it with
88 run over the data with
90 and finally extract the result using
96 which converts the return value to a 41-character
97 (including the terminating '\e0')
99 string which represents the 160 bits in hexadecimal.
102 calculates the digest of a file, and uses
104 to return the result.
105 If the file cannot be opened, a null pointer is returned.
107 calculates the digest of a chunk of data in memory, and uses
109 to return the result.
118 argument can be a null pointer, in which case the returned string
121 and subsequently must be explicitly deallocated using
126 argument is non-null it must point to at least 41 characters of buffer space.
133 These functions appeared in
136 The core hash routines were implemented by Eric Young based on the
141 No method is known to exist which finds two files having the same hash value,
142 nor to find a file with a specific hash value.
143 There is on the other hand no guarantee that such a method doesn't exist.
147 (Intel) implementation of
149 makes heavy use of the
151 instruction, which is not present on the original 80386. Attempts
154 on those processors will cause an illegal instruction trap.
155 (Arguably, the kernel should simply emulate this instruction.)