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