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 47f4ddfb38SRuslan Ermilov.Op Fl o Ar 1 | 2 | 3 48f74fd6ecSPhilippe Charnier.Op Ar 492cbd6933SBruce Evans.Nm sum 50f74fd6ecSPhilippe Charnier.Op Ar 519b50d902SRodney W. Grimes.Sh DESCRIPTION 529b50d902SRodney W. GrimesThe 53f74fd6ecSPhilippe Charnier.Nm 549b50d902SRodney W. Grimesutility writes to the standard output three whitespace separated 559b50d902SRodney W. Grimesfields for each input file. 569b50d902SRodney W. GrimesThese fields are a checksum 579b50d902SRodney W. Grimes.Tn CRC , 589b50d902SRodney W. Grimesthe total number of octets in the file and the file name. 599b50d902SRodney W. GrimesIf no file name is specified, the standard input is used and no file name 609b50d902SRodney W. Grimesis written. 619b50d902SRodney W. Grimes.Pp 622cbd6933SBruce EvansThe 632cbd6933SBruce Evans.Nm sum 642cbd6933SBruce Evansutility is identical to the 65f74fd6ecSPhilippe Charnier.Nm 662cbd6933SBruce Evansutility, except that it defaults to using historic algorithm 1, as 672cbd6933SBruce Evansdescribed below. 682cbd6933SBruce EvansIt is provided for compatibility only. 692cbd6933SBruce Evans.Pp 709b50d902SRodney W. GrimesThe options are as follows: 719b50d902SRodney W. Grimes.Bl -tag -width indent 729b50d902SRodney W. Grimes.It Fl o 739b50d902SRodney W. GrimesUse historic algorithms instead of the (superior) default one. 749b50d902SRodney W. Grimes.Pp 759b50d902SRodney W. GrimesAlgorithm 1 is the algorithm used by historic 769b50d902SRodney W. Grimes.Bx 779b50d902SRodney W. Grimessystems as the 789b50d902SRodney W. Grimes.Xr sum 1 799b50d902SRodney W. Grimesalgorithm and by historic 809b50d902SRodney W. Grimes.At V 819b50d902SRodney W. Grimessystems as the 82f74fd6ecSPhilippe Charnier.Xr sum 1 839b50d902SRodney W. Grimesalgorithm when using the 849b50d902SRodney W. Grimes.Fl r 859b50d902SRodney W. Grimesoption. 869b50d902SRodney W. GrimesThis is a 16-bit checksum, with a right rotation before each addition; 879b50d902SRodney W. Grimesoverflow is discarded. 889b50d902SRodney W. Grimes.Pp 899b50d902SRodney W. GrimesAlgorithm 2 is the algorithm used by historic 909b50d902SRodney W. Grimes.At V 919b50d902SRodney W. Grimessystems as the 929b50d902SRodney W. Grimesdefault 93f74fd6ecSPhilippe Charnier.Xr sum 1 949b50d902SRodney W. Grimesalgorithm. 959b50d902SRodney W. GrimesThis is a 32-bit checksum, and is defined as follows: 969b50d902SRodney W. Grimes.Bd -unfilled -offset indent 979b50d902SRodney W. Grimess = sum of all bytes; 989b50d902SRodney W. Grimesr = s % 2^16 + (s % 2^32) / 2^16; 999b50d902SRodney W. Grimescksum = (r % 2^16) + r / 2^16; 1009b50d902SRodney W. Grimes.Ed 1019b50d902SRodney W. Grimes.Pp 10268d8bb38SPoul-Henning KampAlgorithm 3 is what is commonly called the 10368d8bb38SPoul-Henning Kamp.Ql 32bit CRC 10468d8bb38SPoul-Henning Kampalgorithm. 10568d8bb38SPoul-Henning KampThis is a 32-bit checksum. 10668d8bb38SPoul-Henning Kamp.Pp 1079b50d902SRodney W. GrimesBoth algorithm 1 and 2 write to the standard output the same fields as 1089b50d902SRodney W. Grimesthe default algorithm except that the size of the file in bytes is 1099b50d902SRodney W. Grimesreplaced with the size of the file in blocks. 1109b50d902SRodney W. GrimesFor historic reasons, the block size is 1024 for algorithm 1 and 512 1119b50d902SRodney W. Grimesfor algorithm 2. 1129b50d902SRodney W. GrimesPartial blocks are rounded up. 1139b50d902SRodney W. Grimes.El 1149b50d902SRodney W. Grimes.Pp 1159b50d902SRodney W. GrimesThe default 1169b50d902SRodney W. Grimes.Tn CRC 1179b50d902SRodney W. Grimesused is based on the polynomial used for 1189b50d902SRodney W. Grimes.Tn CRC 1199b50d902SRodney W. Grimeserror checking 1209b50d902SRodney W. Grimesin the networking standard 121f74fd6ecSPhilippe Charnier.St -iso8802-3 . 1229b50d902SRodney W. GrimesThe 1239b50d902SRodney W. Grimes.Tn CRC 1249b50d902SRodney W. Grimeschecksum encoding is defined by the generating polynomial: 1259b50d902SRodney W. Grimes.Pp 1269b50d902SRodney W. Grimes.Bd -unfilled -offset indent 1279b50d902SRodney W. GrimesG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 1289b50d902SRodney W. Grimes x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 1299b50d902SRodney W. Grimes.Ed 1309b50d902SRodney W. Grimes.Pp 1319b50d902SRodney W. GrimesMathematically, the 1329b50d902SRodney W. Grimes.Tn CRC 1339b50d902SRodney W. Grimesvalue corresponding to a given file is defined by 1349b50d902SRodney W. Grimesthe following procedure: 13546eea498SRuslan Ermilov.Bd -ragged -offset indent 1369b50d902SRodney W. GrimesThe 1379b50d902SRodney W. Grimes.Ar n 1389b50d902SRodney W. Grimesbits to be evaluated are considered to be the coefficients of a mod 2 1399b50d902SRodney W. Grimespolynomial M(x) of degree 1409b50d902SRodney W. Grimes.Ar n Ns \-1 . 1419b50d902SRodney W. GrimesThese 1429b50d902SRodney W. Grimes.Ar n 1439b50d902SRodney W. Grimesbits are the bits from the file, with the most significant bit being the most 1449b50d902SRodney W. Grimessignificant bit of the first octet of the file and the last bit being the least 1459b50d902SRodney W. Grimessignificant bit of the last octet, padded with zero bits (if necessary) to 1469b50d902SRodney W. Grimesachieve an integral number of octets, followed by one or more octets 1479b50d902SRodney W. Grimesrepresenting the length of the file as a binary value, least significant octet 1489b50d902SRodney W. Grimesfirst. 1499b50d902SRodney W. GrimesThe smallest number of octets capable of representing this integer are used. 1509b50d902SRodney W. Grimes.Pp 1519b50d902SRodney W. GrimesM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 1529b50d902SRodney W. GrimesG(x) using mod 2 division, producing a remainder R(x) of degree <= 31. 1539b50d902SRodney W. Grimes.Pp 1549b50d902SRodney W. GrimesThe coefficients of R(x) are considered to be a 32-bit sequence. 1559b50d902SRodney W. Grimes.Pp 1569b50d902SRodney W. GrimesThe bit sequence is complemented and the result is the CRC. 1579b50d902SRodney W. Grimes.Ed 158f74fd6ecSPhilippe Charnier.Sh DIAGNOSTICS 1599b50d902SRodney W. GrimesThe 160f74fd6ecSPhilippe Charnier.Nm 1612cbd6933SBruce Evansand 1622cbd6933SBruce Evans.Nm sum 1632cbd6933SBruce Evansutilities exit 0 on success, and >0 if an error occurs. 1649b50d902SRodney W. Grimes.Sh SEE ALSO 1652c0d39adSJohn-Mark Gurney.Xr md5 1 16698849115SRuslan Ermilov.Pp 1679b50d902SRodney W. GrimesThe default calculation is identical to that given in pseudo-code 1689b50d902SRodney W. Grimesin the following 1699b50d902SRodney W. Grimes.Tn ACM 1709b50d902SRodney W. Grimesarticle. 1719b50d902SRodney W. Grimes.Rs 1729b50d902SRodney W. Grimes.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 1739b50d902SRodney W. Grimes.%A Dilip V. Sarwate 1749b88faecSRuslan Ermilov.%J "Communications of the" Tn ACM 1759b50d902SRodney W. Grimes.%D "August 1988" 1769b50d902SRodney W. Grimes.Re 1779b50d902SRodney W. Grimes.Sh STANDARDS 1789b50d902SRodney W. GrimesThe 179f74fd6ecSPhilippe Charnier.Nm 180f8a42d82SPhilippe Charnierutility is expected to conform to 181f8a42d82SPhilippe Charnier.St -p1003.2-92 . 1829b50d902SRodney W. Grimes.Sh HISTORY 1839b50d902SRodney W. GrimesThe 184f74fd6ecSPhilippe Charnier.Nm 18593e0d62dSJohn-Mark Gurneyutility appeared in 1869b50d902SRodney W. Grimes.Bx 4.4 . 187