]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libmd/mdX.3
zfs: merge openzfs/zfs@4647353c8
[FreeBSD/FreeBSD.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 .Dd May 21, 2019
10 .Dt MDX 3
11 .Os
12 .Sh NAME
13 .Nm MDXInit ,
14 .Nm MDXUpdate ,
15 .Nm MDXPad ,
16 .Nm MDXFinal ,
17 .Nm MDXEnd ,
18 .Nm MDXFile ,
19 .Nm MDXFileChunk ,
20 .Nm MDXData
21 .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
22 .Sh LIBRARY
23 .Lb libmd
24 .Sh SYNOPSIS
25 .In sys/types.h
26 .In mdX.h
27 .Ft void
28 .Fn MDXInit "MDX_CTX *context"
29 .Ft void
30 .Fn MDXUpdate "MDX_CTX *context" "const void *data" "unsigned int len"
31 .Ft void
32 .Fn MDXPad "MDX_CTX *context"
33 .Ft void
34 .Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context"
35 .Ft "char *"
36 .Fn MDXEnd "MDX_CTX *context" "char *buf"
37 .Ft "char *"
38 .Fn MDXFile "const char *filename" "char *buf"
39 .Ft "char *"
40 .Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
41 .Ft "char *"
42 .Fn MDXData "const void *data" "unsigned int len" "char *buf"
43 .Sh DESCRIPTION
44 The MDX functions calculate a 128-bit cryptographic checksum (digest)
45 for any number of input bytes.
46 A cryptographic checksum is a one-way
47 hash-function, that is, you cannot find (except by exhaustive search)
48 the input corresponding to a particular output.
49 This net result is a
50 .Dq fingerprint
51 of the input-data, which does not disclose the actual input.
52 .Pp
53 MD4 is the fastest and MD5 is somewhat slower.
54 MD4 has now been broken; it should only be used where necessary for
55 backward compatibility.
56 MD5 has not yet (1999-02-11) been broken, but sufficient attacks have been
57 made that its security is in some doubt.
58 The attacks on both MD4 and MD5
59 are both in the nature of finding
60 .Dq collisions
61 \[en]
62 that is, multiple
63 inputs which hash to the same value; it is still unlikely for an attacker
64 to be able to determine the exact original input given a hash value.
65 .Pp
66 The
67 .Fn MDXInit ,
68 .Fn MDXUpdate ,
69 and
70 .Fn MDXFinal
71 functions are the core functions.
72 Allocate an
73 .Vt MDX_CTX ,
74 initialize it with
75 .Fn MDXInit ,
76 run over the data with
77 .Fn MDXUpdate ,
78 and finally extract the result using
79 .Fn MDXFinal ,
80 which will also erase the
81 .Vt MDX_CTX .
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 ASCII string which represents the 128 bits in hexadecimal.
97 .Pp
98 The
99 .Fn MDXFile
100 function calculates the digest of a file, and uses
101 .Fn MDXEnd
102 to return the result.
103 If the file cannot be opened, a null pointer is returned.
104 The
105 .Fn MDXFileChunk
106 function is similar to
107 .Fn MDXFile ,
108 but it only calculates the digest over a byte-range of the file specified,
109 starting at
110 .Fa offset
111 and spanning
112 .Fa length
113 bytes.
114 If the
115 .Fa length
116 parameter is specified as 0, or more than the length of the remaining part
117 of the file,
118 .Fn MDXFileChunk
119 calculates the digest from
120 .Fa offset
121 to the end of file.
122 The
123 .Fn MDXData
124 function calculates the digest of a chunk of data in memory, and uses
125 .Fn MDXEnd
126 to return the result.
127 .Pp
128 When using
129 .Fn MDXEnd ,
130 .Fn MDXFile ,
131 or
132 .Fn MDXData ,
133 the
134 .Fa buf
135 argument can be a null pointer, in which case the returned string
136 is allocated with
137 .Xr malloc 3
138 and subsequently must be explicitly deallocated using
139 .Xr free 3
140 after use.
141 If the
142 .Fa buf
143 argument is non-null it must point to at least 33 characters of buffer space.
144 .Sh ERRORS
145 The
146 .Fn MDXEnd
147 function called with a null buf argument may fail and return NULL if:
148 .Bl -tag -width Er
149 .It Bq Er ENOMEM
150 Insufficient storage space is available.
151 .El
152 .Pp
153 The
154 .Fn MDXFile
155 and
156 .Fn MDXFileChunk
157 may return NULL when underlying
158 .Xr open 2 ,
159 .Xr fstat 2 ,
160 .Xr lseek 2 ,
161 or
162 .Xr MDXEnd 3
163 fail.
164 .Sh SEE ALSO
165 .Xr md4 3 ,
166 .Xr md5 3 ,
167 .Xr ripemd 3 ,
168 .Xr sha 3 ,
169 .Xr sha256 3 ,
170 .Xr sha512 3 ,
171 .Xr skein 3
172 .Rs
173 .%A R. Rivest
174 .%T The MD4 Message-Digest Algorithm
175 .%O RFC 1186
176 .Re
177 .Rs
178 .%A R. Rivest
179 .%T The MD5 Message-Digest Algorithm
180 .%O RFC 1321
181 .Re
182 .Rs
183 .%A H. Dobbertin
184 .%T Alf Swindles Ann
185 .%J CryptoBytes
186 .%N 1(3):5
187 .%D 1995
188 .Re
189 .Rs
190 .%A MJ. B. Robshaw
191 .%T On Recent Results for MD2, MD4 and MD5
192 .%J RSA Laboratories Bulletin
193 .%N 4
194 .%D November 12, 1996
195 .Re
196 .Sh HISTORY
197 These functions appeared in
198 .Fx 2.0 .
199 .Sh AUTHORS
200 The original MDX routines were developed by
201 RSA Data Security, Inc., and published in the above references.
202 This code is derived directly from these implementations by
203 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
204 .Pp
205 Phk ristede runen.
206 .Sh BUGS
207 The MD5 algorithm has been proven to be vulnerable to practical collision
208 attacks and should not be relied upon to produce unique outputs,
209 .Em nor should they be used as part of a cryptographic signature scheme.