1.\" $NetBSD: mdX.3,v 1.12 2018/05/23 06:08:01 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 May 22, 2018 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.In sys/types.h 29.In mdX.h 30.Ft void 31.Fn MDXInit "MDX_CTX *context" 32.Ft void 33.Fn MDXUpdate "MDX_CTX *context" "const 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 "const char *filename" "char *buf" 40.Ft "char *" 41.Fn MDXData "const 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.Xr openssl_MD2 3 , 110.Xr openssl_MD4 3 , 111.Xr openssl_MD5 3 112.Rs 113.%A B. Kaliski 114.%T The MD2 Message-Digest Algorithm 115.%O RFC 1319 116.Re 117.Rs 118.%A R. Rivest 119.%T The MD4 Message-Digest Algorithm 120.%O RFC 1186 121.Re 122.Rs 123.%A R. Rivest 124.%T The MD5 Message-Digest Algorithm 125.%O RFC 1321 126.Re 127.Rs 128.%A RSA Laboratories 129.%T Frequently Asked Questions About today's Cryptography 130.Re 131.Sh HISTORY 132These functions appeared in 133.Nx 1.3 . 134.Sh AUTHORS 135.An -nosplit 136The original MDX routines were developed by 137.An RSA Data Security, Inc. , 138and published in the above references. 139This code is derived directly from these implementations by 140.An Poul-Henning Kamp Aq Mt phk@login.dkuug.dk . 141.Pp 142Phk ristede runen. 143.Sh BUGS 144No method is known to exist which finds two files having the same hash value, 145nor to find a file with a specific hash value. 146There is on the other hand no guarantee that such a method doesn't exist. 147