Prusa MINI Firmware overview
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"

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

◆ TBLS

#define TBLS   1

◆ DO1

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

◆ DO8

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

◆ GF2_DIM

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

Function Documentation

◆ 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)  )

◆ get_crc_table()

const z_crc_t FAR* ZEXPORT get_crc_table ( )
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 }

◆ crc32_z()

unsigned long ZEXPORT crc32_z ( unsigned long  crc,
const unsigned char FAR buf,
z_size_t  len 
)
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 }
Here is the caller graph for this function:

◆ crc32()

unsigned long ZEXPORT crc32 ( unsigned long  crc,
const unsigned char FAR buf,
uInt  len 
)
241 {
242  return crc32_z(crc, buf, len);
243 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gf2_matrix_times()

unsigned long gf2_matrix_times ( unsigned long *  mat,
unsigned long  vec 
)
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 }
Here is the caller graph for this function:

◆ gf2_matrix_square()

void gf2_matrix_square ( unsigned long *  square,
unsigned long *  mat 
)
364 {
365  int n;
366 
367  for (n = 0; n < GF2_DIM; n++)
368  square[n] = gf2_matrix_times(mat, mat[n]);
369 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crc32_combine_()

uLong crc32_combine_ ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)
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 */
395  gf2_matrix_square(even, odd);
396 
397  /* put operator for four zero bits in odd */
398  gf2_matrix_square(odd, even);
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 */
404  gf2_matrix_square(even, odd);
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 */
414  gf2_matrix_square(odd, even);
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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crc32_combine()

uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)
432 {
433  return crc32_combine_(crc1, crc2, len2);
434 }
Here is the call graph for this function:

◆ crc32_combine64()

uLong ZEXPORT crc32_combine64 ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)
440 {
441  return crc32_combine_(crc1, crc2, len2);
442 }
Here is the call graph for this function:
gf2_matrix_times
unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.c:344
crc
png_uint_32 crc
Definition: png.c:2247
DO1
#define DO1
Definition: crc32.c:198
GF2_DIM
#define GF2_DIM
Definition: crc32.c:341
Z_NULL
#define Z_NULL
Definition: zlib.h:212
crc_table
const z_crc_t FAR crc_table[TBLS][256]
Definition: crc32.h:5
crc32_combine_
uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:372
FAR
#define FAR
Definition: zconf.h:387
square
#define square(v)
Definition: Arduino.h:62
crc32_z
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
Definition: crc32.c:202
gf2_matrix_square
void gf2_matrix_square(unsigned long *square, unsigned long *mat)
Definition: crc32.c:361
z_crc_t
unsigned long z_crc_t
Definition: zconf.h:431
DO8
#define DO8
Definition: crc32.c:199