chiark / gitweb /
@@@ much mess, mostly manpages
[mLib] / hash / crc32.3.in
1 .\" -*-nroff-*-
2 .\"
3 .\" Manual for CRC23 calculator
4 .\"
5 .\" (c) 1999--2001, 2003, 2005, 2009, 2024 Straylight/Edgeware
6 .\"
7 .
8 .\"----- Licensing notice ---------------------------------------------------
9 .\"
10 .\" This file is part of the mLib utilities library.
11 .\"
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
16 .\"
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
20 .\" License for more details.
21 .\"
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib.  If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 .\" USA.
26 .
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
29 .
30 .\"--------------------------------------------------------------------------
31 .TH crc32 3mLib "8 May 1999" "Straylight/Edgeware" "mLib utilities library"
32 .\" @crc32
33 .
34 .\"--------------------------------------------------------------------------
35 .SH NAME
36 crc32 \- calculate 32-bit CRC
37 .
38 .\"--------------------------------------------------------------------------
39 .SH SYNOPSIS
40 .
41 .nf
42 .B "#include <mLib/crc32.h>"
43 .PP
44 .BI "uint32 crc32(uint32 " crc ", const void *" buf ", size_t " sz );
45 .BI CRC32( result ", " crc ", " buf ", " sz )
46 .fi
47 .
48 .\"--------------------------------------------------------------------------
49 .SH DESCRIPTION
50 .
51 The
52 .B crc32
53 function calculates a 32-bit cyclic redundancy check of the data block
54 at address
55 .I buf
56 and size
57 .I sz
58 passed to it.
59 .PP
60 The function is restartable.  For a first call, pass zero as the value
61 of the
62 .I crc
63 argument; for subsequent blocks, pass in the previous output.  The final
64 answer is equal to the result you'd get from computing a CRC over the
65 concatenation of the individual blocks.
66 .PP
67 The
68 .B CRC32
69 macro calculates a CRC inline.  The calculated CRC value is placed in
70 the variable named by
71 .IR result .
72 Only use the macro version when efficiency is a major concern: it makes
73 the code rather harder to read.
74 .PP
75 Note that a CRC is not cryptographically strong: it's fairly easy for an
76 adversary to construct blocks of data with any desired CRC, or to modify
77 a given block in a way which doesn't change its (unknown) CRC.
78 .PP
79 The exact behaviour of the CRC is beyond the scope of this manual;
80 suffice to say that the result is, in some suitable representation, the
81 remainder after division by a degree-32 polynomial in GF(2)[x].
82 .
83 .\"--------------------------------------------------------------------------
84 .SH "RETURN VALUE"
85 The return value is the 32-bit CRC of the input block.
86 .
87 .\"--------------------------------------------------------------------------
88 .SH "SEE ALSO"
89 .
90 .BR unihash (3),
91 .BR mLib (3).
92 .
93 .\"--------------------------------------------------------------------------
94 .SH AUTHOR
95 .
96 Mark Wooding, <mdw@distorted.org.uk>
97 .
98 .\"----- That's all, folks --------------------------------------------------