f2b5ef472927580cbfe4121cb49d11ae19b5dbbb
[dragonfly.git] / lib / libmd / mdX.3
1 .\"
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 .\" ----------------------------------------------------------------------------
8 .\"
9 .\" $FreeBSD: src/lib/libmd/mdX.3,v 1.30 2006/01/17 15:35:56 phk Exp $
10 .\" $DragonFly: src/lib/libmd/mdX.3,v 1.4 2008/09/11 20:25:34 swildner Exp $
11 .\"
12 .Dd February 11, 1999
13 .Dt MDX 3
14 .Os
15 .Sh NAME
16 .Nm MDXInit ,
17 .Nm MDXUpdate ,
18 .Nm MDXPad ,
19 .Nm MDXFinal ,
20 .Nm MDXEnd ,
21 .Nm MDXFile ,
22 .Nm MDXFileChunk ,
23 .Nm MDXData
24 .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
25 .Sh LIBRARY
26 .Lb libmd
27 .Sh SYNOPSIS
28 .In sys/types.h
29 .In mdX.h
30 .Ft void
31 .Fn MDXInit "MDX_CTX *context"
32 .Ft void
33 .Fn MDXUpdate "MDX_CTX *context" "const void *data" "unsigned int len"
34 .Ft void
35 .Fn MDXPad "MDX_CTX *context"
36 .Ft void
37 .Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context"
38 .Ft "char *"
39 .Fn MDXEnd "MDX_CTX *context" "char *buf"
40 .Ft "char *"
41 .Fn MDXFile "const char *filename" "char *buf"
42 .Ft "char *"
43 .Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
44 .Ft "char *"
45 .Fn MDXData "const void *data" "unsigned int len" "char *buf"
46 .Sh DESCRIPTION
47 The MDX functions calculate a 128-bit cryptographic checksum (digest)
48 for any number of input bytes.
49 A cryptographic checksum is a one-way
50 hash-function, that is, you cannot find (except by exhaustive search)
51 the input corresponding to a particular output.
52 This net result is a
53 .Dq fingerprint
54 of the input-data, which does not disclose the actual input.
55 .Pp
56 MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle.
57 MD2 can only be used for Privacy-Enhanced Mail.
58 MD4 has now been broken; it should only be used where necessary for
59 backward compatibility.
60 MD5 has not yet (1999-02-11) been broken, but sufficient attacks have been
61 made that its security is in some doubt.
62 The attacks on both MD4 and MD5
63 are both in the nature of finding
64 .Dq collisions
65 \[en]
66 that is, multiple
67 inputs which hash to the same value; it is still unlikely for an attacker
68 to be able to determine the exact original input given a hash value.
69 .Pp
70 The
71 .Fn MDXInit ,
72 .Fn MDXUpdate ,
73 and
74 .Fn MDXFinal
75 functions are the core functions.
76 Allocate an
77 .Vt MDX_CTX ,
78 initialize it with
79 .Fn MDXInit ,
80 run over the data with
81 .Fn MDXUpdate ,
82 and finally extract the result using
83 .Fn MDXFinal .
84 .Pp
85 The
86 .Fn MDXPad
87 function can be used to pad message data in same way
88 as done by
89 .Fn MDXFinal
90 without terminating calculation.
91 .Pp
92 The
93 .Fn MDXEnd
94 function is a wrapper for
95 .Fn MDXFinal
96 which converts the return value to a 33-character
97 (including the terminating '\e0')
98 .Tn ASCII
99 string which represents the 128 bits in hexadecimal.
100 .Pp
101 The
102 .Fn MDXFile
103 function calculates the digest of a file, and uses
104 .Fn MDXEnd
105 to return the result.
106 If the file cannot be opened, a null pointer is returned.
107 The
108 .Fn MDXFileChunk
109 function is similar to
110 .Fn MDXFile ,
111 but it only calculates the digest over a byte-range of the file specified,
112 starting at
113 .Fa offset
114 and spanning
115 .Fa length
116 bytes.
117 If the
118 .Fa length
119 parameter is specified as 0, or more than the length of the remaining part
120 of the file,
121 .Fn MDXFileChunk
122 calculates the digest from
123 .Fa offset
124 to the end of file.
125 The
126 .Fn MDXData
127 function calculates the digest of a chunk of data in memory, and uses
128 .Fn MDXEnd
129 to return the result.
130 .Pp
131 When using
132 .Fn MDXEnd ,
133 .Fn MDXFile ,
134 or
135 .Fn MDXData ,
136 the
137 .Fa buf
138 argument can be a null pointer, in which case the returned string
139 is allocated with
140 .Xr malloc 3
141 and subsequently must be explicitly deallocated using
142 .Xr free 3
143 after use.
144 If the
145 .Fa buf
146 argument is non-null it must point to at least 33 characters of buffer space.
147 .Sh SEE ALSO
148 .Xr md2 3 ,
149 .Xr md4 3 ,
150 .Xr md5 3 ,
151 .Xr sha 3
152 .Rs
153 .%A B. Kaliski
154 .%T The MD2 Message-Digest Algorithm
155 .%O RFC 1319
156 .Re
157 .Rs
158 .%A R. Rivest
159 .%T The MD4 Message-Digest Algorithm
160 .%O RFC 1186
161 .Re
162 .Rs
163 .%A R. Rivest
164 .%T The MD5 Message-Digest Algorithm
165 .%O RFC 1321
166 .Re
167 .Rs
168 .%A RSA Laboratories
169 .%T Frequently Asked Questions About today's Cryptography
170 .%O \&<http://www.rsa.com/rsalabs/faq/>
171 .Re
172 .Rs
173 .%A H. Dobbertin
174 .%T Alf Swindles Ann
175 .%J CryptoBytes
176 .%N 1(3):5
177 .%D 1995
178 .Re
179 .Rs
180 .%A MJ. B. Robshaw
181 .%T On Recent Results for MD2, MD4 and MD5
182 .%J RSA Laboratories Bulletin
183 .%N 4
184 .%D November 12, 1996
185 .Re
186 .Sh HISTORY
187 These functions appeared in
188 .Fx 2.0 .
189 .Sh AUTHORS
190 The original MDX routines were developed by
191 .Tn RSA
192 Data Security, Inc., and published in the above references.
193 This code is derived directly from these implementations by
194 .An Poul-Henning Kamp Aq phk@FreeBSD.org
195 .Pp
196 Phk ristede runen.
197 .Sh BUGS
198 No method is known to exist which finds two files having the same hash value,
199 nor to find a file with a specific hash value.
200 There is on the other hand no guarantee that such a method does not exist.
201 .Pp
202 MD2 has only been licensed for use in Privacy Enhanced Mail.
203 Use MD4 or MD5 if that is not what you are doing.