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