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 36f8a42d82SPhilippe Charnier.\" $Id: cksum.1,v 1.3 1997/04/29 08:41:26 jmg Exp $ 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 429b50d902SRodney W. Grimes.Nm cksum 439b50d902SRodney W. Grimes.Nd display file checksums and block counts 449b50d902SRodney W. Grimes.Sh SYNOPSIS 45f8a42d82SPhilippe Charnier.Nm cksum 46f8a42d82SPhilippe Charnier.Op Fl o Ar \&1 No \&| Ar \&2 479b50d902SRodney W. Grimes.Op Ar file ... 489b50d902SRodney W. Grimes.Sh DESCRIPTION 499b50d902SRodney W. GrimesThe 50f8a42d82SPhilippe Charnier.Nm cksum 519b50d902SRodney W. Grimesutility writes to the standard output three whitespace separated 529b50d902SRodney W. Grimesfields for each input file. 539b50d902SRodney W. GrimesThese fields are a checksum 549b50d902SRodney W. Grimes.Tn CRC , 559b50d902SRodney W. Grimesthe total number of octets in the file and the file name. 569b50d902SRodney W. GrimesIf no file name is specified, the standard input is used and no file name 579b50d902SRodney W. Grimesis written. 589b50d902SRodney W. Grimes.Pp 599b50d902SRodney W. GrimesThe options are as follows: 609b50d902SRodney W. Grimes.Bl -tag -width indent 619b50d902SRodney W. Grimes.It Fl o 629b50d902SRodney W. GrimesUse historic algorithms instead of the (superior) default one. 639b50d902SRodney W. Grimes.Pp 649b50d902SRodney W. GrimesAlgorithm 1 is the algorithm used by historic 659b50d902SRodney W. Grimes.Bx 669b50d902SRodney W. Grimessystems as the 679b50d902SRodney W. Grimes.Xr sum 1 689b50d902SRodney W. Grimesalgorithm and by historic 699b50d902SRodney W. Grimes.At V 709b50d902SRodney W. Grimessystems as the 719b50d902SRodney W. Grimes.Xr sum 729b50d902SRodney W. Grimesalgorithm when using the 739b50d902SRodney W. Grimes.Fl r 749b50d902SRodney W. Grimesoption. 759b50d902SRodney W. GrimesThis is a 16-bit checksum, with a right rotation before each addition; 769b50d902SRodney W. Grimesoverflow is discarded. 779b50d902SRodney W. Grimes.Pp 789b50d902SRodney W. GrimesAlgorithm 2 is the algorithm used by historic 799b50d902SRodney W. Grimes.At V 809b50d902SRodney W. Grimessystems as the 819b50d902SRodney W. Grimesdefault 829b50d902SRodney W. Grimes.Xr sum 839b50d902SRodney W. Grimesalgorithm. 849b50d902SRodney W. GrimesThis is a 32-bit checksum, and is defined as follows: 859b50d902SRodney W. Grimes.Bd -unfilled -offset indent 869b50d902SRodney W. Grimess = sum of all bytes; 879b50d902SRodney W. Grimesr = s % 2^16 + (s % 2^32) / 2^16; 889b50d902SRodney W. Grimescksum = (r % 2^16) + r / 2^16; 899b50d902SRodney W. Grimes.Ed 909b50d902SRodney W. Grimes.Pp 919b50d902SRodney W. GrimesBoth algorithm 1 and 2 write to the standard output the same fields as 929b50d902SRodney W. Grimesthe default algorithm except that the size of the file in bytes is 939b50d902SRodney W. Grimesreplaced with the size of the file in blocks. 949b50d902SRodney W. GrimesFor historic reasons, the block size is 1024 for algorithm 1 and 512 959b50d902SRodney W. Grimesfor algorithm 2. 969b50d902SRodney W. GrimesPartial blocks are rounded up. 979b50d902SRodney W. Grimes.El 989b50d902SRodney W. Grimes.Pp 999b50d902SRodney W. GrimesThe default 1009b50d902SRodney W. Grimes.Tn CRC 1019b50d902SRodney W. Grimesused is based on the polynomial used for 1029b50d902SRodney W. Grimes.Tn CRC 1039b50d902SRodney W. Grimeserror checking 1049b50d902SRodney W. Grimesin the networking standard 1059b50d902SRodney W. Grimes.St -iso8802-3 1069b50d902SRodney W. GrimesThe 1079b50d902SRodney W. Grimes.Tn CRC 1089b50d902SRodney W. Grimeschecksum encoding is defined by the generating polynomial: 1099b50d902SRodney W. Grimes.Pp 1109b50d902SRodney W. Grimes.Bd -unfilled -offset indent 1119b50d902SRodney W. GrimesG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 1129b50d902SRodney W. Grimes x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 1139b50d902SRodney W. Grimes.Ed 1149b50d902SRodney W. Grimes.Pp 1159b50d902SRodney W. GrimesMathematically, the 1169b50d902SRodney W. Grimes.Tn CRC 1179b50d902SRodney W. Grimesvalue corresponding to a given file is defined by 1189b50d902SRodney W. Grimesthe following procedure: 1199b50d902SRodney W. Grimes.Bd -filled -offset indent 1209b50d902SRodney W. GrimesThe 1219b50d902SRodney W. Grimes.Ar n 1229b50d902SRodney W. Grimesbits to be evaluated are considered to be the coefficients of a mod 2 1239b50d902SRodney W. Grimespolynomial M(x) of degree 1249b50d902SRodney W. Grimes.Ar n Ns \-1 . 1259b50d902SRodney W. GrimesThese 1269b50d902SRodney W. Grimes.Ar n 1279b50d902SRodney W. Grimesbits are the bits from the file, with the most significant bit being the most 1289b50d902SRodney W. Grimessignificant bit of the first octet of the file and the last bit being the least 1299b50d902SRodney W. Grimessignificant bit of the last octet, padded with zero bits (if necessary) to 1309b50d902SRodney W. Grimesachieve an integral number of octets, followed by one or more octets 1319b50d902SRodney W. Grimesrepresenting the length of the file as a binary value, least significant octet 1329b50d902SRodney W. Grimesfirst. 1339b50d902SRodney W. GrimesThe smallest number of octets capable of representing this integer are used. 1349b50d902SRodney W. Grimes.Pp 1359b50d902SRodney W. GrimesM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 1369b50d902SRodney W. GrimesG(x) using mod 2 division, producing a remainder R(x) of degree <= 31. 1379b50d902SRodney W. Grimes.Pp 1389b50d902SRodney W. GrimesThe coefficients of R(x) are considered to be a 32-bit sequence. 1399b50d902SRodney W. Grimes.Pp 1409b50d902SRodney W. GrimesThe bit sequence is complemented and the result is the CRC. 1419b50d902SRodney W. Grimes.Ed 1429b50d902SRodney W. Grimes.Pp 1439b50d902SRodney W. GrimesThe 14493e0d62dSJohn-Mark Gurney.Nm 1459b50d902SRodney W. Grimesutility exits 0 on success, and >0 if an error occurs. 1469b50d902SRodney W. Grimes.Sh SEE ALSO 1472c0d39adSJohn-Mark Gurney.Xr md5 1 1482c0d39adSJohn-Mark Gurney.Rs 1499b50d902SRodney W. GrimesThe default calculation is identical to that given in pseudo-code 1509b50d902SRodney W. Grimesin the following 1519b50d902SRodney W. Grimes.Tn ACM 1529b50d902SRodney W. Grimesarticle. 1539b50d902SRodney W. Grimes.Rs 1549b50d902SRodney W. Grimes.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 1559b50d902SRodney W. Grimes.%A Dilip V. Sarwate 1569b50d902SRodney W. Grimes.%J "Communications of the \\*(tNACM\\*(sP" 1579b50d902SRodney W. Grimes.%D "August 1988" 1589b50d902SRodney W. Grimes.Re 1599b50d902SRodney W. Grimes.Sh STANDARDS 1609b50d902SRodney W. GrimesThe 161f8a42d82SPhilippe Charnier.Nm cksum 162f8a42d82SPhilippe Charnierutility is expected to conform to 163f8a42d82SPhilippe Charnier.St -p1003.2-92 . 1649b50d902SRodney W. Grimes.Sh HISTORY 1659b50d902SRodney W. GrimesThe 166f8a42d82SPhilippe Charnier.Nm cksum 16793e0d62dSJohn-Mark Gurneyutility appeared in 1689b50d902SRodney W. Grimes.Bx 4.4 . 169