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 .\" ----------------------------------------------------------------------------
23 .Nd calculate the RSA Data Security, Inc., ``MDX'' message digest
27 .Fd #include <sys/types.h>
30 .Fn MDXInit "MDX_CTX *context"
32 .Fn MDXUpdate "MDX_CTX *context" "const unsigned char *data" "unsigned int len"
34 .Fn MDXPad "MDX_CTX *context"
36 .Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context"
38 .Fn MDXEnd "MDX_CTX *context" "char *buf"
40 .Fn MDXFile "const char *filename" "char *buf"
42 .Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
44 .Fn MDXData "const unsigned char *data" "unsigned int len" "char *buf"
46 The MDX functions calculate a 128-bit cryptographic checksum (digest)
47 for any number of input bytes. A cryptographic checksum is a one-way
48 hash-function, that is, you cannot find (except by exhaustive search)
49 the input corresponding to a particular output. This net result is
50 a ``fingerprint'' of the input-data, which doesn't disclose the actual
53 MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle.
54 MD2 can only be used for Privacy-Enhanced Mail.
55 MD4 has now been broken; it should only be used where necessary for
56 backward compatibility.
57 MD5 has not yet (1999-02-11) been broken, but sufficient attacks have been
58 made that its security is in some doubt. The attacks on both MD4 and MD5
59 are both in the nature of finding ``collisions'' \- that is, multiple
60 inputs which hash to the same value; it is still unlikely for an attacker
61 to be able to determine the exact original input given a hash value.
68 functions are the core functions. Allocate an MDX_CTX, initialize it with
70 run over the data with
72 and finally extract the result using
76 can be used to pad message data in same way
79 without terminating calculation.
84 which converts the return value to a 33-character
85 (including the terminating '\e0')
87 string which represents the 128 bits in hexadecimal.
90 calculates the digest of a file, and uses
93 If the file cannot be opened, a null pointer is returned.
97 but it only calculates the digest over a byte-range of the file specified,
105 parameter is specified as 0, or more than the length of the remaining part
108 calculates the digest from
112 calculates the digest of a chunk of data in memory, and uses
114 to return the result.
123 argument can be a null pointer, in which case the returned string
126 and subsequently must be explicitly deallocated using
131 argument is non-null it must point to at least 33 characters of buffer space.
139 .%T The MD2 Message-Digest Algorithm
144 .%T The MD4 Message-Digest Algorithm
149 .%T The MD5 Message-Digest Algorithm
154 .%T Frequently Asked Questions About today's Cryptography
155 .%O \&<http://www.rsa.com/rsalabs/faq/>
166 .%T On Recent Results for MD2, MD4 and MD5
167 .%J RSA Laboratories Bulletin
169 .%D November 12, 1996
172 The original MDX routines were developed by
174 Data Security, Inc., and published in the above references.
175 This code is derived directly from these implementations by
176 .An Poul-Henning Kamp Aq phk@login.dkuug.dk
180 These functions appeared in
183 No method is known to exist which finds two files having the same hash value,
184 nor to find a file with a specific hash value.
185 There is on the other hand no guarantee that such a method doesn't exist.
187 MD2 has only been licensed for use in Privacy Enhanced Mail.
188 Use MD4 or MD5 if that isn't what you're doing.