19b50d902SRodney W. Grimes.\" Copyright (c) 1991, 1993 29b50d902SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 39b50d902SRodney W. Grimes.\" 49b50d902SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 59b50d902SRodney W. Grimes.\" the Institute of Electrical and Electronics Engineers, Inc. 69b50d902SRodney W. Grimes.\" 79b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 89b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions 99b50d902SRodney W. Grimes.\" are met: 109b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 119b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 129b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 139b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 149b50d902SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 159b50d902SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 169b50d902SRodney W. Grimes.\" must display the following acknowledgement: 179b50d902SRodney W. Grimes.\" This product includes software developed by the University of 189b50d902SRodney W. Grimes.\" California, Berkeley and its contributors. 199b50d902SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 209b50d902SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 219b50d902SRodney W. Grimes.\" without specific prior written permission. 229b50d902SRodney W. Grimes.\" 239b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 249b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 259b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 269b50d902SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 279b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 289b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 299b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 309b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 319b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 329b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 339b50d902SRodney W. Grimes.\" SUCH DAMAGE. 349b50d902SRodney W. Grimes.\" 35f8a42d82SPhilippe Charnier.\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 36c3aac50fSPeter Wemm.\" $FreeBSD$ 379b50d902SRodney W. Grimes.\" 38f8a42d82SPhilippe Charnier.Dd April 28, 1995 399b50d902SRodney W. Grimes.Dt CKSUM 1 409b50d902SRodney W. Grimes.Os BSD 4.4 419b50d902SRodney W. Grimes.Sh NAME 42a684cccdSMike Pritchard.Nm cksum , 43a684cccdSMike Pritchard.Nm sum 449b50d902SRodney W. Grimes.Nd display file checksums and block counts 459b50d902SRodney W. Grimes.Sh SYNOPSIS 468fe908efSRuslan Ermilov.Nm 47c3855cb0SDavid E. O'Brien.Oo 48c3855cb0SDavid E. O'Brien.Fl o Ar \&1 Xo 49c3855cb0SDavid E. O'Brien.No \&| 50c3855cb0SDavid E. O'Brien.Ar \&2 51c3855cb0SDavid E. O'Brien.No \&| 52c3855cb0SDavid E. O'Brien.Ar \&3 53c3855cb0SDavid E. O'Brien.Xc 54c3855cb0SDavid E. O'Brien.Oc 55f74fd6ecSPhilippe Charnier.Op Ar 562cbd6933SBruce Evans.Nm sum 57f74fd6ecSPhilippe Charnier.Op Ar 589b50d902SRodney W. Grimes.Sh DESCRIPTION 599b50d902SRodney W. GrimesThe 60f74fd6ecSPhilippe Charnier.Nm 619b50d902SRodney W. Grimesutility writes to the standard output three whitespace separated 629b50d902SRodney W. Grimesfields for each input file. 639b50d902SRodney W. GrimesThese fields are a checksum 649b50d902SRodney W. Grimes.Tn CRC , 659b50d902SRodney W. Grimesthe total number of octets in the file and the file name. 669b50d902SRodney W. GrimesIf no file name is specified, the standard input is used and no file name 679b50d902SRodney W. Grimesis written. 689b50d902SRodney W. Grimes.Pp 692cbd6933SBruce EvansThe 702cbd6933SBruce Evans.Nm sum 712cbd6933SBruce Evansutility is identical to the 72f74fd6ecSPhilippe Charnier.Nm 732cbd6933SBruce Evansutility, except that it defaults to using historic algorithm 1, as 742cbd6933SBruce Evansdescribed below. 752cbd6933SBruce EvansIt is provided for compatibility only. 762cbd6933SBruce Evans.Pp 779b50d902SRodney W. GrimesThe options are as follows: 789b50d902SRodney W. Grimes.Bl -tag -width indent 799b50d902SRodney W. Grimes.It Fl o 809b50d902SRodney W. GrimesUse historic algorithms instead of the (superior) default one. 819b50d902SRodney W. Grimes.Pp 829b50d902SRodney W. GrimesAlgorithm 1 is the algorithm used by historic 839b50d902SRodney W. Grimes.Bx 849b50d902SRodney W. Grimessystems as the 859b50d902SRodney W. Grimes.Xr sum 1 869b50d902SRodney W. Grimesalgorithm and by historic 879b50d902SRodney W. Grimes.At V 889b50d902SRodney W. Grimessystems as the 89f74fd6ecSPhilippe Charnier.Xr sum 1 909b50d902SRodney W. Grimesalgorithm when using the 919b50d902SRodney W. Grimes.Fl r 929b50d902SRodney W. Grimesoption. 939b50d902SRodney W. GrimesThis is a 16-bit checksum, with a right rotation before each addition; 949b50d902SRodney W. Grimesoverflow is discarded. 959b50d902SRodney W. Grimes.Pp 969b50d902SRodney W. GrimesAlgorithm 2 is the algorithm used by historic 979b50d902SRodney W. Grimes.At V 989b50d902SRodney W. Grimessystems as the 999b50d902SRodney W. Grimesdefault 100f74fd6ecSPhilippe Charnier.Xr sum 1 1019b50d902SRodney W. Grimesalgorithm. 1029b50d902SRodney W. GrimesThis is a 32-bit checksum, and is defined as follows: 1039b50d902SRodney W. Grimes.Bd -unfilled -offset indent 1049b50d902SRodney W. Grimess = sum of all bytes; 1059b50d902SRodney W. Grimesr = s % 2^16 + (s % 2^32) / 2^16; 1069b50d902SRodney W. Grimescksum = (r % 2^16) + r / 2^16; 1079b50d902SRodney W. Grimes.Ed 1089b50d902SRodney W. Grimes.Pp 10968d8bb38SPoul-Henning KampAlgorithm 3 is what is commonly called the 11068d8bb38SPoul-Henning Kamp.Ql 32bit CRC 11168d8bb38SPoul-Henning Kampalgorithm. 11268d8bb38SPoul-Henning KampThis is a 32-bit checksum. 11368d8bb38SPoul-Henning Kamp.Pp 1149b50d902SRodney W. GrimesBoth algorithm 1 and 2 write to the standard output the same fields as 1159b50d902SRodney W. Grimesthe default algorithm except that the size of the file in bytes is 1169b50d902SRodney W. Grimesreplaced with the size of the file in blocks. 1179b50d902SRodney W. GrimesFor historic reasons, the block size is 1024 for algorithm 1 and 512 1189b50d902SRodney W. Grimesfor algorithm 2. 1199b50d902SRodney W. GrimesPartial blocks are rounded up. 1209b50d902SRodney W. Grimes.El 1219b50d902SRodney W. Grimes.Pp 1229b50d902SRodney W. GrimesThe default 1239b50d902SRodney W. Grimes.Tn CRC 1249b50d902SRodney W. Grimesused is based on the polynomial used for 1259b50d902SRodney W. Grimes.Tn CRC 1269b50d902SRodney W. Grimeserror checking 1279b50d902SRodney W. Grimesin the networking standard 128f74fd6ecSPhilippe Charnier.St -iso8802-3 . 1299b50d902SRodney W. GrimesThe 1309b50d902SRodney W. Grimes.Tn CRC 1319b50d902SRodney W. Grimeschecksum encoding is defined by the generating polynomial: 1329b50d902SRodney W. Grimes.Pp 1339b50d902SRodney W. Grimes.Bd -unfilled -offset indent 1349b50d902SRodney W. GrimesG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 1359b50d902SRodney W. Grimes x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 1369b50d902SRodney W. Grimes.Ed 1379b50d902SRodney W. Grimes.Pp 1389b50d902SRodney W. GrimesMathematically, the 1399b50d902SRodney W. Grimes.Tn CRC 1409b50d902SRodney W. Grimesvalue corresponding to a given file is defined by 1419b50d902SRodney W. Grimesthe following procedure: 1429b50d902SRodney W. Grimes.Bd -filled -offset indent 1439b50d902SRodney W. GrimesThe 1449b50d902SRodney W. Grimes.Ar n 1459b50d902SRodney W. Grimesbits to be evaluated are considered to be the coefficients of a mod 2 1469b50d902SRodney W. Grimespolynomial M(x) of degree 1479b50d902SRodney W. Grimes.Ar n Ns \-1 . 1489b50d902SRodney W. GrimesThese 1499b50d902SRodney W. Grimes.Ar n 1509b50d902SRodney W. Grimesbits are the bits from the file, with the most significant bit being the most 1519b50d902SRodney W. Grimessignificant bit of the first octet of the file and the last bit being the least 1529b50d902SRodney W. Grimessignificant bit of the last octet, padded with zero bits (if necessary) to 1539b50d902SRodney W. Grimesachieve an integral number of octets, followed by one or more octets 1549b50d902SRodney W. Grimesrepresenting the length of the file as a binary value, least significant octet 1559b50d902SRodney W. Grimesfirst. 1569b50d902SRodney W. GrimesThe smallest number of octets capable of representing this integer are used. 1579b50d902SRodney W. Grimes.Pp 1589b50d902SRodney W. GrimesM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 1599b50d902SRodney W. GrimesG(x) using mod 2 division, producing a remainder R(x) of degree <= 31. 1609b50d902SRodney W. Grimes.Pp 1619b50d902SRodney W. GrimesThe coefficients of R(x) are considered to be a 32-bit sequence. 1629b50d902SRodney W. Grimes.Pp 1639b50d902SRodney W. GrimesThe bit sequence is complemented and the result is the CRC. 1649b50d902SRodney W. Grimes.Ed 165f74fd6ecSPhilippe Charnier.Sh DIAGNOSTICS 1669b50d902SRodney W. GrimesThe 167f74fd6ecSPhilippe Charnier.Nm 1682cbd6933SBruce Evansand 1692cbd6933SBruce Evans.Nm sum 1702cbd6933SBruce Evansutilities exit 0 on success, and >0 if an error occurs. 1719b50d902SRodney W. Grimes.Sh SEE ALSO 1722c0d39adSJohn-Mark Gurney.Xr md5 1 1732c0d39adSJohn-Mark Gurney.Rs 1749b50d902SRodney W. GrimesThe default calculation is identical to that given in pseudo-code 1759b50d902SRodney W. Grimesin the following 1769b50d902SRodney W. Grimes.Tn ACM 1779b50d902SRodney W. Grimesarticle. 1789b50d902SRodney W. Grimes.Rs 1799b50d902SRodney W. Grimes.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 1809b50d902SRodney W. Grimes.%A Dilip V. Sarwate 1819b50d902SRodney W. Grimes.%J "Communications of the \\*(tNACM\\*(sP" 1829b50d902SRodney W. Grimes.%D "August 1988" 1839b50d902SRodney W. Grimes.Re 1849b50d902SRodney W. Grimes.Sh STANDARDS 1859b50d902SRodney W. GrimesThe 186f74fd6ecSPhilippe Charnier.Nm 187f8a42d82SPhilippe Charnierutility is expected to conform to 188f8a42d82SPhilippe Charnier.St -p1003.2-92 . 1899b50d902SRodney W. Grimes.Sh HISTORY 1909b50d902SRodney W. GrimesThe 191f74fd6ecSPhilippe Charnier.Nm 19293e0d62dSJohn-Mark Gurneyutility appeared in 1939b50d902SRodney W. Grimes.Bx 4.4 . 194