
#include "devel_template.inc" title="MD5 Algorithm"


<H1><IMG alt=MD5 height=109 src="md5.gif" width=208></H1>
<H2>Command Line Message Digest Utility </H2></CENTER>
<HR>

<P>This page describes <B>md5</B>, a command line utility usable on either Unix 
or MS-DOS/Windows, which generates and verifies message digests (digital 
signatures) using the MD5 algorithm. This program can be useful when developing 
shell scripts or Perl programs for software installation, file comparison, and 
detection of file corruption and tampering. 
<P>
<H3>NAME</H3><B>md5</B> - generate / check MD5 message digest 
<H3>SYNOPSIS</H3><B>md5</B> [ <B>-c</B><I>signature</I> ] [ <B>-u</B> ] [ 
<B>-d</B><I>input_text</I> | <EM>infile</EM> ] [ <EM>outfile</EM> ] 
<H3>DESCRIPTION</H3>A <EM>message digest</EM> is a compact digital signature for 
an arbitrarily long stream of binary data. An ideal message digest algorithm 
would never generate the same signature for two different sets of input, but 
achieving such theoretical perfection would require a message digest as long as 
the input file. Practical message digest algorithms compromise in favour of a 
digital signature of modest size created with an algorithm designed to make 
preparation of input text with a given signature computationally infeasible. 
Message digest algorithms have much in common with techniques used in 
encryption, but to a different end; verification that data have not been altered 
since the signature was published. 
<P>Many older programs requiring digital signatures employed 16 or 32 bit 
<EM>cyclical redundancy codes</EM> (CRC) originally developed to verify correct 
transmission in data communication protocols, but these short codes, while 
adequate to detect the kind of transmission errors for which they were intended, 
are insufficiently secure for applications such as electronic commerce and 
verification of security related software distributions. 
<P>The most commonly used present-day message digest algorithm is the 128 bit 
MD5 algorithm, developed by Ron Rivest of the <A 
href="http://web.mit.edu/">MIT</A> <A href="http://www.lcs.mit.edu/">Laboratory 
for Computer Science</A> and <A href="http://www.rsa.com/">RSA Data Security, 
Inc.</A> The algorithm, with a reference implementation, was published as 
Internet <A href="http://www.fourmilab.ch/md5/rfc1321.html">RFC 1321</A> in 
April 1992, and was placed into the public domain at that time. Message digest 
algorithms such as MD5 are not deemed "encryption technology" and are not 
subject to the export controls some governments impose on other data security 
products. (Obviously, the responsibility for obeying the laws in the 
jurisdiction in which you reside is entirely your own, but many common Web and 
Mail utilities use MD5, and I am unaware of any restrictions on their 
distribution and use.) 
<P>The MD5 algorithm has been implemented in numerous computer languages 
including C, <A href="http://www.perl.org/">Perl</A>, and <A 
href="http://www.javasoft.com/">Java</A>; if you're writing a program in such a 
language, track down a suitable subroutine and incorporate it into your program. 
The program described on this page is a <EM>command line</EM> implementation of 
MD5, intended for use in shell scripts and Perl programs (it is much faster than 
computing an MD5 signature directly in Perl). This <B>md5</B> program was 
originally developed as part of a suite of tools intended to monitor large 
collections of files (for example, the contents of a Web site) to detect 
corruption of files and inadvertent (or perhaps malicious) changes. That task is 
now best accomplished with more comprehensive packages such as <A 
href="ftp://coast.cs.purdue.edu/pub/COAST/Tripwire/">Tripwire</A>, but the 
command line <B>md5</B> component continues to prove useful for verifying 
correct delivery and installation of software packages, comparing the contents 
of two different systems, and checking for changes in specific files. 
<H3>OPTIONS</H3>
<DL compact>
  <DT><B>-c</B><I>signature</I> 
  <DD>Computes the signature of the specified <EM>infile</EM> or the string 
  supplied by the <B>-d</B> option and compares it against the specified 
  <I>signature</I>. If the two signatures match, the exit status will be zero, 
  otherwise the exit status will be 1. No signature is written to 
  <EM>outfile</EM> or standard output; only the exit status is set. The 
  signature to be checked must be specified as 32 hexadecimal digits. 
  <P></P>
  <DT><B>-d</B><I>input_text</I> 
  <DD>A signature is computed for the given <I>input_text</I> (which must be 
  quoted if it contains white space characters) instead of input from 
  <I>infile</I> or standard input. If input is specified with the <B>-d</B> 
  option, no <I>infile</I> should be specified. 
  <P></P>
  <DT><B>-u</B> 
  <DD>Print how-to-call information. </DD></DL>
<H3>FILES</H3>If no <EM>infile</EM> or <B>-d</B> option is specified or 
<EM>infile</EM> is a single "-", <B>md5</B> reads from standard input; if no 
<EM>outfile</EM> is given, or <EM>outfile</EM> is a single "-", output is sent 
to standard output. Input and output are processed strictly serially; 
consequently <B>md5</B> may be used in pipelines. 
<H3>BUGS</H3>The mechanism used to set standard input to binary mode may be 
specific to Microsoft C; if you rebuild the DOS/Windows version of the program 
from source using another compiler, be sure to verify binary files work properly 
when read via redirection or a pipe. 
<P>This program has not been tested on a machine on which <TT>int</TT> and/or 
<TT>long</TT> are longer than 32 bits. 
<H2><A href="http://www.fourmilab.ch/md5/md5.zip"><IMG align=middle alt="" 
height=40 src="file.gif" width=40></A> <A 
href="http://www.fourmilab.ch/md5/md5.zip">Download md5.zip</A> (Zipped 
archive)</H2>The program is provided as <A 
href="http://www.fourmilab.ch/md5/md5.zip">md5.zip</A>, a <A 
href="http://www.pkware.com/">Zipped</A> archive containing an ready-to-run 
Win32 command-line executable program, <CODE>md5.exe</CODE> (compiled using 
Microsoft Visual C++ 5.0), and in source code form along with a 
<CODE>Makefile</CODE> to build the program under Unix. 
<H3>SEE ALSO</H3><B>sum</B>(1) 
<H3>EXIT STATUS</H3><B>md5</B> returns status 0 if processing was completed 
without errors, 1 if the <B>-c</B> option was specified and the given signature 
does not match that of the input, and 2 if processing could not be performed at 
all due, for example, to a nonexistent input file. 
<H3>COPYING</H3>
<BLOCKQUOTE>This software is in the public domain. Permission to use, copy, 
  modify, and distribute this software and its documentation for any purpose and 
  without fee is hereby granted, without any conditions or restrictions. This 
  software is provided "as is" without express or implied warranty. </BLOCKQUOTE>
<H3>ACKNOWLEDGEMENTS</H3>The MD5 algorithm was developed by Ron Rivest. The 
public domain C language implementation used in this program was written by 
Colin Plumb in 1993. 
<HR>

<ADDRESS><A href="http://www.fourmilab.ch/">by John Walker</A><BR>January 6th, 
MIM </ADDRESS>


<page_prev name="Bacula TCP/IP Network Protocol" url="netprotocol.html">
<page_next name="Smart Memory Allocation" url="smartall.html">
