1.\" $NetBSD: mdX.3,v 1.8 2002/10/01 17:06:52 wiz Exp $ 2.\" 3.\" ---------------------------------------------------------------------------- 4.\" "THE BEER-WARE LICENSE" (Revision 42): 5.\" <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you 6.\" can do whatever you want with this stuff. If we meet some day, and you think 7.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 8.\" ---------------------------------------------------------------------------- 9.\" 10.\" from FreeBSD Id: mdX.3,v 1.7 1996/10/22 16:28:56 phk Exp 11.\" 12.Dd October 9, 1996 13.Dt MDX 3 14.Os 15.Sh NAME 16.Nm MDXInit , 17.Nm MDXUpdate , 18.Nm MDXFinal , 19.Nm MDXEnd , 20.Nm MDXFile , 21.Nm MDXData 22.Nd calculate the RSA Data Security, Inc., 23.Dq MDX 24message digest 25.Sh LIBRARY 26.Lb libc 27.Sh SYNOPSIS 28.Fd #include \*[Lt]sys/types.h\*[Gt] 29.Fd #include \*[Lt]mdX.h\*[Gt] 30.Ft void 31.Fn MDXInit "MDX_CTX *context" 32.Ft void 33.Fn MDXUpdate "MDX_CTX *context" "unsigned char *data" "unsigned int len" 34.Ft void 35.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" 36.Ft "char *" 37.Fn MDXEnd "MDX_CTX *context" "char *buf" 38.Ft "char *" 39.Fn MDXFile "char *filename" "char *buf" 40.Ft "char *" 41.Fn MDXData "unsigned char *data" "unsigned int len" "char *buf" 42.Sh DESCRIPTION 43The MDX functions calculate a 128-bit cryptographic checksum (digest) 44for any number of input bytes. 45A cryptographic checksum is a one-way 46hash-function, that is, you cannot find (except by exhaustive search) 47the input corresponding to a particular output. 48This net result is 49a ``fingerprint'' of the input-data, which doesn't disclose the actual 50input. 51.Pp 52MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. 53MD2 can only be used for Privacy-Enhanced Mail. 54MD4 has been criticized for being too weak, so MD5 was developed in 55response as ``MD4 with safety-belts''. 56When in doubt, use MD5. 57.Pp 58The 59.Fn MDXInit , 60.Fn MDXUpdate , 61and 62.Fn MDXFinal 63functions are the core functions. 64Allocate an MDX_CTX, initialize it with 65.Fn MDXInit , 66run over the data with 67.Fn MDXUpdate , 68and finally extract the result using 69.Fn MDXFinal . 70.Pp 71.Fn MDXEnd 72is a wrapper for 73.Fn MDXFinal 74which converts the return value to a 33-character 75(including the terminating '\e0') 76.Tn ASCII 77string which represents the 128 bits in hexadecimal. 78.Pp 79.Fn MDXFile 80calculates the digest of a file, and uses 81.Fn MDXEnd 82to return the result. 83If the file cannot be opened, a null pointer is returned. 84.Fn MDXData 85calculates the digest of a chunk of data in memory, and uses 86.Fn MDXEnd 87to return the result. 88.Pp 89When using 90.Fn MDXEnd , 91.Fn MDXFile , 92or 93.Fn MDXData , 94the 95.Ar buf 96argument can be a null pointer, in which case the returned string 97is allocated with 98.Xr malloc 3 99and subsequently must be explicitly deallocated using 100.Xr free 3 101after use. 102If the 103.Ar buf 104argument is non-null it must point to at least 33 characters of buffer space. 105.Sh SEE ALSO 106.Xr md2 3 , 107.Xr md4 3 , 108.Xr md5 3 109.Rs 110.%A B. Kaliski 111.%T The MD2 Message-Digest Algorithm 112.%O RFC 1319 113.Re 114.Rs 115.%A R. Rivest 116.%T The MD4 Message-Digest Algorithm 117.%O RFC 1186 118.Re 119.Rs 120.%A R. Rivest 121.%T The MD5 Message-Digest Algorithm 122.%O RFC 1321 123.Re 124.Rs 125.%A RSA Laboratories 126.%T Frequently Asked Questions About today's Cryptography 127.Re 128.Sh HISTORY 129These functions appeared in 130.Nx 1.3 . 131.Sh AUTHORS 132The original MDX routines were developed by 133.Tn RSA 134Data Security, Inc., and published in the above references. 135This code is derived directly from these implementations by Poul-Henning Kamp 136.Aq Li phk@login.dkuug.dk 137.Pp 138Phk ristede runen. 139.Sh BUGS 140No method is known to exist which finds two files having the same hash value, 141nor to find a file with a specific hash value. 142There is on the other hand no guarantee that such a method doesn't exist. 143.Sh COPYRIGHT 144