Next round of fixing all kinds of spelling mistakes.
[dragonfly.git] / lib / libmd / sha.3
CommitLineData
984263bc
MD
1.\"
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.\" ----------------------------------------------------------------------------
8.\"
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 $
0b84df5c 11.\" $DragonFly: src/lib/libmd/sha.3,v 1.3 2006/02/17 19:35:07 swildner Exp $
984263bc
MD
12.\"
13.Dd February 25, 1999
14.Dt SHA 3
15.Os
16.Sh NAME
17.Nm SHA_Init ,
18.Nm SHA_Update ,
19.Nm SHA_Final ,
20.Nm SHA_End ,
21.Nm SHA_File ,
22.Nm SHA_Data ,
23.Nm SHA1_Init ,
24.Nm SHA1_Update ,
25.Nm SHA1_Final ,
26.Nm SHA1_End ,
27.Nm SHA1_File ,
28.Nm SHA1_Data
29.Nd calculate the FIPS 160 and 160-1 ``SHA'' message digests
30.Sh LIBRARY
31.Lb libmd
32.Sh SYNOPSIS
33.In sys/types.h
34.In sha.h
35.Ft void
36.Fn SHA_Init "SHA_CTX *context"
37.Ft void
38.Fn SHA_Update "SHA_CTX *context" "const unsigned char *data" "unsigned int len"
39.Ft void
40.Fn SHA_Final "unsigned char digest[20]" "SHA_CTX *context"
41.Ft "char *"
42.Fn SHA_End "SHA_CTX *context" "char *buf"
43.Ft "char *"
44.Fn SHA_File "const char *filename" "char *buf"
45.Ft "char *"
46.Fn SHA_Data "const unsigned char *data" "unsigned int len" "char *buf"
47.Ft void
48.Fn SHA1_Init "SHA_CTX *context"
49.Ft void
50.Fn SHA1_Update "SHA_CTX *context" "const unsigned char *data" "unsigned int len"
51.Ft void
52.Fn SHA1_Final "unsigned char digest[20]" "SHA_CTX *context"
53.Ft "char *"
54.Fn SHA1_End "SHA_CTX *context" "char *buf"
55.Ft "char *"
56.Fn SHA1_File "const char *filename" "char *buf"
57.Ft "char *"
58.Fn SHA1_Data "const unsigned char *data" "unsigned int len" "char *buf"
59.Sh DESCRIPTION
60The
61.Li SHA_
62and
63.Li SHA1_
64functions calculate a 160-bit cryptographic checksum (digest)
65for any number of input bytes. A cryptographic checksum is a one-way
66hash function; that is, it is computationally impractical to find
67the input corresponding to a particular output. This net result is
68a ``fingerprint'' of the input-data, which doesn't disclose the actual
69input.
70.Pp
71.Tn SHA
72(or
73.Tn SHA-0 )
74is the original Secure Hash Algorithm specified in
75.Tn FIPS
76160. It was quickly proven insecure, and has been superseded by
77.Tn SHA-1 .
78.Tn SHA-0
79is included for compatibility purposes only.
80.Pp
81The
82.Fn SHA1_Init ,
83.Fn SHA1_Update ,
84and
85.Fn SHA1_Final
86functions are the core functions. Allocate an SHA_CTX, initialize it with
87.Fn SHA1_Init ,
88run over the data with
89.Fn SHA1_Update ,
90and finally extract the result using
91.Fn SHA1_Final .
92.Pp
93.Fn SHA1_End
94is a wrapper for
95.Fn SHA1_Final
96which converts the return value to a 41-character
97(including the terminating '\e0')
98.Tn ASCII
99string which represents the 160 bits in hexadecimal.
100.Pp
101.Fn SHA1_File
102calculates the digest of a file, and uses
103.Fn SHA1_End
104to return the result.
105If the file cannot be opened, a null pointer is returned.
106.Fn SHA1_Data
107calculates the digest of a chunk of data in memory, and uses
108.Fn SHA1_End
109to return the result.
110.Pp
111When using
112.Fn SHA1_End ,
113.Fn SHA1_File ,
114or
115.Fn SHA1_Data ,
116the
117.Fa buf
118argument can be a null pointer, in which case the returned string
119is allocated with
120.Xr malloc 3
121and subsequently must be explicitly deallocated using
122.Xr free 3
123after use.
124If the
125.Fa buf
126argument is non-null it must point to at least 41 characters of buffer space.
127.Sh SEE ALSO
128.Xr md2 3 ,
129.Xr md4 3 ,
130.Xr md5 3 ,
131.Xr ripemd 3
0b84df5c
SW
132.Sh HISTORY
133These functions appeared in
134.Fx 4.0 .
984263bc
MD
135.Sh AUTHORS
136The core hash routines were implemented by Eric Young based on the
137published
138.Tn FIPS
139standards.
984263bc
MD
140.Sh BUGS
141No method is known to exist which finds two files having the same hash value,
142nor to find a file with a specific hash value.
143There is on the other hand no guarantee that such a method doesn't exist.
144.Pp
145The
146.Tn IA32
147(Intel) implementation of
148.Tn SHA-1
149makes heavy use of the
150.Ql bswapl
151instruction, which is not present on the original 80386. Attempts
152to use
153.Tn SHA-1
154on those processors will cause an illegal instruction trap.
155(Arguably, the kernel should simply emulate this instruction.)