Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"

Go to the source code of this file.

Defines

#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

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)

Define Documentation

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

Definition at line 215 of file crc32.c.

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

Definition at line 216 of file crc32.c.

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

Definition at line 339 of file crc32.c.

#define local   static

Definition at line 31 of file crc32.c.

#define TBLS   1

Definition at line 64 of file crc32.c.


Function Documentation

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

Definition at line 219 of file crc32.c.

{
    if (buf == Z_NULL) return 0UL;

#ifdef DYNAMIC_CRC_TABLE
    if (crc_table_empty)
        make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */

#ifdef BYFOUR
    if (sizeof(void *) == sizeof(ptrdiff_t)) {
        u4 endian;

        endian = 1;
        if (*((unsigned char *)(&endian)))
            return crc32_little(crc, buf, len);
        else
            return crc32_big(crc, buf, len);
    }
#endif /* BYFOUR */
    crc = crc ^ 0xffffffffUL;
    while (len >= 8) {
        DO8;
        len -= 8;
    }
    if (len) do {
        DO1;
    } while (--len);
    return crc ^ 0xffffffffUL;
}
uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Definition at line 370 of file crc32.c.

{
    int n;
    unsigned long row;
    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */
    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */

    /* degenerate case */
    if (len2 == 0)
        return crc1;

    /* put operator for one zero bit in odd */
    odd[0] = 0xedb88320L;           /* CRC-32 polynomial */
    row = 1;
    for (n = 1; n < GF2_DIM; n++) {
        odd[n] = row;
        row <<= 1;
    }

    /* put operator for two zero bits in even */
    gf2_matrix_square(even, odd);

    /* put operator for four zero bits in odd */
    gf2_matrix_square(odd, even);

    /* apply len2 zeros to crc1 (first square will put the operator for one
       zero byte, eight zero bits, in even) */
    do {
        /* apply zeros operator for this bit of len2 */
        gf2_matrix_square(even, odd);
        if (len2 & 1)
            crc1 = gf2_matrix_times(even, crc1);
        len2 >>= 1;

        /* if no more bits set, then done */
        if (len2 == 0)
            break;

        /* another iteration of the loop with odd and even swapped */
        gf2_matrix_square(odd, even);
        if (len2 & 1)
            crc1 = gf2_matrix_times(odd, crc1);
        len2 >>= 1;

        /* if no more bits set, then done */
    } while (len2 != 0);

    /* return combined crc */
    crc1 ^= crc2;
    return crc1;
}

Here is the call graph for this function:

Definition at line 205 of file crc32.c.

{
#ifdef DYNAMIC_CRC_TABLE
    if (crc_table_empty)
        make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
    return (const unsigned long FAR *)crc_table;
}
local void gf2_matrix_square ( unsigned long square,
unsigned long mat 
)

Definition at line 359 of file crc32.c.

{
    int n;

    for (n = 0; n < GF2_DIM; n++)
        square[n] = gf2_matrix_times(mat, mat[n]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 342 of file crc32.c.

{
    unsigned long sum;

    sum = 0;
    while (vec) {
        if (vec & 1)
            sum ^= *mat;
        vec >>= 1;
        mat++;
    }
    return sum;
}

Here is the caller graph for this function:

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