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