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. 15fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 169b50d902SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 179b50d902SRodney W. Grimes.\" without specific prior written permission. 189b50d902SRodney W. Grimes.\" 199b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 209b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 219b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 229b50d902SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 239b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 249b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 259b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 269b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 279b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 289b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 299b50d902SRodney W. Grimes.\" SUCH DAMAGE. 309b50d902SRodney W. Grimes.\" 31f8a42d82SPhilippe Charnier.\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 32c3aac50fSPeter Wemm.\" $FreeBSD$ 339b50d902SRodney W. Grimes.\" 34f8a42d82SPhilippe Charnier.Dd April 28, 1995 359b50d902SRodney W. Grimes.Dt CKSUM 1 3662500372SRuslan Ermilov.Os 379b50d902SRodney W. Grimes.Sh NAME 38a684cccdSMike Pritchard.Nm cksum , 39a684cccdSMike Pritchard.Nm sum 409b50d902SRodney W. Grimes.Nd display file checksums and block counts 419b50d902SRodney W. Grimes.Sh SYNOPSIS 428fe908efSRuslan Ermilov.Nm 43f4ddfb38SRuslan Ermilov.Op Fl o Ar 1 | 2 | 3 44f74fd6ecSPhilippe Charnier.Op Ar 452cbd6933SBruce Evans.Nm sum 46f74fd6ecSPhilippe Charnier.Op Ar 479b50d902SRodney W. Grimes.Sh DESCRIPTION 489b50d902SRodney W. GrimesThe 49f74fd6ecSPhilippe Charnier.Nm 509b50d902SRodney W. Grimesutility writes to the standard output three whitespace separated 519b50d902SRodney W. Grimesfields for each input file. 529b50d902SRodney W. GrimesThese fields are a checksum 539b50d902SRodney W. Grimes.Tn CRC , 549b50d902SRodney W. Grimesthe total number of octets in the file and the file name. 559b50d902SRodney W. GrimesIf no file name is specified, the standard input is used and no file name 569b50d902SRodney W. Grimesis written. 579b50d902SRodney W. Grimes.Pp 582cbd6933SBruce EvansThe 592cbd6933SBruce Evans.Nm sum 602cbd6933SBruce Evansutility is identical to the 61f74fd6ecSPhilippe Charnier.Nm 622cbd6933SBruce Evansutility, except that it defaults to using historic algorithm 1, as 632cbd6933SBruce Evansdescribed below. 642cbd6933SBruce EvansIt is provided for compatibility only. 652cbd6933SBruce Evans.Pp 669b50d902SRodney W. GrimesThe options are as follows: 679b50d902SRodney W. Grimes.Bl -tag -width indent 689b50d902SRodney W. Grimes.It Fl o 699b50d902SRodney W. GrimesUse historic algorithms instead of the (superior) default one. 709b50d902SRodney W. Grimes.Pp 719b50d902SRodney W. GrimesAlgorithm 1 is the algorithm used by historic 729b50d902SRodney W. Grimes.Bx 739b50d902SRodney W. Grimessystems as the 749b50d902SRodney W. Grimes.Xr sum 1 759b50d902SRodney W. Grimesalgorithm and by historic 769b50d902SRodney W. Grimes.At V 779b50d902SRodney W. Grimessystems as the 78f74fd6ecSPhilippe Charnier.Xr sum 1 799b50d902SRodney W. Grimesalgorithm when using the 809b50d902SRodney W. Grimes.Fl r 819b50d902SRodney W. Grimesoption. 829b50d902SRodney W. GrimesThis is a 16-bit checksum, with a right rotation before each addition; 839b50d902SRodney W. Grimesoverflow is discarded. 849b50d902SRodney W. Grimes.Pp 859b50d902SRodney W. GrimesAlgorithm 2 is the algorithm used by historic 869b50d902SRodney W. Grimes.At V 879b50d902SRodney W. Grimessystems as the 889b50d902SRodney W. Grimesdefault 89f74fd6ecSPhilippe Charnier.Xr sum 1 909b50d902SRodney W. Grimesalgorithm. 919b50d902SRodney W. GrimesThis is a 32-bit checksum, and is defined as follows: 929b50d902SRodney W. Grimes.Bd -unfilled -offset indent 939b50d902SRodney W. Grimess = sum of all bytes; 949b50d902SRodney W. Grimesr = s % 2^16 + (s % 2^32) / 2^16; 959b50d902SRodney W. Grimescksum = (r % 2^16) + r / 2^16; 969b50d902SRodney W. Grimes.Ed 979b50d902SRodney W. Grimes.Pp 9868d8bb38SPoul-Henning KampAlgorithm 3 is what is commonly called the 9968d8bb38SPoul-Henning Kamp.Ql 32bit CRC 10068d8bb38SPoul-Henning Kampalgorithm. 10168d8bb38SPoul-Henning KampThis is a 32-bit checksum. 10268d8bb38SPoul-Henning Kamp.Pp 1039b50d902SRodney W. GrimesBoth algorithm 1 and 2 write to the standard output the same fields as 1049b50d902SRodney W. Grimesthe default algorithm except that the size of the file in bytes is 1059b50d902SRodney W. Grimesreplaced with the size of the file in blocks. 1069b50d902SRodney W. GrimesFor historic reasons, the block size is 1024 for algorithm 1 and 512 1079b50d902SRodney W. Grimesfor algorithm 2. 1089b50d902SRodney W. GrimesPartial blocks are rounded up. 1099b50d902SRodney W. Grimes.El 1109b50d902SRodney W. Grimes.Pp 1119b50d902SRodney W. GrimesThe default 1129b50d902SRodney W. Grimes.Tn CRC 1139b50d902SRodney W. Grimesused is based on the polynomial used for 1149b50d902SRodney W. Grimes.Tn CRC 1159b50d902SRodney W. Grimeserror checking 1169b50d902SRodney W. Grimesin the networking standard 117f74fd6ecSPhilippe Charnier.St -iso8802-3 . 1189b50d902SRodney W. GrimesThe 1199b50d902SRodney W. Grimes.Tn CRC 1209b50d902SRodney W. Grimeschecksum encoding is defined by the generating polynomial: 1219b50d902SRodney W. Grimes.Bd -unfilled -offset indent 1229b50d902SRodney W. GrimesG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 1239b50d902SRodney W. Grimes x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 1249b50d902SRodney W. Grimes.Ed 1259b50d902SRodney W. Grimes.Pp 1269b50d902SRodney W. GrimesMathematically, the 1279b50d902SRodney W. Grimes.Tn CRC 1289b50d902SRodney W. Grimesvalue corresponding to a given file is defined by 1299b50d902SRodney W. Grimesthe following procedure: 13046eea498SRuslan Ermilov.Bd -ragged -offset indent 1319b50d902SRodney W. GrimesThe 1329b50d902SRodney W. Grimes.Ar n 1339b50d902SRodney W. Grimesbits to be evaluated are considered to be the coefficients of a mod 2 1349b50d902SRodney W. Grimespolynomial M(x) of degree 1359b50d902SRodney W. Grimes.Ar n Ns \-1 . 1369b50d902SRodney W. GrimesThese 1379b50d902SRodney W. Grimes.Ar n 1389b50d902SRodney W. Grimesbits are the bits from the file, with the most significant bit being the most 1399b50d902SRodney W. Grimessignificant bit of the first octet of the file and the last bit being the least 1409b50d902SRodney W. Grimessignificant bit of the last octet, padded with zero bits (if necessary) to 1419b50d902SRodney W. Grimesachieve an integral number of octets, followed by one or more octets 1429b50d902SRodney W. Grimesrepresenting the length of the file as a binary value, least significant octet 1439b50d902SRodney W. Grimesfirst. 1449b50d902SRodney W. GrimesThe smallest number of octets capable of representing this integer are used. 1459b50d902SRodney W. Grimes.Pp 1469b50d902SRodney W. GrimesM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 1479b50d902SRodney W. GrimesG(x) using mod 2 division, producing a remainder R(x) of degree <= 31. 1489b50d902SRodney W. Grimes.Pp 1499b50d902SRodney W. GrimesThe coefficients of R(x) are considered to be a 32-bit sequence. 1509b50d902SRodney W. Grimes.Pp 1519b50d902SRodney W. GrimesThe bit sequence is complemented and the result is the CRC. 1529b50d902SRodney W. Grimes.Ed 153a866e170SRuslan Ermilov.Sh EXIT STATUS 154d628d776SRuslan Ermilov.Ex -std cksum sum 1559b50d902SRodney W. Grimes.Sh SEE ALSO 1562c0d39adSJohn-Mark Gurney.Xr md5 1 15798849115SRuslan Ermilov.Pp 1589b50d902SRodney W. GrimesThe default calculation is identical to that given in pseudo-code 1599b50d902SRodney W. Grimesin the following 1609b50d902SRodney W. Grimes.Tn ACM 1619b50d902SRodney W. Grimesarticle. 1629b50d902SRodney W. Grimes.Rs 1639b50d902SRodney W. Grimes.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 1649b50d902SRodney W. Grimes.%A Dilip V. Sarwate 1659b88faecSRuslan Ermilov.%J "Communications of the" Tn ACM 1669b50d902SRodney W. Grimes.%D "August 1988" 1679b50d902SRodney W. Grimes.Re 1689b50d902SRodney W. Grimes.Sh STANDARDS 1699b50d902SRodney W. GrimesThe 170f74fd6ecSPhilippe Charnier.Nm 171f8a42d82SPhilippe Charnierutility is expected to conform to 172f8a42d82SPhilippe Charnier.St -p1003.2-92 . 1739b50d902SRodney W. Grimes.Sh HISTORY 1749b50d902SRodney W. GrimesThe 175f74fd6ecSPhilippe Charnier.Nm 17693e0d62dSJohn-Mark Gurneyutility appeared in 1779b50d902SRodney W. Grimes.Bx 4.4 . 178