COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"
Include dependency graph for crc32.c:

Macros

#define local   static
 
#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

static unsigned long gf2_matrix_times OF ((unsigned long *mat, unsigned long vec))
 
static void gf2_matrix_square OF ((unsigned long *square, unsigned long *mat))
 
static 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 (unsigned long crc, const unsigned char FAR *buf, uInt len)
 
static unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
 
static void gf2_matrix_square (unsigned long *square, unsigned long *mat)
 
static 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

#define local   static
#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) */

Function Documentation

static unsigned long gf2_matrix_times OF ( (unsigned long *mat, unsigned long vec)  )
static
static void gf2_matrix_square OF ( (unsigned long *square, unsigned long *mat)  )
static
static uLong crc32_combine_ OF ( (uLong crc1, uLong crc2, z_off64_t len2)  )
static
const z_crc_t FAR* ZEXPORT get_crc_table ( )
191 {
192 #ifdef DYNAMIC_CRC_TABLE
193  if (crc_table_empty)
194  make_crc_table();
195 #endif /* DYNAMIC_CRC_TABLE */
196  return (const z_crc_t FAR *)crc_table;
197 }
unsigned long z_crc_t
Definition: zconf.h:408
local const z_crc_t FAR crc_table[TBLS][256]
Definition: crc32.h:5
#define FAR
Definition: jmorecfg.h:215
unsigned long ZEXPORT crc32 ( unsigned long  crc,
const unsigned char FAR buf,
uInt  len 
)
208 {
209  if (buf == Z_NULL) return 0UL;
210 
211 #ifdef DYNAMIC_CRC_TABLE
212  if (crc_table_empty)
213  make_crc_table();
214 #endif /* DYNAMIC_CRC_TABLE */
215 
216 #ifdef BYFOUR
217  if (sizeof(void *) == sizeof(ptrdiff_t)) {
218  z_crc_t endian;
219 
220  endian = 1;
221  if (*((unsigned char *)(&endian)))
222  return crc32_little(crc, buf, len);
223  else
224  return crc32_big(crc, buf, len);
225  }
226 #endif /* BYFOUR */
227  crc = crc ^ 0xffffffffUL;
228  while (len >= 8) {
229  DO8;
230  len -= 8;
231  }
232  if (len) do {
233  DO1;
234  } while (--len);
235  return crc ^ 0xffffffffUL;
236 }
unsigned long z_crc_t
Definition: zconf.h:408
png_uint_32 crc
Definition: png.c:2173
#define DO1
Definition: crc32.c:200
#define DO8
Definition: crc32.c:201
char buf[128]
Definition: rw_test.cpp:40
#define Z_NULL
Definition: zlib.h:208
static unsigned long gf2_matrix_times ( unsigned long *  mat,
unsigned long  vec 
)
static
330 {
331  unsigned long sum;
332 
333  sum = 0;
334  while (vec) {
335  if (vec & 1)
336  sum ^= *mat;
337  vec >>= 1;
338  mat++;
339  }
340  return sum;
341 }
static void gf2_matrix_square ( unsigned long *  square,
unsigned long *  mat 
)
static
347 {
348  int n;
349 
350  for (n = 0; n < GF2_DIM; n++)
351  square[n] = gf2_matrix_times(mat, mat[n]);
352 }
#define GF2_DIM
Definition: crc32.c:324
static unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.c:327
static uLong crc32_combine_ ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)
static
359 {
360  int n;
361  unsigned long row;
362  unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
363  unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
364 
365  /* degenerate case (also disallow negative lengths) */
366  if (len2 <= 0)
367  return crc1;
368 
369  /* put operator for one zero bit in odd */
370  odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
371  row = 1;
372  for (n = 1; n < GF2_DIM; n++) {
373  odd[n] = row;
374  row <<= 1;
375  }
376 
377  /* put operator for two zero bits in even */
378  gf2_matrix_square(even, odd);
379 
380  /* put operator for four zero bits in odd */
381  gf2_matrix_square(odd, even);
382 
383  /* apply len2 zeros to crc1 (first square will put the operator for one
384  zero byte, eight zero bits, in even) */
385  do {
386  /* apply zeros operator for this bit of len2 */
387  gf2_matrix_square(even, odd);
388  if (len2 & 1)
389  crc1 = gf2_matrix_times(even, crc1);
390  len2 >>= 1;
391 
392  /* if no more bits set, then done */
393  if (len2 == 0)
394  break;
395 
396  /* another iteration of the loop with odd and even swapped */
397  gf2_matrix_square(odd, even);
398  if (len2 & 1)
399  crc1 = gf2_matrix_times(odd, crc1);
400  len2 >>= 1;
401 
402  /* if no more bits set, then done */
403  } while (len2 != 0);
404 
405  /* return combined crc */
406  crc1 ^= crc2;
407  return crc1;
408 }
#define GF2_DIM
Definition: crc32.c:324
static unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.c:327
static void gf2_matrix_square(unsigned long *square, unsigned long *mat)
Definition: crc32.c:344
uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)
415 {
416  return crc32_combine_(crc1, crc2, len2);
417 }
static uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:355
uLong ZEXPORT crc32_combine64 ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)
423 {
424  return crc32_combine_(crc1, crc2, len2);
425 }
static uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:355