ReactOS  0.4.14-dev-52-g6116262
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"
Include dependency graph for crc32.c:

Go to the source code of this file.

Macros

#define TBLS   1
 
#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) */
 

Functions

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

Macro Definition Documentation

◆ DO1

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

Definition at line 198 of file crc32.c.

◆ DO8

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

Definition at line 199 of file crc32.c.

◆ GF2_DIM

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

Definition at line 341 of file crc32.c.

◆ TBLS

#define TBLS   1

Definition at line 44 of file crc32.c.

Function Documentation

◆ crc32()

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

Definition at line 237 of file crc32.c.

241 {
242  return crc32_z(crc, buf, len);
243 }
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
Definition: crc32.c:202
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722

◆ crc32_combine()

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

Definition at line 428 of file crc32.c.

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

◆ crc32_combine64()

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

Definition at line 436 of file crc32.c.

440 {
441  return crc32_combine_(crc1, crc2, len2);
442 }
uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:372

◆ crc32_combine_()

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

Definition at line 372 of file crc32.c.

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

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 202 of file crc32.c.

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

Referenced by crc32().

◆ get_crc_table()

const z_crc_t FAR* ZEXPORT get_crc_table ( )

Definition at line 188 of file crc32.c.

189 {
190 #ifdef DYNAMIC_CRC_TABLE
191  if (crc_table_empty)
192  make_crc_table();
193 #endif /* DYNAMIC_CRC_TABLE */
194  return (const z_crc_t FAR *)crc_table;
195 }
unsigned long z_crc_t
Definition: zconf.h:431
const z_crc_t FAR crc_table[TBLS][256]
Definition: crc32.h:5
#define FAR
Definition: guiddef.h:36

Referenced by unzOpenCurrentFile3(), and zipOpenNewFileInZip4_64().

◆ gf2_matrix_square()

void gf2_matrix_square ( unsigned long square,
unsigned long mat 
)

Definition at line 361 of file crc32.c.

364 {
365  int n;
366 
367  for (n = 0; n < GF2_DIM; n++)
368  square[n] = gf2_matrix_times(mat, mat[n]);
369 }
GLdouble n
Definition: glext.h:7729
static const MAT2 mat
Definition: font.c:66
#define GF2_DIM
Definition: crc32.c:341
unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.c:344

Referenced by crc32_combine_().

◆ gf2_matrix_times()

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

Definition at line 344 of file crc32.c.

347 {
348  unsigned long sum;
349 
350  sum = 0;
351  while (vec) {
352  if (vec & 1)
353  sum ^= *mat;
354  vec >>= 1;
355  mat++;
356  }
357  return sum;
358 }
static const MAT2 mat
Definition: font.c:66
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
FT_Vector * vec
Definition: ftbbox.c:448

Referenced by crc32_combine_(), and gf2_matrix_square().

◆ OF() [1/3]

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

◆ OF() [2/3]

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

◆ OF() [3/3]

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