1crc32(n)                   Cyclic Redundancy Checks                   crc32(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       crc32 - Perform a 32bit Cyclic Redundancy Check
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require crc32  ?1.3.3?
14
15       ::crc::crc32 ?-format format? ?-seed value? [ -channel chan | -filename
16       file | message ]
17
18       ::crc::Crc32Init ?seed?
19
20       ::crc::Crc32Update token data
21
22       ::crc::Crc32Final token
23
24______________________________________________________________________________
25

DESCRIPTION

27       This package provides a Tcl  implementation  of  the  CRC-32  algorithm
28       based   upon   information   provided   at  http://www.naaccr.org/stan
29       dard/crc32/document.html If either the critcl package or the Trf  pack‐
30       age are available then a compiled version may be used internally to ac‐
31       celerate the checksum calculation.
32

COMMANDS

34       ::crc::crc32 ?-format format? ?-seed value? [ -channel chan | -filename
35       file | message ]
36              The  command  takes either string data or a channel or file name
37              and returns a checksum value calculated using the  CRC-32  algo‐
38              rithm.  The  result  is  formatted using the format(n) specifier
39              provided. The default is to return the value as an unsigned  in‐
40              teger (format %u).
41

OPTIONS

43       -channel name
44              Return  a checksum for the data read from a channel. The command
45              will read data from the channel until the eof is  true.  If  you
46              need  to  be  able to process events during this calculation see
47              the PROGRAMMING INTERFACE section
48
49       -filename name
50              This is a convenience option that opens the specified file, sets
51              the  encoding  to binary and then acts as if the -channel option
52              had been used. The file is closed on completion.
53
54       -format string
55              Return the checksum using an alternative format template.
56
57       -seed value
58              Select an alternative seed value for the  CRC  calculation.  The
59              default  is  0xffffffff.  This can be useful for calculating the
60              CRC for data  structures  without  first  converting  the  whole
61              structure  into  a string. The CRC of the previous member can be
62              used as the seed for calculating the CRC  of  the  next  member.
63              Note  that the crc32 algorithm includes a final XOR step. If in‐
64              cremental processing is desired then this must be undone  before
65              using  the  output of the algorithm as the seed for further pro‐
66              cessing. A simpler alternative is to use the PROGRAMMING  INTER‐
67              FACE which is intended for this mode of operation.
68

PROGRAMMING INTERFACE

70       The  CRC-32 package implements the checksum using a context variable to
71       which additional data can be added at any time. This is expecially use‐
72       ful  in  an  event  based environment such as a Tk application or a web
73       server package. Data to be checksummed  may  be  handled  incrementally
74       during a fileevent handler in discrete chunks. This can improve the in‐
75       teractive nature of a GUI application and can help to  avoid  excessive
76       memory consumption.
77
78       ::crc::Crc32Init ?seed?
79              Begins a new CRC32 context. Returns a token ID that must be used
80              for the remaining functions. An optional seed may  be  specified
81              if required.
82
83       ::crc::Crc32Update token data
84              Add  data  to the checksum identified by token. Calling Crc32Up‐
85              date $token "abcd" is equivalent to calling  Crc32Update  $token
86              "ab" followed by Crc32Update $token "cb". See EXAMPLES.
87
88       ::crc::Crc32Final token
89              Returns  the  checksum  value and releases any resources held by
90              this token. Once this command completes the token  will  be  in‐
91              valid. The result is a 32 bit integer value.
92

EXAMPLES

94              % crc::crc32 "Hello, World!"
95              3964322768
96
97
98              % crc::crc32 -format 0x%X "Hello, World!"
99              0xEC4AC3D0
100
101
102              % crc::crc32 -file crc32.tcl
103              483919716
104
105
106              % set tok [crc::Crc32Init]
107              % crc::Crc32Update $tok "Hello, "
108              % crc::Crc32Update $tok "World!"
109              % crc::Crc32Final $tok
110              3964322768
111
112

AUTHORS

114       Pat Thoyts
115

BUGS, IDEAS, FEEDBACK

117       This  document,  and the package it describes, will undoubtedly contain
118       bugs and other problems.  Please report such in the category crc of the
119       Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please also
120       report any ideas for enhancements  you  may  have  for  either  package
121       and/or documentation.
122
123       When proposing code changes, please provide unified diffs, i.e the out‐
124       put of diff -u.
125
126       Note further that  attachments  are  strongly  preferred  over  inlined
127       patches.  Attachments  can  be  made  by  going to the Edit form of the
128       ticket immediately after its creation, and  then  using  the  left-most
129       button in the secondary navigation bar.
130

SEE ALSO

132       cksum(n), crc16(n), sum(n)
133

KEYWORDS

135       checksum,  cksum,  crc, crc32, cyclic redundancy check, data integrity,
136       security
137

CATEGORY

139       Hashes, checksums, and encryption
140
142       Copyright (c) 2002, Pat Thoyts
143
144
145
146
147tcllib                               1.3.3                            crc32(n)
Impressum