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.\" 9c177a86bSGarrett Wollman.\" $Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp $ 10c9502b53SPoul-Henning Kamp.\" 1148ee93d6SGarrett Wollman.Dd February 11, 1999 12c9502b53SPoul-Henning Kamp.Dt MDX 3 13c9502b53SPoul-Henning Kamp.Os FreeBSD 2 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 , 21c211e812SMike Pritchard.Nm MDXData 2204422105SGarrett Wollman.Nd calculate the RSA Data Security, Inc., ``MDX'' message digest 23c9502b53SPoul-Henning Kamp.Sh SYNOPSIS 2452377df3SPoul-Henning Kamp.Fd #include <sys/types.h> 25c9502b53SPoul-Henning Kamp.Fd #include <mdX.h> 26c9502b53SPoul-Henning Kamp.Ft void 27c9502b53SPoul-Henning Kamp.Fn MDXInit "MDX_CTX *context" 28c9502b53SPoul-Henning Kamp.Ft void 2909589ca8SBruce Evans.Fn MDXUpdate "MDX_CTX *context" "const unsigned char *data" "unsigned int len" 30c9502b53SPoul-Henning Kamp.Ft void 31c6bcf724SPoul-Henning Kamp.Fn MDXPad "MDX_CTX *context" 32c6bcf724SPoul-Henning Kamp.Ft void 33c9502b53SPoul-Henning Kamp.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" 34c9502b53SPoul-Henning Kamp.Ft "char *" 3505f65b29SPoul-Henning Kamp.Fn MDXEnd "MDX_CTX *context" "char *buf" 36c9502b53SPoul-Henning Kamp.Ft "char *" 37f7787644SJoerg Wunsch.Fn MDXFile "const char *filename" "char *buf" 38c9502b53SPoul-Henning Kamp.Ft "char *" 3909589ca8SBruce Evans.Fn MDXData "const unsigned char *data" "unsigned int len" "char *buf" 40c9502b53SPoul-Henning Kamp.Sh DESCRIPTION 41c9502b53SPoul-Henning KampThe MDX functions calculate a 128-bit cryptographic checksum (digest) 42c9502b53SPoul-Henning Kampfor any number of input bytes. A cryptographic checksum is a one-way 43c9502b53SPoul-Henning Kamphash-function, that is, you cannot find (except by exhaustive search) 44c9502b53SPoul-Henning Kampthe input corresponding to a particular output. This net result is 45c9502b53SPoul-Henning Kampa ``fingerprint'' of the input-data, which doesn't disclose the actual 46c9502b53SPoul-Henning Kampinput. 4704422105SGarrett Wollman.Pp 48c9502b53SPoul-Henning KampMD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. 49c9502b53SPoul-Henning KampMD2 can only be used for Privacy-Enhanced Mail. 5048ee93d6SGarrett WollmanMD4 has now been broken; it should only be used where necessary for 5148ee93d6SGarrett Wollmanbackward compatibility. 5248ee93d6SGarrett WollmanMD5 has not yet (1999-02-11) been broken, but sufficient attacks have been 5348ee93d6SGarrett Wollmanmade that its security is in some doubt. The attacks on both MD4 and MD5 5448ee93d6SGarrett Wollmanare both in the nature of finding ``collisions'' \- that is, multiple 5548ee93d6SGarrett Wollmaninputs which hash to the same value; it is still unlikely for an attacker 5648ee93d6SGarrett Wollmanto be able to determine the exact original input given a hash value. 5704422105SGarrett Wollman.Pp 58c9502b53SPoul-Henning KampThe 59c9502b53SPoul-Henning Kamp.Fn MDXInit , 6004422105SGarrett Wollman.Fn MDXUpdate , 61c9502b53SPoul-Henning Kampand 62c9502b53SPoul-Henning Kamp.Fn MDXFinal 6304422105SGarrett Wollmanfunctions are the core functions. Allocate an MDX_CTX, initialize it with 6404422105SGarrett Wollman.Fn MDXInit , 65c9502b53SPoul-Henning Kamprun over the data with 6604422105SGarrett Wollman.Fn MDXUpdate , 67c9502b53SPoul-Henning Kampand finally extract the result using 68c9502b53SPoul-Henning Kamp.Fn MDXFinal . 6904422105SGarrett Wollman.Pp 70c6bcf724SPoul-Henning Kamp.Fn MDXPad 71c6bcf724SPoul-Henning Kampcan be used to pad message data in same way 72c6bcf724SPoul-Henning Kampas done by 73c6bcf724SPoul-Henning Kamp.Fn MDXFinal 74c6bcf724SPoul-Henning Kampwithout terminating calculation. 75c6bcf724SPoul-Henning Kamp.Pp 76c9502b53SPoul-Henning Kamp.Fn MDXEnd 7705f65b29SPoul-Henning Kampis a wrapper for 7804422105SGarrett Wollman.Fn MDXFinal 7904422105SGarrett Wollmanwhich converts the return value to a 33-character 8004422105SGarrett Wollman(including the terminating '\e0') 8104422105SGarrett Wollman.Tn ASCII 8204422105SGarrett Wollmanstring which represents the 128 bits in hexadecimal. 8304422105SGarrett Wollman.Pp 84c9502b53SPoul-Henning Kamp.Fn MDXFile 8505f65b29SPoul-Henning Kampcalculates the digest of a file, and uses 86228a1015SJohn Polstra.Fn MDXEnd 8705f65b29SPoul-Henning Kampto return the result. 8804422105SGarrett WollmanIf the file cannot be opened, a null pointer is returned. 89c9502b53SPoul-Henning Kamp.Fn MDXData 9005f65b29SPoul-Henning Kampcalculates the digest of a chunk of data in memory, and uses 91228a1015SJohn Polstra.Fn MDXEnd 9205f65b29SPoul-Henning Kampto return the result. 9304422105SGarrett Wollman.Pp 94c9502b53SPoul-Henning KampWhen using 95c9502b53SPoul-Henning Kamp.Fn MDXEnd , 9604422105SGarrett Wollman.Fn MDXFile , 9705f65b29SPoul-Henning Kampor 98c9502b53SPoul-Henning Kamp.Fn MDXData , 9905f65b29SPoul-Henning Kampthe 10005f65b29SPoul-Henning Kamp.Ar buf 10104422105SGarrett Wollmanargument can be a null pointer, in which case the returned string 10204422105SGarrett Wollmanis allocated with 10305f65b29SPoul-Henning Kamp.Xr malloc 3 10405f65b29SPoul-Henning Kampand subsequently must be explicitly deallocated using 105c9502b53SPoul-Henning Kamp.Xr free 3 106c9502b53SPoul-Henning Kampafter use. 10705f65b29SPoul-Henning KampIf the 10805f65b29SPoul-Henning Kamp.Ar buf 10904422105SGarrett Wollmanargument is non-null it must point to at least 33 characters of buffer space. 110c9502b53SPoul-Henning Kamp.Sh SEE ALSO 111c9502b53SPoul-Henning Kamp.Xr md2 3 , 112c9502b53SPoul-Henning Kamp.Xr md4 3 , 113c177a86bSGarrett Wollman.Xr md5 3 , 114c177a86bSGarrett Wollman.Xr sha 3 11504422105SGarrett Wollman.Rs 11604422105SGarrett Wollman.%A B. Kaliski 11704422105SGarrett Wollman.%T The MD2 Message-Digest Algorithm 11804422105SGarrett Wollman.%O RFC 1319 11904422105SGarrett Wollman.Re 12004422105SGarrett Wollman.Rs 12104422105SGarrett Wollman.%A R. Rivest 12204422105SGarrett Wollman.%T The MD4 Message-Digest Algorithm 12304422105SGarrett Wollman.%O RFC 1186 12404422105SGarrett Wollman.Re 12504422105SGarrett Wollman.Rs 12604422105SGarrett Wollman.%A R. Rivest 12704422105SGarrett Wollman.%T The MD5 Message-Digest Algorithm 12804422105SGarrett Wollman.%O RFC 1321 12904422105SGarrett Wollman.Re 13004422105SGarrett Wollman.Rs 13104422105SGarrett Wollman.%A RSA Laboratories 13204422105SGarrett Wollman.%T Frequently Asked Questions About today's Cryptography 13348ee93d6SGarrett Wollman.%O \&<http://www.rsa.com/rsalabs/faq/> 13448ee93d6SGarrett Wollman.Re 13548ee93d6SGarrett Wollman.Rs 13648ee93d6SGarrett Wollman.%A H. Dobbertin 13748ee93d6SGarrett Wollman.%T Alf Swindles Ann 13848ee93d6SGarrett Wollman.%J CryptoBytes 13948ee93d6SGarrett Wollman.%N 1(3):5 14048ee93d6SGarrett Wollman.%D 1995 14148ee93d6SGarrett Wollman.Re 14248ee93d6SGarrett Wollman.Rs 14348ee93d6SGarrett Wollman.%A MJ. B. Robshaw 14448ee93d6SGarrett Wollman.%T On Recent Results for MD2, MD4 and MD5 14548ee93d6SGarrett Wollman.%J RSA Laboratories Bulletin 14648ee93d6SGarrett Wollman.%N 4 14748ee93d6SGarrett Wollman.%D November 12, 1996 14804422105SGarrett Wollman.Re 149a5941fc2SPhilippe Charnier.Sh AUTHORS 15004422105SGarrett WollmanThe original MDX routines were developed by 15104422105SGarrett Wollman.Tn RSA 15204422105SGarrett WollmanData Security, Inc., and published in the above references. 153a5941fc2SPhilippe CharnierThis code is derived directly from these implementations by 154a5941fc2SPhilippe Charnier.An Poul-Henning Kamp Aq phk@login.dkuug.dk 15504422105SGarrett Wollman.Pp 156c9502b53SPoul-Henning KampPhk ristede runen. 157c9502b53SPoul-Henning Kamp.Sh HISTORY 158c9502b53SPoul-Henning KampThese functions appeared in 1596c65d959SMike Pritchard.Fx 2.0 . 160c9502b53SPoul-Henning Kamp.Sh BUGS 161c9502b53SPoul-Henning KampNo method is known to exist which finds two files having the same hash value, 162c9502b53SPoul-Henning Kampnor to find a file with a specific hash value. 163c9502b53SPoul-Henning KampThere is on the other hand no guarantee that such a method doesn't exist. 16404422105SGarrett Wollman.Pp 16504422105SGarrett WollmanMD2 has only been licensed for use in Privacy Enhanced Mail. 166c9502b53SPoul-Henning KampUse MD4 or MD5 if that isn't what you're doing. 167c9502b53SPoul-Henning Kamp.Sh COPYRIGHT 168