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.\" 9c9502b53SPoul-Henning Kamp.\" $FreeBSD$ 10c9502b53SPoul-Henning Kamp.\" 11c9502b53SPoul-Henning Kamp.Dd July 14, 1994 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 , 17c9502b53SPoul-Henning Kamp.Nm MDXFinal , 18c9502b53SPoul-Henning Kamp.Nm MDXEnd , 19c9502b53SPoul-Henning Kamp.Nm MDXFile , 20c9502b53SPoul-Henning Kamp.Nm MDXData . 21c9502b53SPoul-Henning Kamp.Nd calculate ``MDX'' cryptographic checksum 22c9502b53SPoul-Henning Kamp.Sh SYNOPSIS 23c9502b53SPoul-Henning Kamp.Fd #include <mdX.h> 24c9502b53SPoul-Henning Kamp.Ft void 25c9502b53SPoul-Henning Kamp.Fn MDXInit "MDX_CTX *context" 26c9502b53SPoul-Henning Kamp.Ft void 27c9502b53SPoul-Henning Kamp.Fn MDXUpdate "MDX_CTX *context" "unsigned char *data" "unsigned int len" 28c9502b53SPoul-Henning Kamp.Ft void 29c9502b53SPoul-Henning Kamp.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" 30c9502b53SPoul-Henning Kamp.Ft "char *" 3105f65b29SPoul-Henning Kamp.Fn MDXEnd "MDX_CTX *context" "char *buf" 32c9502b53SPoul-Henning Kamp.Ft "char *" 3305f65b29SPoul-Henning Kamp.Fn MDXFile "char *filename" "char *buf" 34c9502b53SPoul-Henning Kamp.Ft "char *" 3505f65b29SPoul-Henning Kamp.Fn MDXData "unsigned char *data" "unsigned int len" "char *buf" 36c9502b53SPoul-Henning Kamp.Sh DESCRIPTION 37c9502b53SPoul-Henning KampThe MDX functions calculate a 128-bit cryptographic checksum (digest) 38c9502b53SPoul-Henning Kampfor any number of input bytes. A cryptographic checksum is a one-way 39c9502b53SPoul-Henning Kamphash-function, that is, you cannot find (except by exhaustive search) 40c9502b53SPoul-Henning Kampthe input corresponding to a particular output. This net result is 41c9502b53SPoul-Henning Kampa ``fingerprint'' of the input-data, which doesn't disclose the actual 42c9502b53SPoul-Henning Kampinput. 43c9502b53SPoul-Henning Kamp 44c9502b53SPoul-Henning KampMD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. 45c9502b53SPoul-Henning KampMD2 can only be used for Privacy-Enhanced Mail. 46c9502b53SPoul-Henning KampMD4 has been critizised for being to weak, and MD5 was developed as a 47c9502b53SPoul-Henning Kampresponse to this as ``MD4 with safety-belts''. If in doubt, use MD5. 48c9502b53SPoul-Henning Kamp 49c9502b53SPoul-Henning KampThe 50c9502b53SPoul-Henning Kamp.Fn MDXInit , 51c9502b53SPoul-Henning Kamp.Fn MDXUpdate 52c9502b53SPoul-Henning Kampand 53c9502b53SPoul-Henning Kamp.Fn MDXFinal 54c9502b53SPoul-Henning Kampfunctions are the core functions. Allocate a MDX_CTX, initialize it with 55c9502b53SPoul-Henning Kamp.Fn MDXInit 56c9502b53SPoul-Henning Kamprun over the data with 57c9502b53SPoul-Henning Kamp.Fn MDXUpdate 58c9502b53SPoul-Henning Kampand finally extract the result using 59c9502b53SPoul-Henning Kamp.Fn MDXFinal . 60c9502b53SPoul-Henning Kamp 61c9502b53SPoul-Henning Kamp.Fn MDXEnd 6205f65b29SPoul-Henning Kampis a wrapper for 63c9502b53SPoul-Henning Kamp.Fn MDXFinal , 6405f65b29SPoul-Henning Kampwhich converts the return value to a 33 character (incl terminating NULL) 6505f65b29SPoul-Henning Kampascii string which represents the 128 bits in hexadecimal. 66c9502b53SPoul-Henning Kamp 67c9502b53SPoul-Henning Kamp.Fn MDXFile 6805f65b29SPoul-Henning Kampcalculates the digest of a file, and uses 6905f65b29SPoul-Henning Kamp.Fn MDXFinal 7005f65b29SPoul-Henning Kampto return the result. 71c9502b53SPoul-Henning KampIn case the file cannot be opened, NULL is returned. 72c9502b53SPoul-Henning Kamp 73c9502b53SPoul-Henning Kamp.Fn MDXData 7405f65b29SPoul-Henning Kampcalculates the digest of a chunk of data in memory, and uses 7505f65b29SPoul-Henning Kamp.Fn MDXFinal 7605f65b29SPoul-Henning Kampto return the result. 77c9502b53SPoul-Henning Kamp 78c9502b53SPoul-Henning KampWhen using 79c9502b53SPoul-Henning Kamp.Fn MDXEnd , 80c9502b53SPoul-Henning Kamp.Fn MDXFile 8105f65b29SPoul-Henning Kampor 82c9502b53SPoul-Henning Kamp.Fn MDXData , 8305f65b29SPoul-Henning Kampthe 8405f65b29SPoul-Henning Kamp.Ar buf 8505f65b29SPoul-Henning Kampargument can be NULL, in which case the returned string is allocated with 8605f65b29SPoul-Henning Kamp.Xr malloc 3 8705f65b29SPoul-Henning Kampand subsequently must be explicitly deallocated using 88c9502b53SPoul-Henning Kamp.Xr free 3 89c9502b53SPoul-Henning Kampafter use. 9005f65b29SPoul-Henning KampIf the 9105f65b29SPoul-Henning Kamp.Ar buf 9205f65b29SPoul-Henning Kampargument isn't NULL it must point to at least 33 characters of buffer space. 93c9502b53SPoul-Henning Kamp.Sh SEE ALSO 94c9502b53SPoul-Henning Kamp.Xr md2 3 , 95c9502b53SPoul-Henning Kamp.Xr md4 3 , 96c9502b53SPoul-Henning Kamp.Xr md5 3 97c9502b53SPoul-Henning Kamp.Pp 98c9502b53SPoul-Henning KampISOC 99c9502b53SPoul-Henning KampInternet Request For Comments 100c9502b53SPoul-Henning Kamp.%T RFC1319 , 101c9502b53SPoul-Henning Kamp.%T RFC1320 102c9502b53SPoul-Henning Kampand 103c9502b53SPoul-Henning Kamp.%T RFC1321 . 104c9502b53SPoul-Henning Kamp.Pp 105c9502b53SPoul-Henning KampRSA Laboratories 106c9502b53SPoul-Henning Kamp.%T Frequently Asked Questions About today's Cryptography . 107c9502b53SPoul-Henning Kamp.Sh AUTHOR 108c9502b53SPoul-Henning KampThe MD2, MD4 and MD5 is designed and written by Ron Rivest and published in 109c9502b53SPoul-Henning Kampthe above RFC's, including a reference implementation of each algorithm. 110c9502b53SPoul-Henning Kamp 111c9502b53SPoul-Henning KampThis code is derived directly from these implementations by Poul-Henning Kamp 112c9502b53SPoul-Henning Kamp<phk@login.dkuug.dk> 113c9502b53SPoul-Henning Kamp 114c9502b53SPoul-Henning KampPhk ristede runen. 115c9502b53SPoul-Henning Kamp.Sh HISTORY 116c9502b53SPoul-Henning KampThese functions appeared in 117c9502b53SPoul-Henning Kamp.Em FreeBSD-2.0 118c9502b53SPoul-Henning Kamp.Sh BUGS 119c9502b53SPoul-Henning KampNo method is known to exist which finds two files having the same hash value, 120c9502b53SPoul-Henning Kampnor to find a file with a specific hash value. 121c9502b53SPoul-Henning KampThere is on the other hand no guarantee that such a method doesn't exist. 122c9502b53SPoul-Henning Kamp 12305f65b29SPoul-Henning KampMD2 has only been released for use in Privacy Enhanced eMail. 124c9502b53SPoul-Henning KampUse MD4 or MD5 if that isn't what you're doing. 125c9502b53SPoul-Henning Kamp.Sh COPYRIGHT 126