Geant4-11
Macros | Functions
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"

Go to the source code of this file.

Macros

#define DO1   crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
 
#define DO8   DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
 
#define GF2_DIM   32 /* dimension of GF(2) vectors (length of CRC) */
 
#define TBLS   1
 

Functions

unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, uInt len)
 
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_z (unsigned long crc, const unsigned char FAR *buf, z_size_t len)
 
const z_crc_t FAR *ZEXPORT get_crc_table ()
 
void gf2_matrix_square (unsigned long *square, unsigned long *mat)
 
unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
 
uLong crc32_combine_ OF ((uLong crc1, uLong crc2, z_off64_t len2))
 
unsigned long gf2_matrix_times OF ((unsigned long *mat, unsigned long vec))
 
void gf2_matrix_square OF ((unsigned long *square, unsigned long *mat))
 

Macro Definition Documentation

◆ DO1

#define DO1   crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)

Definition at line 197 of file crc32.c.

◆ DO8

#define DO8   DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1

Definition at line 198 of file crc32.c.

◆ GF2_DIM

#define GF2_DIM   32 /* dimension of GF(2) vectors (length of CRC) */

Definition at line 340 of file crc32.c.

◆ TBLS

#define TBLS   1

Definition at line 43 of file crc32.c.

Function Documentation

◆ crc32()

unsigned long ZEXPORT crc32 ( unsigned long  crc,
const unsigned char FAR *  buf,
uInt  len 
)

Definition at line 236 of file crc32.c.

240{
241 return crc32_z(crc, buf, len);
242}
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
Definition: crc32.c:201

References crc32_z().

Referenced by deflate(), deflateResetKeep(), gl2psPrintGzipFooter(), inflate(), and read_buf().

◆ crc32_combine()

uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Definition at line 427 of file crc32.c.

431{
432 return crc32_combine_(crc1, crc2, len2);
433}
uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:371

References crc32_combine_().

◆ crc32_combine64()

uLong ZEXPORT crc32_combine64 ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)

Definition at line 435 of file crc32.c.

439{
440 return crc32_combine_(crc1, crc2, len2);
441}

References crc32_combine_().

◆ crc32_combine_()

uLong crc32_combine_ ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)

Definition at line 371 of file crc32.c.

375{
376 int n;
377 unsigned long row;
378 unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
379 unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
380
381 /* degenerate case (also disallow negative lengths) */
382 if (len2 <= 0)
383 return crc1;
384
385 /* put operator for one zero bit in odd */
386 odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
387 row = 1;
388 for (n = 1; n < GF2_DIM; n++) {
389 odd[n] = row;
390 row <<= 1;
391 }
392
393 /* put operator for two zero bits in even */
394 gf2_matrix_square(even, odd);
395
396 /* put operator for four zero bits in odd */
397 gf2_matrix_square(odd, even);
398
399 /* apply len2 zeros to crc1 (first square will put the operator for one
400 zero byte, eight zero bits, in even) */
401 do {
402 /* apply zeros operator for this bit of len2 */
403 gf2_matrix_square(even, odd);
404 if (len2 & 1)
405 crc1 = gf2_matrix_times(even, crc1);
406 len2 >>= 1;
407
408 /* if no more bits set, then done */
409 if (len2 == 0)
410 break;
411
412 /* another iteration of the loop with odd and even swapped */
413 gf2_matrix_square(odd, even);
414 if (len2 & 1)
415 crc1 = gf2_matrix_times(odd, crc1);
416 len2 >>= 1;
417
418 /* if no more bits set, then done */
419 } while (len2 != 0);
420
421 /* return combined crc */
422 crc1 ^= crc2;
423 return crc1;
424}
#define GF2_DIM
Definition: crc32.c:340
unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.c:343
void gf2_matrix_square(unsigned long *square, unsigned long *mat)
Definition: crc32.c:360

References GF2_DIM, gf2_matrix_square(), gf2_matrix_times(), and CLHEP::detail::n.

Referenced by crc32_combine(), and crc32_combine64().

◆ crc32_z()

unsigned long ZEXPORT crc32_z ( unsigned long  crc,
const unsigned char FAR *  buf,
z_size_t  len 
)

Definition at line 201 of file crc32.c.

205{
206 if (buf == Z_NULL) return 0UL;
207
208#ifdef DYNAMIC_CRC_TABLE
209 if (crc_table_empty)
210 make_crc_table();
211#endif /* DYNAMIC_CRC_TABLE */
212
213#ifdef BYFOUR
214 if (sizeof(void *) == sizeof(ptrdiff_t)) {
215 z_crc_t endian;
216
217 endian = 1;
218 if (*((unsigned char *)(&endian)))
219 return crc32_little(crc, buf, len);
220 else
221 return crc32_big(crc, buf, len);
222 }
223#endif /* BYFOUR */
224 crc = crc ^ 0xffffffffUL;
225 while (len >= 8) {
226 DO8;
227 len -= 8;
228 }
229 if (len) do {
230 DO1;
231 } while (--len);
232 return crc ^ 0xffffffffUL;
233}
#define DO8
Definition: crc32.c:198
#define DO1
Definition: crc32.c:197
#define Z_NULL
Definition: zlib.h:212

References DO1, DO8, and Z_NULL.

Referenced by crc32().

◆ get_crc_table()

const z_crc_t FAR *ZEXPORT get_crc_table ( )

Definition at line 187 of file crc32.c.

188{
189#ifdef DYNAMIC_CRC_TABLE
190 if (crc_table_empty)
191 make_crc_table();
192#endif /* DYNAMIC_CRC_TABLE */
193 return (const z_crc_t FAR *)crc_table;
194}
const z_crc_t FAR crc_table[TBLS][256]
Definition: crc32.h:5

References crc_table.

◆ gf2_matrix_square()

void gf2_matrix_square ( unsigned long *  square,
unsigned long *  mat 
)

Definition at line 360 of file crc32.c.

363{
364 int n;
365
366 for (n = 0; n < GF2_DIM; n++)
367 square[n] = gf2_matrix_times(mat, mat[n]);
368}

References GF2_DIM, gf2_matrix_times(), and CLHEP::detail::n.

Referenced by crc32_combine_().

◆ gf2_matrix_times()

unsigned long gf2_matrix_times ( unsigned long *  mat,
unsigned long  vec 
)

Definition at line 343 of file crc32.c.

346{
347 unsigned long sum;
348
349 sum = 0;
350 while (vec) {
351 if (vec & 1)
352 sum ^= *mat;
353 vec >>= 1;
354 mat++;
355 }
356 return sum;
357}

Referenced by crc32_combine_(), and gf2_matrix_square().

◆ OF() [1/3]

uLong crc32_combine_ OF ( (uLong crc1, uLong crc2, z_off64_t len2)  )

◆ OF() [2/3]

unsigned long gf2_matrix_times OF ( (unsigned long *mat, unsigned long vec)  )

◆ OF() [3/3]

void gf2_matrix_square OF ( (unsigned long *square, unsigned long *mat)  )