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.\" 9c6bcf724SPoul-Henning Kamp.\" $Id: mdX.3,v 1.12 1998/03/19 07:34:12 charnier Exp $ 10c9502b53SPoul-Henning Kamp.\" 1104422105SGarrett Wollman.Dd October 9, 1996 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. 5004422105SGarrett WollmanMD4 has been criticized for being too weak, so MD5 was developed in 5104422105SGarrett Wollmanresponse as ``MD4 with safety-belts''. When in doubt, use MD5. 5204422105SGarrett Wollman.Pp 53c9502b53SPoul-Henning KampThe 54c9502b53SPoul-Henning Kamp.Fn MDXInit , 5504422105SGarrett Wollman.Fn MDXUpdate , 56c9502b53SPoul-Henning Kampand 57c9502b53SPoul-Henning Kamp.Fn MDXFinal 5804422105SGarrett Wollmanfunctions are the core functions. Allocate an MDX_CTX, initialize it with 5904422105SGarrett Wollman.Fn MDXInit , 60c9502b53SPoul-Henning Kamprun over the data with 6104422105SGarrett Wollman.Fn MDXUpdate , 62c9502b53SPoul-Henning Kampand finally extract the result using 63c9502b53SPoul-Henning Kamp.Fn MDXFinal . 6404422105SGarrett Wollman.Pp 65c6bcf724SPoul-Henning Kamp.Fn MDXPad 66c6bcf724SPoul-Henning Kampcan be used to pad message data in same way 67c6bcf724SPoul-Henning Kampas done by 68c6bcf724SPoul-Henning Kamp.Fn MDXFinal 69c6bcf724SPoul-Henning Kampwithout terminating calculation. 70c6bcf724SPoul-Henning Kamp.Pp 71c9502b53SPoul-Henning Kamp.Fn MDXEnd 7205f65b29SPoul-Henning Kampis a wrapper for 7304422105SGarrett Wollman.Fn MDXFinal 7404422105SGarrett Wollmanwhich converts the return value to a 33-character 7504422105SGarrett Wollman(including the terminating '\e0') 7604422105SGarrett Wollman.Tn ASCII 7704422105SGarrett Wollmanstring which represents the 128 bits in hexadecimal. 7804422105SGarrett Wollman.Pp 79c9502b53SPoul-Henning Kamp.Fn MDXFile 8005f65b29SPoul-Henning Kampcalculates the digest of a file, and uses 81228a1015SJohn Polstra.Fn MDXEnd 8205f65b29SPoul-Henning Kampto return the result. 8304422105SGarrett WollmanIf the file cannot be opened, a null pointer is returned. 84c9502b53SPoul-Henning Kamp.Fn MDXData 8505f65b29SPoul-Henning Kampcalculates the digest of a chunk of data in memory, and uses 86228a1015SJohn Polstra.Fn MDXEnd 8705f65b29SPoul-Henning Kampto return the result. 8804422105SGarrett Wollman.Pp 89c9502b53SPoul-Henning KampWhen using 90c9502b53SPoul-Henning Kamp.Fn MDXEnd , 9104422105SGarrett Wollman.Fn MDXFile , 9205f65b29SPoul-Henning Kampor 93c9502b53SPoul-Henning Kamp.Fn MDXData , 9405f65b29SPoul-Henning Kampthe 9505f65b29SPoul-Henning Kamp.Ar buf 9604422105SGarrett Wollmanargument can be a null pointer, in which case the returned string 9704422105SGarrett Wollmanis allocated with 9805f65b29SPoul-Henning Kamp.Xr malloc 3 9905f65b29SPoul-Henning Kampand subsequently must be explicitly deallocated using 100c9502b53SPoul-Henning Kamp.Xr free 3 101c9502b53SPoul-Henning Kampafter use. 10205f65b29SPoul-Henning KampIf the 10305f65b29SPoul-Henning Kamp.Ar buf 10404422105SGarrett Wollmanargument is non-null it must point to at least 33 characters of buffer space. 105c9502b53SPoul-Henning Kamp.Sh SEE ALSO 106c9502b53SPoul-Henning Kamp.Xr md2 3 , 107c9502b53SPoul-Henning Kamp.Xr md4 3 , 108c9502b53SPoul-Henning Kamp.Xr md5 3 10904422105SGarrett Wollman.Rs 11004422105SGarrett Wollman.%A B. Kaliski 11104422105SGarrett Wollman.%T The MD2 Message-Digest Algorithm 11204422105SGarrett Wollman.%O RFC 1319 11304422105SGarrett Wollman.Re 11404422105SGarrett Wollman.Rs 11504422105SGarrett Wollman.%A R. Rivest 11604422105SGarrett Wollman.%T The MD4 Message-Digest Algorithm 11704422105SGarrett Wollman.%O RFC 1186 11804422105SGarrett Wollman.Re 11904422105SGarrett Wollman.Rs 12004422105SGarrett Wollman.%A R. Rivest 12104422105SGarrett Wollman.%T The MD5 Message-Digest Algorithm 12204422105SGarrett Wollman.%O RFC 1321 12304422105SGarrett Wollman.Re 12404422105SGarrett Wollman.Rs 12504422105SGarrett Wollman.%A RSA Laboratories 12604422105SGarrett Wollman.%T Frequently Asked Questions About today's Cryptography 12704422105SGarrett Wollman.Re 128a5941fc2SPhilippe Charnier.Sh AUTHORS 12904422105SGarrett WollmanThe original MDX routines were developed by 13004422105SGarrett Wollman.Tn RSA 13104422105SGarrett WollmanData Security, Inc., and published in the above references. 132a5941fc2SPhilippe CharnierThis code is derived directly from these implementations by 133a5941fc2SPhilippe Charnier.An Poul-Henning Kamp Aq phk@login.dkuug.dk 13404422105SGarrett Wollman.Pp 135c9502b53SPoul-Henning KampPhk ristede runen. 136c9502b53SPoul-Henning Kamp.Sh HISTORY 137c9502b53SPoul-Henning KampThese functions appeared in 1386c65d959SMike Pritchard.Fx 2.0 . 139c9502b53SPoul-Henning Kamp.Sh BUGS 140c9502b53SPoul-Henning KampNo method is known to exist which finds two files having the same hash value, 141c9502b53SPoul-Henning Kampnor to find a file with a specific hash value. 142c9502b53SPoul-Henning KampThere is on the other hand no guarantee that such a method doesn't exist. 14304422105SGarrett Wollman.Pp 14404422105SGarrett WollmanMD2 has only been licensed for use in Privacy Enhanced Mail. 145c9502b53SPoul-Henning KampUse MD4 or MD5 if that isn't what you're doing. 146c9502b53SPoul-Henning Kamp.Sh COPYRIGHT 147