26# ifndef DYNAMIC_CRC_TABLE
27# define DYNAMIC_CRC_TABLE
34#if !defined(NOBYFOUR) && defined(Z_U4)
38 local unsigned long crc32_little
OF((
unsigned long,
40 local unsigned long crc32_big
OF((
unsigned long,
54#ifdef DYNAMIC_CRC_TABLE
56local volatile int crc_table_empty = 1;
58local void make_crc_table
OF((
void));
88local void make_crc_table()
94 static volatile int first = 1;
95 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
105 for (n = 0; n < (int)(
sizeof(p)/
sizeof(
unsigned char)); n++)
106 poly |= (
z_crc_t)1 << (31 - p[n]);
109 for (n = 0; n < 256; n++) {
111 for (k = 0; k < 8; k++)
112 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
119 for (n = 0; n < 256; n++) {
122 for (k = 1; k < 4; k++) {
134 while (crc_table_empty)
143 out = fopen(
"crc32.h",
"w");
144 if (out == NULL)
return;
145 fprintf(out,
"/* crc32.h -- tables for rapid CRC calculation\n");
146 fprintf(out,
" * Generated automatically by crc32.c\n */\n\n");
147 fprintf(out,
"local const z_crc_t FAR ");
148 fprintf(out,
"crc_table[TBLS][256] =\n{\n {\n");
151 fprintf(out,
"#ifdef BYFOUR\n");
152 for (k = 1; k < 8; k++) {
153 fprintf(out,
" },\n {\n");
156 fprintf(out,
"#endif\n");
158 fprintf(out,
" }\n};\n");
165local void write_table(out, table)
171 for (n = 0; n < 256; n++)
172 fprintf(out,
"%s0x%08lxUL%s", n % 5 ?
"" :
" ",
173 (
unsigned long)(table[n]),
174 n == 255 ?
"\n" : (n % 5 == 4 ?
",\n" :
", "));
190#ifdef DYNAMIC_CRC_TABLE
198#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
199#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
204 const unsigned char FAR *buf;
207 if (buf ==
Z_NULL)
return 0UL;
209#ifdef DYNAMIC_CRC_TABLE
215 if (
sizeof(
void *) ==
sizeof(ptrdiff_t)) {
219 if (*((
unsigned char *)(&endian)))
220 return crc32_little(crc, buf, len);
222 return crc32_big(crc, buf, len);
225 crc = crc ^ 0xffffffffUL;
233 return crc ^ 0xffffffffUL;
239 const unsigned char FAR *buf;
260#define DOLIT4 c ^= *buf4++; \
261 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
262 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
263#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
266local unsigned long crc32_little(crc, buf, len)
268 const unsigned char FAR *buf;
276 while (len && ((ptrdiff_t)buf & 3)) {
277 c =
crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
290 buf = (
const unsigned char FAR *)buf4;
293 c =
crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
296 return (
unsigned long)c;
300#define DOBIG4 c ^= *buf4++; \
301 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
302 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
303#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
306local unsigned long crc32_big(crc, buf, len)
308 const unsigned char FAR *buf;
316 while (len && ((ptrdiff_t)buf & 3)) {
317 c =
crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
330 buf = (
const unsigned char FAR *)buf4;
333 c =
crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
336 return (
unsigned long)(
ZSWAP32(c));
362 unsigned long *square;
387 odd[0] = 0xedb88320UL;
389 for (n = 1; n <
GF2_DIM; n++) {
const z_crc_t FAR *ZEXPORT get_crc_table()
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
unsigned long gf2_matrix_times OF((unsigned long *mat, unsigned long vec))
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2)
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
void gf2_matrix_square(unsigned long *square, unsigned long *mat)
const z_crc_t FAR crc_table[TBLS][256]