CHDK_DE Vorschauversion  Trunk Rev. 5663
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
crc32.c-Dateireferenz
#include "zutil.h"
#include "crc32.h"
+ Include-Abhängigkeitsdiagramm für crc32.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

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

Funktionen

local unsigned long
gf2_matrix_times 
OF ((unsigned long *mat, unsigned long vec))
 
local void gf2_matrix_square OF ((unsigned long *square, unsigned long *mat))
 
const unsigned long FAR *ZEXPORT get_crc_table ()
 
unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
 
local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
 
local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
 
uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
 

Makro-Dokumentation

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

Definiert in Zeile 215 der Datei crc32.c.

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

Definiert in Zeile 216 der Datei crc32.c.

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

Definiert in Zeile 339 der Datei crc32.c.

#define local   static

Definiert in Zeile 31 der Datei crc32.c.

#define TBLS   1

Definiert in Zeile 64 der Datei crc32.c.

Dokumentation der Funktionen

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

Definiert in Zeile 219 der Datei crc32.c.

223 {
224  if (buf == Z_NULL) return 0UL;
225 
226 #ifdef DYNAMIC_CRC_TABLE
227  if (crc_table_empty)
228  make_crc_table();
229 #endif /* DYNAMIC_CRC_TABLE */
230 
231 #ifdef BYFOUR
232  if (sizeof(void *) == sizeof(ptrdiff_t)) {
233  u4 endian;
234 
235  endian = 1;
236  if (*((unsigned char *)(&endian)))
237  return crc32_little(crc, buf, len);
238  else
239  return crc32_big(crc, buf, len);
240  }
241 #endif /* BYFOUR */
242  crc = crc ^ 0xffffffffUL;
243  while (len >= 8) {
244  DO8;
245  len -= 8;
246  }
247  if (len) do {
248  DO1;
249  } while (--len);
250  return crc ^ 0xffffffffUL;
251 }
uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Definiert in Zeile 370 der Datei crc32.c.

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

Definiert in Zeile 205 der Datei crc32.c.

206 {
207 #ifdef DYNAMIC_CRC_TABLE
208  if (crc_table_empty)
209  make_crc_table();
210 #endif /* DYNAMIC_CRC_TABLE */
211  return (const unsigned long FAR *)crc_table;
212 }
local void gf2_matrix_square ( unsigned long *  square,
unsigned long *  mat 
)

Definiert in Zeile 359 der Datei crc32.c.

362 {
363  int n;
364 
365  for (n = 0; n < GF2_DIM; n++)
366  square[n] = gf2_matrix_times(mat, mat[n]);
367 }
local unsigned long gf2_matrix_times ( unsigned long *  mat,
unsigned long  vec 
)

Definiert in Zeile 342 der Datei crc32.c.

345 {
346  unsigned long sum;
347 
348  sum = 0;
349  while (vec) {
350  if (vec & 1)
351  sum ^= *mat;
352  vec >>= 1;
353  mat++;
354  }
355  return sum;
356 }
local unsigned long gf2_matrix_times OF ( (unsigned long *mat, unsigned long vec)  )
local void gf2_matrix_square OF ( (unsigned long *square, unsigned long *mat)  )