1 |
%$Header: /uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions/c_cch0.tex 3 12/31/00 7:42p Dashley1 $ |
%$Header$ |
2 |
|
|
3 |
\chapter[\ccchzeroshorttitle{}]{\ccchzerolongtitle{}} |
\chapter[\ccchzeroshorttitle{}]{\ccchzerolongtitle{}} |
4 |
|
|
5 |
\label{ccch0} |
\label{ccch0} |
6 |
|
|
7 |
\beginchapterquote{``\ldots{} Beauty is the first test: there is no permanent |
\beginchapterquote{``\ldots{} Beauty is the first test: there is no permanent |
8 |
place in the world for ugly mathematics.''} |
place in the world for ugly mathematics.''} |
9 |
{G.H. Hardy \cite{bibref:b:mathematiciansapology:1940}, |
{G.H. Hardy \cite{bibref:b:mathematiciansapology:1940}, |
10 |
p.85} |
p.85} |
11 |
|
|
12 |
\section{Introduction} |
\section{Introduction} |
13 |
%Section Tag: INT |
%Section Tag: INT |
14 |
|
|
15 |
|
|
16 |
\section{crc32} |
\section{crc32} |
17 |
|
|
18 |
\begin{tclcommandname}{crc32}% |
\begin{tclcommandname}{crc32}% |
19 |
generates the CRC-32 of a file or string. This CRC can be reliably used to obtain |
generates the CRC-32 of a file or string. This CRC can be reliably used to obtain |
20 |
digital signatures of files or data. |
digital signatures of files or data. |
21 |
\end{tclcommandname} |
\end{tclcommandname} |
22 |
|
|
23 |
\begin{tclcommandsynopsis} |
\begin{tclcommandsynopsis} |
24 |
\tclcommandsynopsisline{crc32}{filename} |
\tclcommandsynopsisline{crc32}{filename} |
25 |
\tclcommandsynopsisline{crc32}{-string binarystringval} |
\tclcommandsynopsisline{crc32}{-string binarystringval} |
26 |
\tclcommandsynopsisline{crc32}{-initialstate} |
\tclcommandsynopsisline{crc32}{-initialstate} |
27 |
\tclcommandsynopsisline{crc32}{-advancestate state filename} |
\tclcommandsynopsisline{crc32}{-advancestate state filename} |
28 |
\tclcommandsynopsisline{crc32}{-advancestate -string state binarystringval} |
\tclcommandsynopsisline{crc32}{-advancestate -string state binarystringval} |
29 |
\tclcommandsynopsisline{crc32}{-crcfromstate state} |
\tclcommandsynopsisline{crc32}{-crcfromstate state} |
30 |
\end{tclcommandsynopsis} |
\end{tclcommandsynopsis} |
31 |
|
|
32 |
\begin{tclcommanddescription} |
\begin{tclcommanddescription} |
33 |
The \emph{crc32} command forms the CRC-32 of the binary contents of a file |
The \emph{crc32} command forms the CRC-32 of the binary contents of a file |
34 |
or of the binary contents of a string. The CRC-32 is useful as a digital |
or of the binary contents of a string. The CRC-32 is useful as a digital |
35 |
signature, and can be used with unity probability to determine that two |
signature, and can be used with unity probability to determine that two |
36 |
files are different, or with a probability of about $1-2^{-32}$ to determine |
files are different, or with a probability of about $1-2^{-32}$ to determine |
37 |
that two files are almost certainly identical. |
that two files are almost certainly identical. |
38 |
|
|
39 |
In the invocations below, the CRC-32 is always returned as a 10-character ASCII string |
In the invocations below, the CRC-32 is always returned as a 10-character ASCII string |
40 |
of the form \emph{``0xDDDDDDDD''}, where \emph{``DDDDDDDD''} is the hexadecimal representation |
of the form \emph{``0xDDDDDDDD''}, where \emph{``DDDDDDDD''} is the hexadecimal representation |
41 |
of the 32-bit CRC-32, and \emph{``0x''} is a constant 2-character prefix which is included for |
of the 32-bit CRC-32, and \emph{``0x''} is a constant 2-character prefix which is included for |
42 |
aesthetics. It is guaranteed that: |
aesthetics. It is guaranteed that: |
43 |
|
|
44 |
\begin{itemize} |
\begin{itemize} |
45 |
\item The string returned will be exclusive ASCII. |
\item The string returned will be exclusive ASCII. |
46 |
\item The string will have a length of exactly 10 characters. |
\item The string will have a length of exactly 10 characters. |
47 |
\item The first two characters of the string will be \emph{``0x''}. |
\item The first two characters of the string will be \emph{``0x''}. |
48 |
\item Any letters in the hexadecimal representation will be upper-case. |
\item Any letters in the hexadecimal representation will be upper-case. |
49 |
\end{itemize} |
\end{itemize} |
50 |
|
|
51 |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{filename}} |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{filename}} |
52 |
Returns the CRC-32 of \emph{filename}, treated as an ordered collection of bytes (i.e. |
Returns the CRC-32 of \emph{filename}, treated as an ordered collection of bytes (i.e. |
53 |
newline characters and file termination characters are not treated---the file is |
newline characters and file termination characters are not treated---the file is |
54 |
treated as a binary file). \emph{filename} must be specified in the form accepted by |
treated as a binary file). \emph{filename} must be specified in the form accepted by |
55 |
the Tcl internals (forward slashes only). |
the Tcl internals (forward slashes only). |
56 |
\end{tclcommandinternaldescription} |
\end{tclcommandinternaldescription} |
57 |
|
|
58 |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-string binarystringval}} |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-string binarystringval}} |
59 |
Returns the CRC-32 of \emph{binarystringval}, treated as an ordered collection of bytes (i.e. |
Returns the CRC-32 of \emph{binarystringval}, treated as an ordered collection of bytes (i.e. |
60 |
newline characters and string termination characters are not honored---the string is |
newline characters and string termination characters are not honored---the string is |
61 |
treated as a binary string).\footnote{For an ASCII string, the \emph{crc32} extension will |
treated as a binary string).\footnote{For an ASCII string, the \emph{crc32} extension will |
62 |
behave as expected, and will process all characters up to but not including the zero |
behave as expected, and will process all characters up to but not including the zero |
63 |
terminator. However, the \emph{crc32} extension will also correctly process non-ASCII strings.} |
terminator. However, the \emph{crc32} extension will also correctly process non-ASCII strings.} |
64 |
\end{tclcommandinternaldescription} |
\end{tclcommandinternaldescription} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-initialstate}% |
\begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-initialstate}% |
71 |
\tclcommanddescsynopsisline{crc32}{-advancestate state filename}% |
\tclcommanddescsynopsisline{crc32}{-advancestate state filename}% |
72 |
\tclcommanddescsynopsisline{crc32}{-advancestate -string state filename}% |
\tclcommanddescsynopsisline{crc32}{-advancestate -string state filename}% |
73 |
\tclcommanddescsynopsisline{crc32}{-crcfromstate state}% |
\tclcommanddescsynopsisline{crc32}{-crcfromstate state}% |
74 |
} |
} |
75 |
The four forms above are designed to allow ``running CRCs'' to be calculated; in which |
The four forms above are designed to allow ``running CRCs'' to be calculated; in which |
76 |
the CRC is calculated piecemeal. These forms allow the caller to retain the internal |
the CRC is calculated piecemeal. These forms allow the caller to retain the internal |
77 |
state vector of the CRC calculation algorithm. |
state vector of the CRC calculation algorithm. |
78 |
|
|
79 |
The first form, \emph{crc32 -initialstate}, returns an ASCII representation of the |
The first form, \emph{crc32 -initialstate}, returns an ASCII representation of the |
80 |
correct initial state vector of the CRC-32 state machine. The client is required |
correct initial state vector of the CRC-32 state machine. The client is required |
81 |
to obtain this initial state before beginning a piecemeal CRC calculation. Although the |
to obtain this initial state before beginning a piecemeal CRC calculation. Although the |
82 |
returned string is a constant (it will always be the same), representational details |
returned string is a constant (it will always be the same), representational details |
83 |
may change in future versions of the \emph{crc32} extension, and so a caller should never |
may change in future versions of the \emph{crc32} extension, and so a caller should never |
84 |
make assumptions about what this invocation will return, as these assumptions may |
make assumptions about what this invocation will return, as these assumptions may |
85 |
render a script incompatible with future versions of \emph{crc32}. |
render a script incompatible with future versions of \emph{crc32}. |
86 |
|
|
87 |
The second and third forms, \emph{crc32 -advancestate state filename} |
The second and third forms, \emph{crc32 -advancestate state filename} |
88 |
and \emph{crc32 -advancestate -string state filename}, apply a file or a binary string |
and \emph{crc32 -advancestate -string state filename}, apply a file or a binary string |
89 |
to \emph{state} to produce a new \emph{state}, which is returned. This new \emph{state} |
to \emph{state} to produce a new \emph{state}, which is returned. This new \emph{state} |
90 |
must be retained by the caller and used in subsequent calls. |
must be retained by the caller and used in subsequent calls. |
91 |
|
|
92 |
The final form, \emph{crc32 -crcfromstate state}, maps from the state vector to the |
The final form, \emph{crc32 -crcfromstate state}, maps from the state vector to the |
93 |
calculated CRC, and will return a 10-character ASCII string as described above. |
calculated CRC, and will return a 10-character ASCII string as described above. |
94 |
\end{tclcommandinternaldescription} |
\end{tclcommandinternaldescription} |
95 |
|
|
96 |
\end{tclcommanddescription} |
\end{tclcommanddescription} |
97 |
|
|
98 |
|
|
99 |
\begin{tclcommandusagenotes} |
\begin{tclcommandusagenotes} |
100 |
The ``piecemeal'' forms are as efficient as the file and string forms---there is no difference |
The ``piecemeal'' forms are as efficient as the file and string forms---there is no difference |
101 |
in the internal algorithms. The primary cost of the piecemeal forms is in importing and |
in the internal algorithms. The primary cost of the piecemeal forms is in importing and |
102 |
exporting the algorithm state vector to/from an ASCII string. |
exporting the algorithm state vector to/from an ASCII string. |
103 |
Thus, the piecemeal forms become less efficient when |
Thus, the piecemeal forms become less efficient when |
104 |
small files or strings are processed, as there are more exports and imports |
small files or strings are processed, as there are more exports and imports |
105 |
of the state vector. When using the piecemeal forms, processing the data in |
of the state vector. When using the piecemeal forms, processing the data in |
106 |
larger chunks will give better performance. |
larger chunks will give better performance. |
107 |
\end{tclcommandusagenotes} |
\end{tclcommandusagenotes} |
108 |
|
|
109 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
110 |
\noindent\begin{figure}[!b] |
\noindent\begin{figure}[!b] |
111 |
\noindent\rule[-0.25in]{\textwidth}{1pt} |
\noindent\rule[-0.25in]{\textwidth}{1pt} |
112 |
\begin{tiny} |
\begin{tiny} |
113 |
\begin{verbatim} |
\begin{verbatim} |
114 |
$Workfile: c_cch0.tex $ |
$Workfile: c_cch0.tex $ |
115 |
$Archive: /uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions/c_cch0.tex $ |
$Archive: /uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions/c_cch0.tex $ |
116 |
$Revision: 3 $ |
$Revision: 3 $ |
117 |
$Author: Dashley1 $ |
$Author: Dashley1 $ |
118 |
$Date: 12/31/00 7:42p $ |
$Date: 12/31/00 7:42p $ |
119 |
$Modtime: 12/24/00 4:05a $ |
$Modtime: 12/24/00 4:05a $ |
120 |
\end{verbatim} |
\end{verbatim} |
121 |
\end{tiny} |
\end{tiny} |
122 |
\noindent\rule[0.25in]{\textwidth}{1pt} |
\noindent\rule[0.25in]{\textwidth}{1pt} |
123 |
\end{figure} |
\end{figure} |
124 |
|
|
125 |
%$History: c_cch0.tex $ |
%$History: c_cch0.tex $ |
126 |
% |
% |
127 |
% ***************** Version 3 ***************** |
% ***************** Version 3 ***************** |
128 |
% User: Dashley1 Date: 12/31/00 Time: 7:42p |
% User: Dashley1 Date: 12/31/00 Time: 7:42p |
129 |
% Updated in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
% Updated in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
130 |
% |
% |
131 |
% ***************** Version 2 ***************** |
% ***************** Version 2 ***************** |
132 |
% User: Dashley1 Date: 12/22/00 Time: 12:54a |
% User: Dashley1 Date: 12/22/00 Time: 12:54a |
133 |
% Updated in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
% Updated in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
134 |
% Tcl automated method of build refined. |
% Tcl automated method of build refined. |
135 |
% |
% |
136 |
% ***************** Version 1 ***************** |
% ***************** Version 1 ***************** |
137 |
% User: David Ashley Date: 11/29/00 Time: 7:17p |
% User: David Ashley Date: 11/29/00 Time: 7:17p |
138 |
% Created in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
% Created in $/uC Software Multi-Volume Book (A)/Chapter, CCH0, CRC, Checksum, Hash Extensions |
139 |
% Initial check-in. |
% Initial check-in. |
140 |
% |
% |
141 |
%End of file C_CCH0.TEX |
%End of file C_CCH0.TEX |