opennurbs_crc.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_CRC_INC_)
18 #define OPENNURBS_CRC_INC_
19 
20 ON_BEGIN_EXTERNC
21 
22 /*
23 Description:
24  Continues 16 bit CRC calulation to include the buffer.
25 
26 Parameters:
27  current_remainder - [in]
28  sizeof_buffer - [in] number of bytes in buffer
29  buffer - [in]
30 
31 Example:
32  16 bit CRC calculations are typically done something like this:
33 
34  const ON__UINT16 crc_seed = 0; // or 1, or your favorite starting value
35 
36  // Compute CRC on "good" data
37  unsigned ON__UINT16 first_crc = crc_seed;
38  first_crc = ON_CRC16( first_crc, size1, buffer1 );
39  ...
40  first_crc = ON_CRC16( first_crc, sizeN, bufferN );
41  unsigned char two_zero_bytes[2] = (0,0);
42  first_crc = ON_CRC16( first_crc, 2, two_zero_bytes );
43 
44  // make sure 16 bit CRC calculation is valid
45  ON__UINT16 check_crc_calculation = ON_CRC16( first_crc, 2, &first_crc );
46  if ( check_crc_calculation != 0 )
47  {
48  printf("ON_CRC16() calculated a bogus 16 bit CRC\n");
49  }
50 
51  // Do something that may potentially change the values in
52  // the buffers (like storing them on a faulty disk).
53 
54  // Compute CRC on "suspect" data
55  ON__UINT16 second_crc = crc_seed;
56  second_crc = ON_CRC16( second_crc, size1, buffer1 );
57  ...
58  second_crc = ON_CRC16( second_crc, sizeN, bufferN );
59  if ( 0 != ON_CRC16( second_crc, 2, &first_crc ) )
60  {
61  printf( "The value of at least one byte has changed.\n" );
62  }
63 */
64 ON_DECL
65 ON__UINT16 ON_CRC16(
66  ON__UINT16 current_remainder,
67  size_t sizeof_buffer,
68  const void* buffer
69  );
70 
71 /*
72 Description:
73  Continues 32 bit CRC calulation to include the buffer
74 
75  ON_CRC32() is a slightly altered version of zlib 1.3.3's crc32()
76  and the zlib "legal stuff" is reproduced below.
77 
78  ON_CRC32() and zlib's crc32() compute the same values. ON_CRC32()
79  was renamed so it wouldn't clash with the other crc32()'s that are
80  out there and the argument order was switched to match that used by
81  the legacy ON_CRC16().
82 
83 Parameters:
84  current_remainder - [in]
85  sizeof_buffer - [in] number of bytes in buffer
86  buffer - [in]
87 
88 Example:
89  32 bit CRC calculations are typically done something like this:
90 
91  const ON__UINT32 crc_seed = 0; // or 1, or your favorite starting value
92 
93  //Compute CRC on "good" data
94  ON__UINT32 first_crc = crc_seed;
95  first_crc = ON_CRC32( first_crc, size1, buffer1 );
96  ...
97  first_crc = ON_CRC32( first_crc, sizeN, bufferN );
98 
99  // Do something that may potentially change the values in
100  // the buffers (like storing them on a faulty disk).
101 
102  // Compute CRC on "suspect" data
103  ON__UINT32 second_crc = crc_seed;
104  second_crc = ON_CRC32( second_crc, size1, buffer1 );
105  ...
106  second_crc = ON_CRC32( second_crc, sizeN, bufferN );
107  if ( second_crc != first_crc )
108  {
109  printf( "The value of at least one byte has changed.\n" );
110  }
111 */
112 ON_DECL
113 ON__UINT32 ON_CRC32(
114  ON__UINT32 current_remainder,
115  size_t sizeof_buffer,
116  const void* buffer
117  );
118 
119 /*
120 zlib.h -- interface of the 'zlib' general purpose compression library
121 version 1.1.3, July 9th, 1998
122 
123 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
124 
125 This software is provided 'as-is', without any express or implied
126 warranty. In no event will the authors be held liable for any damages
127 arising from the use of this software.
128 
129 Permission is granted to anyone to use this software for any purpose,
130 including commercial applications, and to alter it and redistribute it
131 freely, subject to the following restrictions:
132 
133 1. The origin of this software must not be misrepresented; you must not
134  claim that you wrote the original software. If you use this software
135  in a product, an acknowledgment in the product documentation would be
136  appreciated but is not required.
137 2. Altered source versions must be plainly marked as such, and must not be
138  misrepresented as being the original software.
139 3. This notice may not be removed or altered from any source distribution.
140 
141 Jean-loup Gailly Mark Adler
142 jloup@gzip.org madler@alumni.caltech.edu
143 
144 The data format used by the zlib library is described by RFCs (Request for
145 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
146 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
147 
148 */
149 
150 ON_END_EXTERNC
151 
152 #endif