1c9502b53SPoul-Henning Kamp.\" 2c9502b53SPoul-Henning Kamp.\" ---------------------------------------------------------------------------- 3c9502b53SPoul-Henning Kamp.\" "THE BEER-WARE LICENSE" (Revision 42): 442c159feSPoul-Henning Kamp.\" <phk@FreeBSD.org> wrote this file. As long as you retain this notice you 5c9502b53SPoul-Henning Kamp.\" can do whatever you want with this stuff. If we meet some day, and you think 6c9502b53SPoul-Henning Kamp.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7c9502b53SPoul-Henning Kamp.\" ---------------------------------------------------------------------------- 8c9502b53SPoul-Henning Kamp.\" 97f3dea24SPeter Wemm.\" $FreeBSD$ 10c9502b53SPoul-Henning Kamp.\" 1148ee93d6SGarrett Wollman.Dd February 11, 1999 12c9502b53SPoul-Henning Kamp.Dt MDX 3 13a307d598SRuslan Ermilov.Os 14c9502b53SPoul-Henning Kamp.Sh NAME 15c9502b53SPoul-Henning Kamp.Nm MDXInit , 16c9502b53SPoul-Henning Kamp.Nm MDXUpdate , 17c6bcf724SPoul-Henning Kamp.Nm MDXPad , 18c9502b53SPoul-Henning Kamp.Nm MDXFinal , 19c9502b53SPoul-Henning Kamp.Nm MDXEnd , 20c9502b53SPoul-Henning Kamp.Nm MDXFile , 218a24546cSPoul-Henning Kamp.Nm MDXFileChunk , 22c211e812SMike Pritchard.Nm MDXData 2304422105SGarrett Wollman.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest 249452ceebSAlexey Zelkin.Sh LIBRARY 259452ceebSAlexey Zelkin.Lb libmd 26c9502b53SPoul-Henning Kamp.Sh SYNOPSIS 2732eef9aeSRuslan Ermilov.In sys/types.h 2832eef9aeSRuslan Ermilov.In mdX.h 29c9502b53SPoul-Henning Kamp.Ft void 30c9502b53SPoul-Henning Kamp.Fn MDXInit "MDX_CTX *context" 31c9502b53SPoul-Henning Kamp.Ft void 3225a14196SPoul-Henning Kamp.Fn MDXUpdate "MDX_CTX *context" "const void *data" "unsigned int len" 33c9502b53SPoul-Henning Kamp.Ft void 34c6bcf724SPoul-Henning Kamp.Fn MDXPad "MDX_CTX *context" 35c6bcf724SPoul-Henning Kamp.Ft void 36c9502b53SPoul-Henning Kamp.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" 37c9502b53SPoul-Henning Kamp.Ft "char *" 3805f65b29SPoul-Henning Kamp.Fn MDXEnd "MDX_CTX *context" "char *buf" 39c9502b53SPoul-Henning Kamp.Ft "char *" 40f7787644SJoerg Wunsch.Fn MDXFile "const char *filename" "char *buf" 41c9502b53SPoul-Henning Kamp.Ft "char *" 428a24546cSPoul-Henning Kamp.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length" 438a24546cSPoul-Henning Kamp.Ft "char *" 4425a14196SPoul-Henning Kamp.Fn MDXData "const void *data" "unsigned int len" "char *buf" 45c9502b53SPoul-Henning Kamp.Sh DESCRIPTION 46c9502b53SPoul-Henning KampThe MDX functions calculate a 128-bit cryptographic checksum (digest) 47dc2af37dSHiten Pandyafor any number of input bytes. 48dc2af37dSHiten PandyaA cryptographic checksum is a one-way 49c9502b53SPoul-Henning Kamphash-function, that is, you cannot find (except by exhaustive search) 50dc2af37dSHiten Pandyathe input corresponding to a particular output. 51dc2af37dSHiten PandyaThis net result is a 52dc2af37dSHiten Pandya.Dq fingerprint 530227791bSRuslan Ermilovof the input-data, which does not disclose the actual input. 5404422105SGarrett Wollman.Pp 55c9502b53SPoul-Henning KampMD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. 56c9502b53SPoul-Henning KampMD2 can only be used for Privacy-Enhanced Mail. 5748ee93d6SGarrett WollmanMD4 has now been broken; it should only be used where necessary for 5848ee93d6SGarrett Wollmanbackward compatibility. 5948ee93d6SGarrett WollmanMD5 has not yet (1999-02-11) been broken, but sufficient attacks have been 60dc2af37dSHiten Pandyamade that its security is in some doubt. 61dc2af37dSHiten PandyaThe attacks on both MD4 and MD5 62dc2af37dSHiten Pandyaare both in the nature of finding 63dc2af37dSHiten Pandya.Dq collisions 64dc2af37dSHiten Pandya\[en] 65dc2af37dSHiten Pandyathat is, multiple 6648ee93d6SGarrett Wollmaninputs which hash to the same value; it is still unlikely for an attacker 6748ee93d6SGarrett Wollmanto be able to determine the exact original input given a hash value. 6804422105SGarrett Wollman.Pp 69c9502b53SPoul-Henning KampThe 70c9502b53SPoul-Henning Kamp.Fn MDXInit , 7104422105SGarrett Wollman.Fn MDXUpdate , 72c9502b53SPoul-Henning Kampand 73c9502b53SPoul-Henning Kamp.Fn MDXFinal 74dc2af37dSHiten Pandyafunctions are the core functions. 75dc2af37dSHiten PandyaAllocate an 76dc2af37dSHiten Pandya.Vt MDX_CTX , 77dc2af37dSHiten Pandyainitialize it with 7804422105SGarrett Wollman.Fn MDXInit , 79c9502b53SPoul-Henning Kamprun over the data with 8004422105SGarrett Wollman.Fn MDXUpdate , 81c9502b53SPoul-Henning Kampand finally extract the result using 82c9502b53SPoul-Henning Kamp.Fn MDXFinal . 8304422105SGarrett Wollman.Pp 840552350eSPhilippe CharnierThe 85c6bcf724SPoul-Henning Kamp.Fn MDXPad 860552350eSPhilippe Charnierfunction can be used to pad message data in same way 87c6bcf724SPoul-Henning Kampas done by 88c6bcf724SPoul-Henning Kamp.Fn MDXFinal 89c6bcf724SPoul-Henning Kampwithout terminating calculation. 90c6bcf724SPoul-Henning Kamp.Pp 910552350eSPhilippe CharnierThe 92c9502b53SPoul-Henning Kamp.Fn MDXEnd 930552350eSPhilippe Charnierfunction is a wrapper for 9404422105SGarrett Wollman.Fn MDXFinal 9504422105SGarrett Wollmanwhich converts the return value to a 33-character 9604422105SGarrett Wollman(including the terminating '\e0') 9704422105SGarrett Wollman.Tn ASCII 9804422105SGarrett Wollmanstring which represents the 128 bits in hexadecimal. 9904422105SGarrett Wollman.Pp 1000552350eSPhilippe CharnierThe 101c9502b53SPoul-Henning Kamp.Fn MDXFile 1020552350eSPhilippe Charnierfunction calculates the digest of a file, and uses 103228a1015SJohn Polstra.Fn MDXEnd 10405f65b29SPoul-Henning Kampto return the result. 10504422105SGarrett WollmanIf the file cannot be opened, a null pointer is returned. 1060552350eSPhilippe CharnierThe 1078a24546cSPoul-Henning Kamp.Fn MDXFileChunk 1080552350eSPhilippe Charnierfunction is similar to 1098a24546cSPoul-Henning Kamp.Fn MDXFile , 1108a24546cSPoul-Henning Kampbut it only calculates the digest over a byte-range of the file specified, 1118a24546cSPoul-Henning Kampstarting at 1127e5d6de0SRuslan Ermilov.Fa offset 1138a24546cSPoul-Henning Kampand spanning 1147e5d6de0SRuslan Ermilov.Fa length 1158a24546cSPoul-Henning Kampbytes. 1168a24546cSPoul-Henning KampIf the 1177e5d6de0SRuslan Ermilov.Fa length 1188a24546cSPoul-Henning Kampparameter is specified as 0, or more than the length of the remaining part 1198a24546cSPoul-Henning Kampof the file, 1208a24546cSPoul-Henning Kamp.Fn MDXFileChunk 1218a24546cSPoul-Henning Kampcalculates the digest from 1227e5d6de0SRuslan Ermilov.Fa offset 1238a24546cSPoul-Henning Kampto the end of file. 1240552350eSPhilippe CharnierThe 125c9502b53SPoul-Henning Kamp.Fn MDXData 1260552350eSPhilippe Charnierfunction calculates the digest of a chunk of data in memory, and uses 127228a1015SJohn Polstra.Fn MDXEnd 12805f65b29SPoul-Henning Kampto return the result. 12904422105SGarrett Wollman.Pp 130c9502b53SPoul-Henning KampWhen using 131c9502b53SPoul-Henning Kamp.Fn MDXEnd , 13204422105SGarrett Wollman.Fn MDXFile , 13305f65b29SPoul-Henning Kampor 134c9502b53SPoul-Henning Kamp.Fn MDXData , 13505f65b29SPoul-Henning Kampthe 1367e5d6de0SRuslan Ermilov.Fa buf 13704422105SGarrett Wollmanargument can be a null pointer, in which case the returned string 13804422105SGarrett Wollmanis allocated with 13905f65b29SPoul-Henning Kamp.Xr malloc 3 14005f65b29SPoul-Henning Kampand subsequently must be explicitly deallocated using 141c9502b53SPoul-Henning Kamp.Xr free 3 142c9502b53SPoul-Henning Kampafter use. 14305f65b29SPoul-Henning KampIf the 1447e5d6de0SRuslan Ermilov.Fa buf 14504422105SGarrett Wollmanargument is non-null it must point to at least 33 characters of buffer space. 146c9502b53SPoul-Henning Kamp.Sh SEE ALSO 147c9502b53SPoul-Henning Kamp.Xr md2 3 , 148c9502b53SPoul-Henning Kamp.Xr md4 3 , 149c177a86bSGarrett Wollman.Xr md5 3 , 150c177a86bSGarrett Wollman.Xr sha 3 15104422105SGarrett Wollman.Rs 15204422105SGarrett Wollman.%A B. Kaliski 15304422105SGarrett Wollman.%T The MD2 Message-Digest Algorithm 15404422105SGarrett Wollman.%O RFC 1319 15504422105SGarrett Wollman.Re 15604422105SGarrett Wollman.Rs 15704422105SGarrett Wollman.%A R. Rivest 15804422105SGarrett Wollman.%T The MD4 Message-Digest Algorithm 15904422105SGarrett Wollman.%O RFC 1186 16004422105SGarrett Wollman.Re 16104422105SGarrett Wollman.Rs 16204422105SGarrett Wollman.%A R. Rivest 16304422105SGarrett Wollman.%T The MD5 Message-Digest Algorithm 16404422105SGarrett Wollman.%O RFC 1321 16504422105SGarrett Wollman.Re 16604422105SGarrett Wollman.Rs 16704422105SGarrett Wollman.%A RSA Laboratories 16804422105SGarrett Wollman.%T Frequently Asked Questions About today's Cryptography 16948ee93d6SGarrett Wollman.%O \&<http://www.rsa.com/rsalabs/faq/> 17048ee93d6SGarrett Wollman.Re 17148ee93d6SGarrett Wollman.Rs 17248ee93d6SGarrett Wollman.%A H. Dobbertin 17348ee93d6SGarrett Wollman.%T Alf Swindles Ann 17448ee93d6SGarrett Wollman.%J CryptoBytes 17548ee93d6SGarrett Wollman.%N 1(3):5 17648ee93d6SGarrett Wollman.%D 1995 17748ee93d6SGarrett Wollman.Re 17848ee93d6SGarrett Wollman.Rs 17948ee93d6SGarrett Wollman.%A MJ. B. Robshaw 18048ee93d6SGarrett Wollman.%T On Recent Results for MD2, MD4 and MD5 18148ee93d6SGarrett Wollman.%J RSA Laboratories Bulletin 18248ee93d6SGarrett Wollman.%N 4 18348ee93d6SGarrett Wollman.%D November 12, 1996 18404422105SGarrett Wollman.Re 18524a0682cSRuslan Ermilov.Sh HISTORY 18624a0682cSRuslan ErmilovThese functions appeared in 18724a0682cSRuslan Ermilov.Fx 2.0 . 188a5941fc2SPhilippe Charnier.Sh AUTHORS 18904422105SGarrett WollmanThe original MDX routines were developed by 19004422105SGarrett Wollman.Tn RSA 19104422105SGarrett WollmanData Security, Inc., and published in the above references. 192a5941fc2SPhilippe CharnierThis code is derived directly from these implementations by 19342c159feSPoul-Henning Kamp.An Poul-Henning Kamp Aq phk@FreeBSD.org 19404422105SGarrett Wollman.Pp 195c9502b53SPoul-Henning KampPhk ristede runen. 196c9502b53SPoul-Henning Kamp.Sh BUGS 197c9502b53SPoul-Henning KampNo method is known to exist which finds two files having the same hash value, 198c9502b53SPoul-Henning Kampnor to find a file with a specific hash value. 1990227791bSRuslan ErmilovThere is on the other hand no guarantee that such a method does not exist. 20004422105SGarrett Wollman.Pp 20104422105SGarrett WollmanMD2 has only been licensed for use in Privacy Enhanced Mail. 202423ac680SRuslan ErmilovUse MD4 or MD5 if that is not what you are doing. 203