1*0a6a1f1dSLionel Sambuc.\" $NetBSD: cksum.1,v 1.47 2014/08/31 07:23:53 wiz Exp $ 2280d8c66SLionel Sambuc.\" 3280d8c66SLionel Sambuc.\" Copyright (c) 1991, 1993 4280d8c66SLionel Sambuc.\" The Regents of the University of California. All rights reserved. 5280d8c66SLionel Sambuc.\" 6280d8c66SLionel Sambuc.\" This code is derived from software contributed to Berkeley by 7280d8c66SLionel Sambuc.\" the Institute of Electrical and Electronics Engineers, Inc. 8280d8c66SLionel Sambuc.\" 9280d8c66SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 10280d8c66SLionel Sambuc.\" modification, are permitted provided that the following conditions 11280d8c66SLionel Sambuc.\" are met: 12280d8c66SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 13280d8c66SLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 14280d8c66SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 15280d8c66SLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 16280d8c66SLionel Sambuc.\" documentation and/or other materials provided with the distribution. 17280d8c66SLionel Sambuc.\" 3. Neither the name of the University nor the names of its contributors 18280d8c66SLionel Sambuc.\" may be used to endorse or promote products derived from this software 19280d8c66SLionel Sambuc.\" without specific prior written permission. 20280d8c66SLionel Sambuc.\" 21280d8c66SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22280d8c66SLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23280d8c66SLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24280d8c66SLionel Sambuc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25280d8c66SLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26280d8c66SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27280d8c66SLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28280d8c66SLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29280d8c66SLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30280d8c66SLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31280d8c66SLionel Sambuc.\" SUCH DAMAGE. 32280d8c66SLionel Sambuc.\" 33280d8c66SLionel Sambuc.\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 34280d8c66SLionel Sambuc.\" 35*0a6a1f1dSLionel Sambuc.Dd August 31, 2014 36280d8c66SLionel Sambuc.Dt CKSUM 1 37280d8c66SLionel Sambuc.Os 38280d8c66SLionel Sambuc.Sh NAME 39280d8c66SLionel Sambuc.Nm cksum , 40280d8c66SLionel Sambuc.Nm md2 , 41280d8c66SLionel Sambuc.Nm md4 , 42280d8c66SLionel Sambuc.Nm md5 , 43280d8c66SLionel Sambuc.Nm rmd160 , 44280d8c66SLionel Sambuc.Nm sha1 , 45280d8c66SLionel Sambuc.Nm sum 46280d8c66SLionel Sambuc.Nd display file checksums and block counts 47280d8c66SLionel Sambuc.Sh SYNOPSIS 48280d8c66SLionel Sambuc.Nm cksum 49280d8c66SLionel Sambuc.Op Fl n 50*0a6a1f1dSLionel Sambuc.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc 51280d8c66SLionel Sambuc.Op Fl o Ar 1 Ns | Ns Ar 2 52280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 53280d8c66SLionel Sambuc.Nm sum 54280d8c66SLionel Sambuc.Op Fl n 55*0a6a1f1dSLionel Sambuc.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc 56280d8c66SLionel Sambuc.Op Fl o Ar 1 Ns | Ns Ar 2 57280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 58280d8c66SLionel Sambuc.Nm md2 59*0a6a1f1dSLionel Sambuc.Op Fl npqtx 60280d8c66SLionel Sambuc.Op Fl s Ar string 61280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 62280d8c66SLionel Sambuc.Nm md4 63*0a6a1f1dSLionel Sambuc.Op Fl npqtx 64280d8c66SLionel Sambuc.Op Fl s Ar string 65280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 66280d8c66SLionel Sambuc.Nm md5 67*0a6a1f1dSLionel Sambuc.Op Fl npqtx 68280d8c66SLionel Sambuc.Op Fl s Ar string 69280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 70280d8c66SLionel Sambuc.Nm rmd160 71*0a6a1f1dSLionel Sambuc.Op Fl npqtx 72280d8c66SLionel Sambuc.Op Fl s Ar string 73280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 74280d8c66SLionel Sambuc.Nm sha1 75*0a6a1f1dSLionel Sambuc.Op Fl npqtx 76280d8c66SLionel Sambuc.Op Fl s Ar string 77280d8c66SLionel Sambuc.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc 78280d8c66SLionel Sambuc.Sh DESCRIPTION 79280d8c66SLionel SambucThe 80280d8c66SLionel Sambuc.Nm 81280d8c66SLionel Sambucutility writes to the standard output three whitespace separated 82280d8c66SLionel Sambucfields for each input file. 83280d8c66SLionel SambucThese fields are a checksum 84280d8c66SLionel Sambuc.Tn CRC , 85280d8c66SLionel Sambucthe total number of octets in the file and the file name. 86280d8c66SLionel SambucIf no file name is specified, the standard input is used and no file name 87280d8c66SLionel Sambucis written. 88280d8c66SLionel Sambuc.Pp 89280d8c66SLionel SambucThe 90280d8c66SLionel Sambuc.Nm sum 91280d8c66SLionel Sambucutility is identical to the 92280d8c66SLionel Sambuc.Nm 93280d8c66SLionel Sambucutility, except that it defaults to using historic algorithm 1, as 94280d8c66SLionel Sambucdescribed below. 95280d8c66SLionel SambucIt is provided for compatibility only. 96280d8c66SLionel Sambuc.Pp 97280d8c66SLionel SambucThe 98280d8c66SLionel Sambuc.Nm md2 , 99280d8c66SLionel Sambuc.Nm md4 , 100280d8c66SLionel Sambuc.Nm md5 , 101280d8c66SLionel Sambuc.Nm sha1 , 102280d8c66SLionel Sambucand 103280d8c66SLionel Sambuc.Nm rmd160 104280d8c66SLionel Sambucutilities compute cryptographic hash functions, and write to standard 105280d8c66SLionel Sambucoutput the hexadecimal representation of the hash of their input. 106280d8c66SLionel Sambuc.Pp 107280d8c66SLionel SambucThe options are as follows: 108280d8c66SLionel Sambuc.Bl -tag -width indent 109280d8c66SLionel Sambuc.It Fl a Ar algorithm 110280d8c66SLionel SambucWhen invoked as 111280d8c66SLionel Sambuc.Nm cksum , 112280d8c66SLionel Sambucuse the specified 113280d8c66SLionel Sambuc.Ar algorithm . 114280d8c66SLionel SambucValid algorithms are: 115280d8c66SLionel Sambuc.Bl -column -offset indent ".Sy Algorithm" ".Sy Bits" ".Sy Description" 116280d8c66SLionel Sambuc.It Sy Algorithm Ta Sy Bits Ta Sy Description 117280d8c66SLionel Sambuc.It Li CRC Ta 32 Ta Default CRC algorithm 118280d8c66SLionel Sambuc.It Li MD2 Ta 128 Ta MD2, per Li RFC1319 119280d8c66SLionel Sambuc.It Li MD4 Ta 128 Ta MD4, per Li RFC1320 120280d8c66SLionel Sambuc.It Li MD5 Ta 128 Ta MD5, per Li RFC1321 121280d8c66SLionel Sambuc.It Li RMD160 Ta 160 Ta RIPEMD-160 122280d8c66SLionel Sambuc.It Li SHA1 Ta 160 Ta SHA-1, per Li FIPS PUB 180-1 123280d8c66SLionel Sambuc.It Li SHA256 Ta 256 Ta SHA-2 124280d8c66SLionel Sambuc.It Li SHA384 Ta 384 Ta SHA-2 125280d8c66SLionel Sambuc.It Li SHA512 Ta 512 Ta SHA-2 126280d8c66SLionel Sambuc.It Li old1 Ta 16 Ta Algorithm 1, per Fl o Ar 1 127280d8c66SLionel Sambuc.It Li old2 Ta 16 Ta Algorithm 2, per Fl o Ar 2 128280d8c66SLionel Sambuc.El 129280d8c66SLionel Sambuc.It Fl c Op Ar sumfile 130280d8c66SLionel SambucVerify (check) files against a list of checksums. 131280d8c66SLionel SambucThe list is read from 132280d8c66SLionel Sambuc.Ar sumfile , 133280d8c66SLionel Sambucor from stdin if no filename is given. 134280d8c66SLionel SambucE.g. first run 135280d8c66SLionel Sambuc.Dl Ic md5 *.tgz \*[Gt] MD5 136280d8c66SLionel Sambuc.Dl Ic sha1 *.tgz \*[Gt] SHA1 137280d8c66SLionel Sambucto generate a list of MD5 checksums in 138280d8c66SLionel Sambuc.Pa MD5 , 139280d8c66SLionel Sambucthen use the following command to verify them: 140280d8c66SLionel Sambuc.Dl Ic cat MD5 SHA1 | cksum -c 141280d8c66SLionel SambucIf an error is found during checksum verification, an error 142280d8c66SLionel Sambucmessage is printed, and the program returns an error code of 1. 143280d8c66SLionel Sambuc.It Fl o 144280d8c66SLionel SambucUse historic algorithms instead of the (superior) default one. 145280d8c66SLionel Sambuc.Pp 146280d8c66SLionel SambucAlgorithm 1 is the algorithm used by historic 147280d8c66SLionel Sambuc.Bx 148280d8c66SLionel Sambucsystems as the 149280d8c66SLionel Sambuc.Xr sum 1 150280d8c66SLionel Sambucalgorithm and by historic 151280d8c66SLionel Sambuc.At V 152280d8c66SLionel Sambucsystems as the 153280d8c66SLionel Sambuc.Xr sum 1 154280d8c66SLionel Sambucalgorithm when using the 155280d8c66SLionel Sambuc.Fl r 156280d8c66SLionel Sambucoption. 157280d8c66SLionel SambucThis is a 16-bit checksum, with a right rotation before each addition; 158280d8c66SLionel Sambucoverflow is discarded. 159280d8c66SLionel Sambuc.Pp 160280d8c66SLionel SambucAlgorithm 2 is the algorithm used by historic 161280d8c66SLionel Sambuc.At V 162280d8c66SLionel Sambucsystems as the 163280d8c66SLionel Sambucdefault 164280d8c66SLionel Sambuc.Xr sum 1 165280d8c66SLionel Sambucalgorithm. 166280d8c66SLionel SambucThis is a 32-bit checksum, and is defined as follows: 167280d8c66SLionel Sambuc.Bd -unfilled -offset indent 168280d8c66SLionel Sambucs = sum of all bytes; 169280d8c66SLionel Sambucr = s % 2^16 + (s % 2^32) / 2^16; 170280d8c66SLionel Sambuccksum = (r % 2^16) + r / 2^16; 171280d8c66SLionel Sambuc.Ed 172280d8c66SLionel Sambuc.Pp 173280d8c66SLionel SambucBoth algorithm 1 and 2 write to the standard output the same fields as 174280d8c66SLionel Sambucthe default algorithm except that the size of the file in bytes is 175280d8c66SLionel Sambucreplaced with the size of the file in blocks. 176280d8c66SLionel SambucFor historic reasons, the block size is 1024 for algorithm 1 and 512 177280d8c66SLionel Sambucfor algorithm 2. 178280d8c66SLionel SambucPartial blocks are rounded up. 179280d8c66SLionel Sambuc.It Fl w 180280d8c66SLionel SambucPrint warnings about malformed checksum files when verifying 181280d8c66SLionel Sambucchecksums with 182280d8c66SLionel Sambuc.Fl c . 183280d8c66SLionel Sambuc.El 184280d8c66SLionel Sambuc.Pp 185280d8c66SLionel SambucThe following options apply only when using the one of the message 186280d8c66SLionel Sambucdigest algorithms: 187280d8c66SLionel Sambuc.Bl -tag -width indent 188280d8c66SLionel Sambuc.It Fl n 189280d8c66SLionel SambucPrint the hash and the filename in the normal sum output form, with 190280d8c66SLionel Sambucthe hash at the left and the filename following on the right. 191280d8c66SLionel Sambuc.It Fl p 192280d8c66SLionel SambucEcho input from standard input to standard output, and append the 193280d8c66SLionel Sambucselected message digest. 194*0a6a1f1dSLionel Sambuc.It Fl q 195*0a6a1f1dSLionel SambucQuiet mode \(em only the checksum is printed out. 196*0a6a1f1dSLionel SambucOverrides the 197*0a6a1f1dSLionel Sambuc.Fl n 198*0a6a1f1dSLionel Sambucoption. 199280d8c66SLionel Sambuc.It Fl s Ar string 200280d8c66SLionel SambucPrint the hash of the given string 201280d8c66SLionel Sambuc.Ar string . 202280d8c66SLionel Sambuc.It Fl t 203280d8c66SLionel SambucRun a built-in message digest time trial. 204280d8c66SLionel Sambuc.It Fl x 205280d8c66SLionel SambucRun a built-in message digest test script. 206280d8c66SLionel SambucThe tests that are run 207280d8c66SLionel Sambucare supposed to encompass all the various tests in the suites that 208280d8c66SLionel Sambucaccompany the algorithms' descriptions with the exception of the 209280d8c66SLionel Sambuclast test for the SHA-1 algorithm and the RIPEMD-160 algorithm. 210280d8c66SLionel SambucThe 211280d8c66SLionel Sambuclast test for these is one million copies of the lower letter a. 212280d8c66SLionel Sambuc.El 213280d8c66SLionel Sambuc.Pp 214280d8c66SLionel SambucThe default 215280d8c66SLionel Sambuc.Tn CRC 216280d8c66SLionel Sambucused is based on the polynomial used for 217280d8c66SLionel Sambuc.Tn CRC 218280d8c66SLionel Sambucerror checking 219280d8c66SLionel Sambucin the networking standard 220280d8c66SLionel Sambuc.St -iso8802-3 . 221280d8c66SLionel SambucThe 222280d8c66SLionel Sambuc.Tn CRC 223280d8c66SLionel Sambucchecksum encoding is defined by the generating polynomial: 224280d8c66SLionel Sambuc.Pp 225280d8c66SLionel Sambuc.Bd -unfilled -offset indent 226280d8c66SLionel SambucG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 227280d8c66SLionel Sambuc x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 228280d8c66SLionel Sambuc.Ed 229280d8c66SLionel Sambuc.Pp 230280d8c66SLionel SambucMathematically, the 231280d8c66SLionel Sambuc.Tn CRC 232280d8c66SLionel Sambucvalue corresponding to a given file is defined by 233280d8c66SLionel Sambucthe following procedure: 234280d8c66SLionel Sambuc.Bd -filled -offset indent 235280d8c66SLionel SambucThe 236280d8c66SLionel Sambuc.Ar n 237280d8c66SLionel Sambucbits to be evaluated are considered to be the coefficients of a mod 2 238280d8c66SLionel Sambucpolynomial M(x) of degree 239280d8c66SLionel Sambuc.Ar n Ns \-1 . 240280d8c66SLionel SambucThese 241280d8c66SLionel Sambuc.Ar n 242280d8c66SLionel Sambucbits are the bits from the file, with the most significant bit being the most 243280d8c66SLionel Sambucsignificant bit of the first octet of the file and the last bit being the least 244280d8c66SLionel Sambucsignificant bit of the last octet, padded with zero bits (if necessary) to 245280d8c66SLionel Sambucachieve an integral number of octets, followed by one or more octets 246280d8c66SLionel Sambucrepresenting the length of the file as a binary value, least significant octet 247280d8c66SLionel Sambucfirst. 248280d8c66SLionel SambucThe smallest number of octets capable of representing this integer are used. 249280d8c66SLionel Sambuc.Pp 250280d8c66SLionel SambucM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 251280d8c66SLionel SambucG(x) using mod 2 division, producing a remainder R(x) of degree \*[Le] 31. 252280d8c66SLionel Sambuc.Pp 253280d8c66SLionel SambucThe coefficients of R(x) are considered to be a 32-bit sequence. 254280d8c66SLionel Sambuc.Pp 255280d8c66SLionel SambucThe bit sequence is complemented and the result is the CRC. 256280d8c66SLionel Sambuc.Ed 257280d8c66SLionel Sambuc.Pp 258280d8c66SLionel SambucThe 259280d8c66SLionel Sambuc.Nm 260280d8c66SLionel Sambucand 261280d8c66SLionel Sambuc.Nm sum 262280d8c66SLionel Sambucutilities exit 0 on success, and \*[Gt]0 if an error occurs. 263280d8c66SLionel Sambuc.Sh SEE ALSO 264280d8c66SLionel Sambuc.Xr openssl 1 , 265280d8c66SLionel Sambuc.Xr mtree 8 266280d8c66SLionel Sambuc.Pp 267280d8c66SLionel SambucThe default calculation is identical to that given in pseudo-code 268280d8c66SLionel Sambucin the following 269280d8c66SLionel Sambuc.Tn ACM 270280d8c66SLionel Sambucarticle. 271280d8c66SLionel Sambuc.Rs 272280d8c66SLionel Sambuc.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 273280d8c66SLionel Sambuc.%A Dilip V. Sarwate 27484d9c625SLionel Sambuc.%J "Communications of the ACM" 275280d8c66SLionel Sambuc.%D "August 1988" 276280d8c66SLionel Sambuc.Re 277280d8c66SLionel Sambuc.Rs 278280d8c66SLionel Sambuc.%A R. Rivest 279280d8c66SLionel Sambuc.%T The MD2 Message-Digest Algorithm 280280d8c66SLionel Sambuc.%O RFC 1319 281280d8c66SLionel Sambuc.Re 282280d8c66SLionel Sambuc.Rs 283280d8c66SLionel Sambuc.%A R. Rivest 284280d8c66SLionel Sambuc.%T The MD4 Message-Digest Algorithm 285280d8c66SLionel Sambuc.%O RFC 1186 and RFC 1320 286280d8c66SLionel Sambuc.Re 287280d8c66SLionel Sambuc.Rs 288280d8c66SLionel Sambuc.%A R. Rivest 289280d8c66SLionel Sambuc.%T The MD5 Message-Digest Algorithm 290280d8c66SLionel Sambuc.%O RFC 1321 291280d8c66SLionel Sambuc.Re 292280d8c66SLionel Sambuc.Rs 293280d8c66SLionel Sambuc.%A U.S. DOC/NIST 294280d8c66SLionel Sambuc.%T Secure Hash Standard 295280d8c66SLionel Sambuc.%O FIPS PUB 180-1 296280d8c66SLionel Sambuc.Re 297280d8c66SLionel Sambuc.Sh STANDARDS 298280d8c66SLionel SambucThe 299280d8c66SLionel Sambuc.Nm 300280d8c66SLionel Sambucutility is expected to conform to 301280d8c66SLionel Sambuc.St -p1003.1-2004 . 302280d8c66SLionel Sambuc.Sh HISTORY 303280d8c66SLionel SambucThe 304280d8c66SLionel Sambuc.Nm 305280d8c66SLionel Sambucutility appeared in 306280d8c66SLionel Sambuc.Bx 4.4 . 307280d8c66SLionel Sambuc.Nm md5 308280d8c66SLionel Sambucwas added in 309280d8c66SLionel Sambuc.Nx 1.3 . 310280d8c66SLionel SambucThe functionality for 311280d8c66SLionel Sambuc.Nm md2 , 312280d8c66SLionel Sambuc.Nm md4 , 313280d8c66SLionel Sambuc.Nm sha1 , 314280d8c66SLionel Sambucand 315280d8c66SLionel Sambuc.Nm rmd160 316280d8c66SLionel Sambucwas added in 317280d8c66SLionel Sambuc.Nx 1.6 . 318280d8c66SLionel SambucSupport for the SHA-2 algorithms 319280d8c66SLionel Sambuc.Po 320280d8c66SLionel Sambuc.Li SHA256 , 321280d8c66SLionel Sambuc.Li SHA384 , 322280d8c66SLionel Sambucand 323280d8c66SLionel Sambuc.Li SHA512 324280d8c66SLionel Sambuc.Pc 325280d8c66SLionel Sambucwas added in 326280d8c66SLionel Sambuc.Nx 3.0 . 327280d8c66SLionel SambucThe functionality to verify checksum stored in a file 328280d8c66SLionel Sambuc.Pq Fl c 329280d8c66SLionel Sambucfirst appeared in 330280d8c66SLionel Sambuc.Nx 4.0 . 331*0a6a1f1dSLionel SambucQuiet mode 332*0a6a1f1dSLionel Sambuc.Pq Fl q 333*0a6a1f1dSLionel Sambucwas added in 334*0a6a1f1dSLionel Sambuc.Nx 7.0 . 335280d8c66SLionel Sambuc.\" .Pp 336280d8c66SLionel Sambuc.\" The 337280d8c66SLionel Sambuc.\" .Nm sum 338280d8c66SLionel Sambuc.\" utility appeared in 339280d8c66SLionel Sambuc.\" .Bx ?.? 340280d8c66SLionel Sambuc.\" and 341280d8c66SLionel Sambuc.\" .At V . 342