1c9502b53SPoul-Henning Kamp.\" 2c9502b53SPoul-Henning Kamp.\" ---------------------------------------------------------------------------- 3c9502b53SPoul-Henning Kamp.\" "THE BEER-WARE LICENSE" (Revision 42): 4c9502b53SPoul-Henning Kamp.\" <phk@login.dkuug.dk> 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 13ed403116SRuslan Ermilov.Os FreeBSD 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 2752377df3SPoul-Henning Kamp.Fd #include <sys/types.h> 28c9502b53SPoul-Henning Kamp.Fd #include <mdX.h> 29c9502b53SPoul-Henning Kamp.Ft void 30c9502b53SPoul-Henning Kamp.Fn MDXInit "MDX_CTX *context" 31c9502b53SPoul-Henning Kamp.Ft void 3209589ca8SBruce Evans.Fn MDXUpdate "MDX_CTX *context" "const unsigned char *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 *" 4409589ca8SBruce Evans.Fn MDXData "const unsigned char *data" "unsigned int len" "char *buf" 45c9502b53SPoul-Henning Kamp.Sh DESCRIPTION 46c9502b53SPoul-Henning KampThe MDX functions calculate a 128-bit cryptographic checksum (digest) 47c9502b53SPoul-Henning Kampfor any number of input bytes. A cryptographic checksum is a one-way 48c9502b53SPoul-Henning Kamphash-function, that is, you cannot find (except by exhaustive search) 49c9502b53SPoul-Henning Kampthe input corresponding to a particular output. This net result is 50c9502b53SPoul-Henning Kampa ``fingerprint'' of the input-data, which doesn't disclose the actual 51c9502b53SPoul-Henning Kampinput. 5204422105SGarrett Wollman.Pp 53c9502b53SPoul-Henning KampMD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. 54c9502b53SPoul-Henning KampMD2 can only be used for Privacy-Enhanced Mail. 5548ee93d6SGarrett WollmanMD4 has now been broken; it should only be used where necessary for 5648ee93d6SGarrett Wollmanbackward compatibility. 5748ee93d6SGarrett WollmanMD5 has not yet (1999-02-11) been broken, but sufficient attacks have been 5848ee93d6SGarrett Wollmanmade that its security is in some doubt. The attacks on both MD4 and MD5 5948ee93d6SGarrett Wollmanare both in the nature of finding ``collisions'' \- that is, multiple 6048ee93d6SGarrett Wollmaninputs which hash to the same value; it is still unlikely for an attacker 6148ee93d6SGarrett Wollmanto be able to determine the exact original input given a hash value. 6204422105SGarrett Wollman.Pp 63c9502b53SPoul-Henning KampThe 64c9502b53SPoul-Henning Kamp.Fn MDXInit , 6504422105SGarrett Wollman.Fn MDXUpdate , 66c9502b53SPoul-Henning Kampand 67c9502b53SPoul-Henning Kamp.Fn MDXFinal 6804422105SGarrett Wollmanfunctions are the core functions. Allocate an MDX_CTX, initialize it with 6904422105SGarrett Wollman.Fn MDXInit , 70c9502b53SPoul-Henning Kamprun over the data with 7104422105SGarrett Wollman.Fn MDXUpdate , 72c9502b53SPoul-Henning Kampand finally extract the result using 73c9502b53SPoul-Henning Kamp.Fn MDXFinal . 7404422105SGarrett Wollman.Pp 75c6bcf724SPoul-Henning Kamp.Fn MDXPad 76c6bcf724SPoul-Henning Kampcan be used to pad message data in same way 77c6bcf724SPoul-Henning Kampas done by 78c6bcf724SPoul-Henning Kamp.Fn MDXFinal 79c6bcf724SPoul-Henning Kampwithout terminating calculation. 80c6bcf724SPoul-Henning Kamp.Pp 81c9502b53SPoul-Henning Kamp.Fn MDXEnd 8205f65b29SPoul-Henning Kampis a wrapper for 8304422105SGarrett Wollman.Fn MDXFinal 8404422105SGarrett Wollmanwhich converts the return value to a 33-character 8504422105SGarrett Wollman(including the terminating '\e0') 8604422105SGarrett Wollman.Tn ASCII 8704422105SGarrett Wollmanstring which represents the 128 bits in hexadecimal. 8804422105SGarrett Wollman.Pp 89c9502b53SPoul-Henning Kamp.Fn MDXFile 9005f65b29SPoul-Henning Kampcalculates the digest of a file, and uses 91228a1015SJohn Polstra.Fn MDXEnd 9205f65b29SPoul-Henning Kampto return the result. 9304422105SGarrett WollmanIf the file cannot be opened, a null pointer is returned. 948a24546cSPoul-Henning Kamp.Fn MDXFileChunk 958a24546cSPoul-Henning Kampis similar to 968a24546cSPoul-Henning Kamp.Fn MDXFile , 978a24546cSPoul-Henning Kampbut it only calculates the digest over a byte-range of the file specified, 988a24546cSPoul-Henning Kampstarting at 998a24546cSPoul-Henning Kamp.Ar offset 1008a24546cSPoul-Henning Kampand spanning 1018a24546cSPoul-Henning Kamp.Ar length 1028a24546cSPoul-Henning Kampbytes. 1038a24546cSPoul-Henning KampIf the 1048a24546cSPoul-Henning Kamp.Ar length 1058a24546cSPoul-Henning Kampparameter is specified as 0, or more than the length of the remaining part 1068a24546cSPoul-Henning Kampof the file, 1078a24546cSPoul-Henning Kamp.Fn MDXFileChunk 1088a24546cSPoul-Henning Kampcalculates the digest from 1098a24546cSPoul-Henning Kamp.Ar offset 1108a24546cSPoul-Henning Kampto the end of file. 111c9502b53SPoul-Henning Kamp.Fn MDXData 11205f65b29SPoul-Henning Kampcalculates the digest of a chunk of data in memory, and uses 113228a1015SJohn Polstra.Fn MDXEnd 11405f65b29SPoul-Henning Kampto return the result. 11504422105SGarrett Wollman.Pp 116c9502b53SPoul-Henning KampWhen using 117c9502b53SPoul-Henning Kamp.Fn MDXEnd , 11804422105SGarrett Wollman.Fn MDXFile , 11905f65b29SPoul-Henning Kampor 120c9502b53SPoul-Henning Kamp.Fn MDXData , 12105f65b29SPoul-Henning Kampthe 12205f65b29SPoul-Henning Kamp.Ar buf 12304422105SGarrett Wollmanargument can be a null pointer, in which case the returned string 12404422105SGarrett Wollmanis allocated with 12505f65b29SPoul-Henning Kamp.Xr malloc 3 12605f65b29SPoul-Henning Kampand subsequently must be explicitly deallocated using 127c9502b53SPoul-Henning Kamp.Xr free 3 128c9502b53SPoul-Henning Kampafter use. 12905f65b29SPoul-Henning KampIf the 13005f65b29SPoul-Henning Kamp.Ar buf 13104422105SGarrett Wollmanargument is non-null it must point to at least 33 characters of buffer space. 132c9502b53SPoul-Henning Kamp.Sh SEE ALSO 133c9502b53SPoul-Henning Kamp.Xr md2 3 , 134c9502b53SPoul-Henning Kamp.Xr md4 3 , 135c177a86bSGarrett Wollman.Xr md5 3 , 136c177a86bSGarrett Wollman.Xr sha 3 13704422105SGarrett Wollman.Rs 13804422105SGarrett Wollman.%A B. Kaliski 13904422105SGarrett Wollman.%T The MD2 Message-Digest Algorithm 14004422105SGarrett Wollman.%O RFC 1319 14104422105SGarrett Wollman.Re 14204422105SGarrett Wollman.Rs 14304422105SGarrett Wollman.%A R. Rivest 14404422105SGarrett Wollman.%T The MD4 Message-Digest Algorithm 14504422105SGarrett Wollman.%O RFC 1186 14604422105SGarrett Wollman.Re 14704422105SGarrett Wollman.Rs 14804422105SGarrett Wollman.%A R. Rivest 14904422105SGarrett Wollman.%T The MD5 Message-Digest Algorithm 15004422105SGarrett Wollman.%O RFC 1321 15104422105SGarrett Wollman.Re 15204422105SGarrett Wollman.Rs 15304422105SGarrett Wollman.%A RSA Laboratories 15404422105SGarrett Wollman.%T Frequently Asked Questions About today's Cryptography 15548ee93d6SGarrett Wollman.%O \&<http://www.rsa.com/rsalabs/faq/> 15648ee93d6SGarrett Wollman.Re 15748ee93d6SGarrett Wollman.Rs 15848ee93d6SGarrett Wollman.%A H. Dobbertin 15948ee93d6SGarrett Wollman.%T Alf Swindles Ann 16048ee93d6SGarrett Wollman.%J CryptoBytes 16148ee93d6SGarrett Wollman.%N 1(3):5 16248ee93d6SGarrett Wollman.%D 1995 16348ee93d6SGarrett Wollman.Re 16448ee93d6SGarrett Wollman.Rs 16548ee93d6SGarrett Wollman.%A MJ. B. Robshaw 16648ee93d6SGarrett Wollman.%T On Recent Results for MD2, MD4 and MD5 16748ee93d6SGarrett Wollman.%J RSA Laboratories Bulletin 16848ee93d6SGarrett Wollman.%N 4 16948ee93d6SGarrett Wollman.%D November 12, 1996 17004422105SGarrett Wollman.Re 171a5941fc2SPhilippe Charnier.Sh AUTHORS 17204422105SGarrett WollmanThe original MDX routines were developed by 17304422105SGarrett Wollman.Tn RSA 17404422105SGarrett WollmanData Security, Inc., and published in the above references. 175a5941fc2SPhilippe CharnierThis code is derived directly from these implementations by 176a5941fc2SPhilippe Charnier.An Poul-Henning Kamp Aq phk@login.dkuug.dk 17704422105SGarrett Wollman.Pp 178c9502b53SPoul-Henning KampPhk ristede runen. 179c9502b53SPoul-Henning Kamp.Sh HISTORY 180c9502b53SPoul-Henning KampThese functions appeared in 1816c65d959SMike Pritchard.Fx 2.0 . 182c9502b53SPoul-Henning Kamp.Sh BUGS 183c9502b53SPoul-Henning KampNo method is known to exist which finds two files having the same hash value, 184c9502b53SPoul-Henning Kampnor to find a file with a specific hash value. 185c9502b53SPoul-Henning KampThere is on the other hand no guarantee that such a method doesn't exist. 18604422105SGarrett Wollman.Pp 18704422105SGarrett WollmanMD2 has only been licensed for use in Privacy Enhanced Mail. 188c9502b53SPoul-Henning KampUse MD4 or MD5 if that isn't what you're doing. 189