1.\" $OpenBSD: cksum.1,v 1.38 2014/03/20 22:06:21 tedu Exp $ 2.\" 3.\" Copyright (c) 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the Institute of Electrical and Electronics Engineers, Inc. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 34.\" 35.Dd $Mdocdate: March 20 2014 $ 36.Dt CKSUM 1 37.Os 38.Sh NAME 39.Nm cksum 40.Nd display file checksums and block counts 41.Sh SYNOPSIS 42.Nm cksum 43.Bk -words 44.Op Fl bcpqrtx 45.Op Fl a Ar algorithms 46.Op Fl C Ar checklist 47.Op Fl h Ar hashfile 48.Op Fl s Ar string 49.Op Ar 50.Ek 51.Sh DESCRIPTION 52The 53.Nm cksum 54utility writes to the standard output a single line for each input file. 55The format of this line varies with the algorithm being used as follows: 56.Bl -tag -width allxothers 57.It cksum 58The output line consists of three whitespace separated fields: 59a CRC checksum, the number of octets in the input, 60and name of the file or string. 61If no file name is specified, the standard input is used and no file name 62is written. 63.It all others 64The output line consists of four whitespace separated fields: 65the name of the algorithm used, the name of the file or string in 66parentheses, an equals sign, and the cryptographic hash of the input. 67If no file name is specified, the standard input is used and only 68the cryptographic hash is output. 69.El 70.Pp 71The options are as follows: 72.Bl -tag -width Ds 73.It Fl a Ar algorithms 74Use the specified algorithm(s) instead of the default (cksum). 75Supported algorithms include cksum, md5, rmd160, sha1, 76sha224, sha256, sha384, and sha512. 77Multiple algorithms may be specified, separated by a comma or whitespace. 78Additionally, multiple 79.Fl a 80options may be specified on the command line. 81Case is ignored when matching algorithms. 82The output format may be specified on a per-algorithm basis 83by using a single-character suffix, e.g.\& 84.Dq sha256b . 85If the algorithm has a 86.Sq b 87suffix, the checksum will be output in base64 format. 88If the algorithm has an 89.Sq x 90suffix, the checksum will be output in hex format. 91If an algorithm with the same output format is repeated, 92only the first instance is used. 93Note that output format suffixes are not supported 94for the cksum algorithm. 95.It Fl b 96Output checksums in base64 notation, not hexadecimal by 97default. 98A 99.Sq b 100or 101.Sq x 102suffix on the algorithm will override this default. 103This option is ignored for the cksum algorithm. 104.It Fl C Ar checklist 105Compare the checksum of each 106.Ar file 107against the checksums in the 108.Ar checklist . 109Any specified 110.Ar file 111that is not listed in the 112.Ar checklist 113will generate an error. 114.It Fl c 115If this option is specified, the 116.Ar file 117options become checklists. 118Each checklist should contain hash results in the normal format, 119which will be verified against the specified paths. 120Output consists of the digest used, the file name, 121and an OK, FAILED, or MISSING for the result of the comparison. 122This will validate any of the supported checksums. 123If no file is given, stdin is used. 124The 125.Fl c 126option may not be used in conjunction with more than a single 127.Fl a 128option. 129.It Fl h Ar hashfile 130Place the checksum into 131.Ar hashfile 132instead of stdout. 133.It Fl p 134Echoes stdin to stdout and appends the 135checksum to stdout. 136.It Fl q 137Only print the checksum (quiet mode) or if used in conjunction with the 138.Fl c 139flag, only print the failed cases. 140.It Fl r 141Reverse the format of the hash algorithm output, making 142it match the checksum output format. 143.It Fl s Ar string 144Prints a checksum of the given 145.Ar string . 146.It Fl t 147Runs a built-in time trial. 148Specifying 149.Fl t 150multiple times results in the number of rounds being multiplied 151by 10 for each additional flag. 152.It Fl x 153Runs a built-in test script. 154.El 155.Pp 156The default CRC used is based on the polynomial used for CRC error checking 157in the networking standard 158ISO/IEC 8802-3:1996. 159The other available algorithms are described in their respective 160man pages in section 3 of the manual. 161.Sh EXIT STATUS 162.Ex -std cksum 163.Sh SEE ALSO 164.Xr md5 1 165.Pp 166The default calculation is identical to that given in pseudo-code 167in the following ACM article: 168.Rs 169.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 170.%A Dilip V. Sarwate 171.%J "Communications of the ACM" 172.%D "August 1988" 173.Re 174.Sh STANDARDS 175The 176.Nm 177utility is compliant with the 178.St -p1003.1-2008 179specification. 180.Pp 181All the flags are extensions to that specification. 182.Sh HISTORY 183The 184.Nm cksum 185utility appeared in 186.Bx 4.4 . 187.Sh CAVEATS 188Do not use the cksum or md5 algorithms to verify file integrity. 189An attacker can trivially produce modified payload that 190has the same checksum as the original version. 191Use a cryptographic checksum instead. 192