[BACK]Return to cksum.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / cksum

Annotation of src/usr.bin/cksum/cksum.1, Revision 1.12

1.12    ! aaron       1: .\"    $OpenBSD: cksum.1,v 1.11 2000/03/05 20:09:20 aaron Exp $
1.1       deraadt     2: .\"    $NetBSD: cksum.1,v 1.8 1995/09/02 05:45:15 jtc Exp $
                      3: .\"
                      4: .\" Copyright (c) 1991, 1993
                      5: .\"    The Regents of the University of California.  All rights reserved.
                      6: .\"
                      7: .\" This code is derived from software contributed to Berkeley by
                      8: .\" the Institute of Electrical and Electronics Engineers, Inc.
                      9: .\"
                     10: .\" Redistribution and use in source and binary forms, with or without
                     11: .\" modification, are permitted provided that the following conditions
                     12: .\" are met:
                     13: .\" 1. Redistributions of source code must retain the above copyright
                     14: .\"    notice, this list of conditions and the following disclaimer.
                     15: .\" 2. Redistributions in binary form must reproduce the above copyright
                     16: .\"    notice, this list of conditions and the following disclaimer in the
                     17: .\"    documentation and/or other materials provided with the distribution.
                     18: .\" 3. All advertising materials mentioning features or use of this software
                     19: .\"    must display the following acknowledgement:
                     20: .\"    This product includes software developed by the University of
                     21: .\"    California, Berkeley and its contributors.
                     22: .\" 4. Neither the name of the University nor the names of its contributors
                     23: .\"    may be used to endorse or promote products derived from this software
                     24: .\"    without specific prior written permission.
                     25: .\"
                     26: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29: .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36: .\" SUCH DAMAGE.
                     37: .\"
                     38: .\"    @(#)cksum.1     8.2 (Berkeley) 4/28/95
                     39: .\"
                     40: .Dd April 28, 1995
                     41: .Dt CKSUM 1
1.8       aaron      42: .Os
1.1       deraadt    43: .Sh NAME
1.9       aaron      44: .Nm cksum ,
                     45: .Nm sum
1.1       deraadt    46: .Nd display file checksums and block counts
                     47: .Sh SYNOPSIS
                     48: .Nm cksum
                     49: .Op Fl o Ar \&1 No \&| Ar \&2
                     50: .Op Ar file ...
                     51: .Nm sum
                     52: .Op Ar file ...
                     53: .Sh DESCRIPTION
                     54: The
1.11      aaron      55: .Nm cksum
1.1       deraadt    56: utility writes to the standard output three whitespace separated
                     57: fields for each input file.
                     58: These fields are a checksum
                     59: .Tn CRC ,
                     60: the total number of octets in the file and the file name.
                     61: If no file name is specified, the standard input is used and no file name
                     62: is written.
                     63: .Pp
                     64: The
                     65: .Nm sum
                     66: utility is identical to the
1.11      aaron      67: .Nm cksum
1.1       deraadt    68: utility, except that it defaults to using historic algorithm 1, as
                     69: described below.
                     70: It is provided for compatibility only.
                     71: .Pp
                     72: The options are as follows:
1.12    ! aaron      73: .Bl -tag -width Ds
1.10      deraadt    74: .It Fl o Ar \&1 No \&| Ar \&2
1.1       deraadt    75: Use historic algorithms instead of the (superior) default one.
                     76: .Pp
                     77: Algorithm 1 is the algorithm used by historic
                     78: .Bx
1.8       aaron      79: systems as the
1.1       deraadt    80: .Xr sum 1
                     81: algorithm and by historic
                     82: .At V
                     83: systems as the
                     84: .Xr sum
                     85: algorithm when using the
                     86: .Fl r
                     87: option.
                     88: This is a 16-bit checksum, with a right rotation before each addition;
                     89: overflow is discarded.
                     90: .Pp
                     91: Algorithm 2 is the algorithm used by historic
                     92: .At V
                     93: systems as the
                     94: default
                     95: .Xr sum
                     96: algorithm.
                     97: This is a 32-bit checksum, and is defined as follows:
                     98: .Bd -unfilled -offset indent
                     99: s = sum of all bytes;
                    100: r = s % 2^16 + (s % 2^32) / 2^16;
                    101: cksum = (r % 2^16) + r / 2^16;
                    102: .Ed
                    103: .Pp
                    104: Both algorithm 1 and 2 write to the standard output the same fields as
                    105: the default algorithm except that the size of the file in bytes is
                    106: replaced with the size of the file in blocks.
                    107: For historic reasons, the block size is 1024 for algorithm 1 and 512
                    108: for algorithm 2.
                    109: Partial blocks are rounded up.
                    110: .El
                    111: .Pp
                    112: The default
                    113: .Tn CRC
                    114: used is based on the polynomial used for
                    115: .Tn CRC
                    116: error checking
                    117: in the networking standard
                    118: .St -iso8802-3
                    119: The
                    120: .Tn CRC
                    121: checksum encoding is defined by the generating polynomial:
                    122: .Pp
                    123: .Bd -unfilled -offset indent
                    124: G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 +
                    125:      x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
                    126: .Ed
                    127: .Pp
                    128: Mathematically, the
                    129: .Tn CRC
                    130: value corresponding to a given file is defined by
                    131: the following procedure:
                    132: .Bd -filled -offset indent
                    133: The
                    134: .Ar n
                    135: bits to be evaluated are considered to be the coefficients of a mod 2
                    136: polynomial M(x) of degree
                    137: .Ar n Ns \-1 .
                    138: These
                    139: .Ar n
                    140: bits are the bits from the file, with the most significant bit being the most
                    141: significant bit of the first octet of the file and the last bit being the least
                    142: significant bit of the last octet, padded with zero bits (if necessary) to
                    143: achieve an integral number of octets, followed by one or more octets
                    144: representing the length of the file as a binary value, least significant octet
                    145: first.
                    146: The smallest number of octets capable of representing this integer are used.
                    147: .Pp
                    148: M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by
                    149: G(x) using mod 2 division, producing a remainder R(x) of degree <= 31.
                    150: .Pp
                    151: The coefficients of R(x) are considered to be a 32-bit sequence.
                    152: .Pp
                    153: The bit sequence is complemented and the result is the CRC.
                    154: .Ed
                    155: .Pp
                    156: The
1.11      aaron     157: .Nm cksum
1.1       deraadt   158: and
                    159: .Nm sum
1.7       aaron     160: utilities exit 0 on success or >0 if an error occurred.
1.3       bitblt    161: .Sh WARNING
                    162: Do not use
1.11      aaron     163: .Nm cksum
                    164: or
1.8       aaron     165: .Nm sum
1.11      aaron     166: to detect hostile binary modifications.
                    167: An attacker can trivially produce backdoored daemons which have the same
                    168: CRC as the standard versions.
                    169: Use a cryptographic checksum (such as MD5) instead.
1.1       deraadt   170: .Sh SEE ALSO
1.6       deraadt   171: .Xr md5 1 ,
                    172: .Xr rmd160 1 ,
                    173: .Xr sha1 1
1.5       deraadt   174: .Pp
1.1       deraadt   175: The default calculation is identical to that given in pseudo-code
                    176: in the following
                    177: .Tn ACM
                    178: article.
                    179: .Rs
                    180: .%T "Computation of Cyclic Redundancy Checks Via Table Lookup"
                    181: .%A Dilip V. Sarwate
                    182: .%J "Communications of the \\*(tNACM\\*(sP"
                    183: .%D "August 1988"
                    184: .Re
                    185: .Sh STANDARDS
                    186: The
1.11      aaron     187: .Nm cksum
1.4       denny     188: utility is compliant with the
                    189: .St -p1003.2-92
                    190: specification.
1.1       deraadt   191: .Sh HISTORY
                    192: The
1.11      aaron     193: .Nm cksum
1.1       deraadt   194: utility appeared in
                    195: .Bx 4.4 .