xref: /csrg-svn/usr.bin/cksum/cksum.1 (revision 50182)
149209Scael.\" Copyright (c) 1991, 1991 The Regents of the University of California.
247170Sbostic.\" All rights reserved.
347170Sbostic.\"
4*50182Sbostic.\" This code is derived from software contributed to Berkeley by
5*50182Sbostic.\" the Institute of Electrical and Electronics Engineers, Inc.
6*50182Sbostic.\"
749209Scael.\" %sccs.include.redist.roff%
847170Sbostic.\"
9*50182Sbostic.\"	@(#)cksum.1	5.5 (Berkeley) 06/27/91
1047170Sbostic.\"
1149209Scael.Dd
1249209Scael.Dt CKSUM 1
1349209Scael.Os
1449209Scael.Sh NAME
1549209Scael.Nm cksum
1649209Scael.Nd display file checksums and block counts
1749209Scael.Sh SYNOPSIS
1849209Scael.Nm cksum
1950101Sbostic.Op Fl o Op \&1 \&| \&2
2049209Scael.Op Ar file ...
2149209Scael.Sh DESCRIPTION
2247170SbosticThe
2349209Scael.Nm cksum
2447801Sbosticutility writes to standard output three whitespace separated fields for each
2547801Sbosticinput file (or the standard input by default).
2649209ScaelThese fields are a checksum
2749209Scael.Tn CRC ,
2849209Scaelthe total number of bytes in the file and
2947801Sbosticthe file name.
3049209Scael.Pp
3147801SbosticThe options are as follows:
3249209Scael.Bl -tag -width indent
3349209Scael.It Fl o
3447801SbosticUse historic algorithms instead of the (superior) default one.
3549209Scael.Pp
3649209ScaelAlgorithm 1 is the algorithm used by historic
3749209Scael.Bx
3849209Scaelsystems as the
3949209Scael.Xr sum 1
4049209Scaelalgorithm and by historic
4149209Scael.At V
4249209Scaelsystems as the
4349209Scael.Xr sum
4449209Scaelalgorithm when using the
4549209Scael.Fl r
4649209Scaeloption.
4747801SbosticThis is a 16-bit checksum, with a right rotation before each addition;
4847801Sbosticoverflow is discarded.
4949209Scael.Pp
5049209ScaelAlgorithm 2 is the algorithm used by historic
5149209Scael.At V
5249209Scaelsystems as the
5347801Sbosticdefault
5449209Scael.Xr sum
5547801Sbosticalgorithm.
5647801SbosticThis is a 32-bit checksum, and is defined as follows:
5749209Scael.Bd -unfilled -offset indent
5847801Sbostics = sum of all bytes;
5947801Sbosticr = s % 2^16 + (s % 2^32) / 2^16;
6047801Sbosticcksum = (r % 2^16) + r / 2^16;
6149209Scael.Ed
6249209Scael.Pp
6347801SbosticBoth algorithm 1 and 2 write to standard output the same fields as
6447801Sbosticthe default algorithm except that the size of the file in bytes is
6547801Sbosticreplaced with the size of the file in blocks.
6647801SbosticFor historic reasons, the block size is 1024 for algorithm 1 and 512
6747801Sbosticfor algorithm 2.
6847801SbosticPartial blocks are rounded up.
6949209Scael.El
7049209Scael.Pp
7149209ScaelThe default
7249209Scael.Tn CRC
7349209Scaelused is based on the polynomial used for
7449209Scael.Tn CRC
7549209Scaelerror checking
7649209Scaelin the networking standard
7749209Scael.St -iso8802-3
7849209ScaelThe
7949209Scael.Tn CRC
8049209Scaelchecksum encoding is defined by the generating polynomial:
8149209Scael.Pp
8249209Scael.Bd -unfilled -offset indent
8347801SbosticG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 +
8449209Scael     x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
8549209Scael.Ed
8649209Scael.Pp
8749209ScaelMathematically, the
8849209Scael.Tn CRC
8949209Scaelvalue corresponding to a given file is defined by
9047170Sbosticthe following procedure:
9149209Scael.Bd -filled -offset indent
9247170SbosticThe
9349209Scael.Ar n
9447170Sbosticbits of the file are considered to be the coefficients of a mod 2
9547170Sbosticpolynomial M(x) of degree
9649209Scael.Ar n Ns \-1 .
9749209Scael.Pp
9847170SbosticM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by
9947170SbosticG(x) using mod 2 division, producing a remainder R(x) of degree <= 31.
10047170SbosticDuring the division, each time the intermediate remainder is zero, it
10149209Scaelis changed to the next value from a predefined sequence of
10249209Scael32-bit integers before completing the division.
10347170SbosticThis sequence is long and complex -- see the source code for more
10447170Sbosticinformation.
10549209Scael.Pp
10647170SbosticThe coefficients of R(x) are considered to be a 32-bit sequence.
10749209Scael.Ed
10849209Scael.Pp
10947170SbosticThe calculation used is identical to that given in pseudo-code in
11049209Scaelthe
11149209Scael.Tn ACM
11249209Scaelarticle referenced below.
11349209Scael.Pp
11447170SbosticThe
11549209Scael.Nm cksum
11647170Sbosticutility exits 0 on success, and >0 if an error occurs.
11749209Scael.Sh SEE ALSO
11849209Scael.Rs
11949209Scael.%T "Computation of Cyclic Redundancy Checks Via Table Lookup"
12049209Scael.%A Dilip V. Sarwate
12149209Scael.%J "Communications of the \\*(tNACM\\*(sP"
12249209Scael.%D "August 1988"
12349209Scael.Re
12449209Scael.Sh STANDARDS
12549209Scael.Nm Cksum
12649209Scaelis expected to conform to
12749209Scael.St -p1003.2 .
12849209Scael.Sh HISTORY
12949209ScaelThe
13049209Scael.Nm cksum
13149209Scaelutility is
13249209Scael.Ud .
133