00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(OPENNURBS_CRC_INC_) 00018 #define OPENNURBS_CRC_INC_ 00019 00020 ON_BEGIN_EXTERNC 00021 00022 /* 00023 Description: 00024 Continues 16 bit CRC calulation to include the buffer. 00025 00026 Parameters: 00027 current_remainder - [in] 00028 sizeof_buffer - [in] number of bytes in buffer 00029 buffer - [in] 00030 00031 Example: 00032 16 bit CRC calculations are typically done something like this: 00033 00034 const ON__UINT16 crc_seed = 0; // or 1, or your favorite starting value 00035 00036 // Compute CRC on "good" data 00037 unsigned ON__UINT16 first_crc = crc_seed; 00038 first_crc = ON_CRC16( first_crc, size1, buffer1 ); 00039 ... 00040 first_crc = ON_CRC16( first_crc, sizeN, bufferN ); 00041 unsigned char two_zero_bytes[2] = (0,0); 00042 first_crc = ON_CRC16( first_crc, 2, two_zero_bytes ); 00043 00044 // make sure 16 bit CRC calculation is valid 00045 ON__UINT16 check_crc_calculation = ON_CRC16( first_crc, 2, &first_crc ); 00046 if ( check_crc_calculation != 0 ) 00047 { 00048 printf("ON_CRC16() calculated a bogus 16 bit CRC\n"); 00049 } 00050 00051 // Do something that may potentially change the values in 00052 // the buffers (like storing them on a faulty disk). 00053 00054 // Compute CRC on "suspect" data 00055 ON__UINT16 second_crc = crc_seed; 00056 second_crc = ON_CRC16( second_crc, size1, buffer1 ); 00057 ... 00058 second_crc = ON_CRC16( second_crc, sizeN, bufferN ); 00059 if ( 0 != ON_CRC16( second_crc, 2, &first_crc ) ) 00060 { 00061 printf( "The value of at least one byte has changed.\n" ); 00062 } 00063 */ 00064 ON_DECL 00065 ON__UINT16 ON_CRC16( 00066 ON__UINT16 current_remainder, 00067 size_t sizeof_buffer, 00068 const void* buffer 00069 ); 00070 00071 /* 00072 Description: 00073 Continues 32 bit CRC calulation to include the buffer 00074 00075 ON_CRC32() is a slightly altered version of zlib 1.3.3's crc32() 00076 and the zlib "legal stuff" is reproduced below. 00077 00078 ON_CRC32() and zlib's crc32() compute the same values. ON_CRC32() 00079 was renamed so it wouldn't clash with the other crc32()'s that are 00080 out there and the argument order was switched to match that used by 00081 the legacy ON_CRC16(). 00082 00083 Parameters: 00084 current_remainder - [in] 00085 sizeof_buffer - [in] number of bytes in buffer 00086 buffer - [in] 00087 00088 Example: 00089 32 bit CRC calculations are typically done something like this: 00090 00091 const ON__UINT32 crc_seed = 0; // or 1, or your favorite starting value 00092 00093 //Compute CRC on "good" data 00094 ON__UINT32 first_crc = crc_seed; 00095 first_crc = ON_CRC32( first_crc, size1, buffer1 ); 00096 ... 00097 first_crc = ON_CRC32( first_crc, sizeN, bufferN ); 00098 00099 // Do something that may potentially change the values in 00100 // the buffers (like storing them on a faulty disk). 00101 00102 // Compute CRC on "suspect" data 00103 ON__UINT32 second_crc = crc_seed; 00104 second_crc = ON_CRC32( second_crc, size1, buffer1 ); 00105 ... 00106 second_crc = ON_CRC32( second_crc, sizeN, bufferN ); 00107 if ( second_crc != first_crc ) 00108 { 00109 printf( "The value of at least one byte has changed.\n" ); 00110 } 00111 */ 00112 ON_DECL 00113 ON__UINT32 ON_CRC32( 00114 ON__UINT32 current_remainder, 00115 size_t sizeof_buffer, 00116 const void* buffer 00117 ); 00118 00119 /* 00120 zlib.h -- interface of the 'zlib' general purpose compression library 00121 version 1.1.3, July 9th, 1998 00122 00123 Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler 00124 00125 This software is provided 'as-is', without any express or implied 00126 warranty. In no event will the authors be held liable for any damages 00127 arising from the use of this software. 00128 00129 Permission is granted to anyone to use this software for any purpose, 00130 including commercial applications, and to alter it and redistribute it 00131 freely, subject to the following restrictions: 00132 00133 1. The origin of this software must not be misrepresented; you must not 00134 claim that you wrote the original software. If you use this software 00135 in a product, an acknowledgment in the product documentation would be 00136 appreciated but is not required. 00137 2. Altered source versions must be plainly marked as such, and must not be 00138 misrepresented as being the original software. 00139 3. This notice may not be removed or altered from any source distribution. 00140 00141 Jean-loup Gailly Mark Adler 00142 jloup@gzip.org madler@alumni.caltech.edu 00143 00144 The data format used by the zlib library is described by RFCs (Request for 00145 Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt 00146 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 00147 00148 */ 00149 00150 ON_END_EXTERNC 00151 00152 #endif