Blame zlib-src/crc32.c

Packit Service 4a2782
/* crc32.c -- compute the CRC-32 of a data stream
Packit Service 4a2782
 * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
Packit Service 4a2782
 * For conditions of distribution and use, see copyright notice in zlib.h
Packit Service 4a2782
 *
Packit Service 4a2782
 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
Packit Service 4a2782
 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
Packit Service 4a2782
 * tables for updating the shift register in one step with three exclusive-ors
Packit Service 4a2782
 * instead of four steps with four exclusive-ors.  This results in about a
Packit Service 4a2782
 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
/* @(#) $Id$ */
Packit Service 4a2782
Packit Service 4a2782
/*
Packit Service 4a2782
  Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
Packit Service 4a2782
  protection on the static variables used to control the first-use generation
Packit Service 4a2782
  of the crc tables.  Therefore, if you #define DYNAMIC_CRC_TABLE, you should
Packit Service 4a2782
  first call get_crc_table() to initialize the tables before allowing more than
Packit Service 4a2782
  one thread to use crc32().
Packit Service 4a2782
Packit Service 4a2782
  DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
#ifdef MAKECRCH
Packit Service 4a2782
#  include <stdio.h>
Packit Service 4a2782
#  ifndef DYNAMIC_CRC_TABLE
Packit Service 4a2782
#    define DYNAMIC_CRC_TABLE
Packit Service 4a2782
#  endif /* !DYNAMIC_CRC_TABLE */
Packit Service 4a2782
#endif /* MAKECRCH */
Packit Service 4a2782
Packit Service 4a2782
#include "zutil.h"      /* for STDC and FAR definitions */
Packit Service 4a2782
Packit Service 4a2782
/* Definitions for doing the crc four data bytes at a time. */
Packit Service 4a2782
#if !defined(NOBYFOUR) && defined(Z_U4)
Packit Service 4a2782
#  define BYFOUR
Packit Service 4a2782
#endif
Packit Service 4a2782
#ifdef BYFOUR
Packit Service 4a2782
   local unsigned long crc32_little OF((unsigned long,
Packit Service 4a2782
                        const unsigned char FAR *, z_size_t));
Packit Service 4a2782
   local unsigned long crc32_big OF((unsigned long,
Packit Service 4a2782
                        const unsigned char FAR *, z_size_t));
Packit Service 4a2782
#  define TBLS 8
Packit Service 4a2782
#else
Packit Service 4a2782
#  define TBLS 1
Packit Service 4a2782
#endif /* BYFOUR */
Packit Service 4a2782
Packit Service 4a2782
/* Local functions for crc concatenation */
Packit Service 4a2782
local unsigned long gf2_matrix_times OF((unsigned long *mat,
Packit Service 4a2782
                                         unsigned long vec));
Packit Service 4a2782
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
Packit Service 4a2782
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
Packit Service 4a2782
Packit Service 4a2782
Packit Service 4a2782
#ifdef DYNAMIC_CRC_TABLE
Packit Service 4a2782
Packit Service 4a2782
local volatile int crc_table_empty = 1;
Packit Service 4a2782
local z_crc_t FAR crc_table[TBLS][256];
Packit Service 4a2782
local void make_crc_table OF((void));
Packit Service 4a2782
#ifdef MAKECRCH
Packit Service 4a2782
   local void write_table OF((FILE *, const z_crc_t FAR *));
Packit Service 4a2782
#endif /* MAKECRCH */
Packit Service 4a2782
/*
Packit Service 4a2782
  Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
Packit Service 4a2782
  x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Packit Service 4a2782
Packit Service 4a2782
  Polynomials over GF(2) are represented in binary, one bit per coefficient,
Packit Service 4a2782
  with the lowest powers in the most significant bit.  Then adding polynomials
Packit Service 4a2782
  is just exclusive-or, and multiplying a polynomial by x is a right shift by
Packit Service 4a2782
  one.  If we call the above polynomial p, and represent a byte as the
Packit Service 4a2782
  polynomial q, also with the lowest power in the most significant bit (so the
Packit Service 4a2782
  byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
Packit Service 4a2782
  where a mod b means the remainder after dividing a by b.
Packit Service 4a2782
Packit Service 4a2782
  This calculation is done using the shift-register method of multiplying and
Packit Service 4a2782
  taking the remainder.  The register is initialized to zero, and for each
Packit Service 4a2782
  incoming bit, x^32 is added mod p to the register if the bit is a one (where
Packit Service 4a2782
  x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
Packit Service 4a2782
  x (which is shifting right by one and adding x^32 mod p if the bit shifted
Packit Service 4a2782
  out is a one).  We start with the highest power (least significant bit) of
Packit Service 4a2782
  q and repeat for all eight bits of q.
Packit Service 4a2782
Packit Service 4a2782
  The first table is simply the CRC of all possible eight bit values.  This is
Packit Service 4a2782
  all the information needed to generate CRCs on data a byte at a time for all
Packit Service 4a2782
  combinations of CRC register values and incoming bytes.  The remaining tables
Packit Service 4a2782
  allow for word-at-a-time CRC calculation for both big-endian and little-
Packit Service 4a2782
  endian machines, where a word is four bytes.
Packit Service 4a2782
*/
Packit Service 4a2782
local void make_crc_table()
Packit Service 4a2782
{
Packit Service 4a2782
    z_crc_t c;
Packit Service 4a2782
    int n, k;
Packit Service 4a2782
    z_crc_t poly;                       /* polynomial exclusive-or pattern */
Packit Service 4a2782
    /* terms of polynomial defining this crc (except x^32): */
Packit Service 4a2782
    static volatile int first = 1;      /* flag to limit concurrent making */
Packit Service 4a2782
    static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
Packit Service 4a2782
Packit Service 4a2782
    /* See if another task is already doing this (not thread-safe, but better
Packit Service 4a2782
       than nothing -- significantly reduces duration of vulnerability in
Packit Service 4a2782
       case the advice about DYNAMIC_CRC_TABLE is ignored) */
Packit Service 4a2782
    if (first) {
Packit Service 4a2782
        first = 0;
Packit Service 4a2782
Packit Service 4a2782
        /* make exclusive-or pattern from polynomial (0xedb88320UL) */
Packit Service 4a2782
        poly = 0;
Packit Service 4a2782
        for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
Packit Service 4a2782
            poly |= (z_crc_t)1 << (31 - p[n]);
Packit Service 4a2782
Packit Service 4a2782
        /* generate a crc for every 8-bit value */
Packit Service 4a2782
        for (n = 0; n < 256; n++) {
Packit Service 4a2782
            c = (z_crc_t)n;
Packit Service 4a2782
            for (k = 0; k < 8; k++)
Packit Service 4a2782
                c = c & 1 ? poly ^ (c >> 1) : c >> 1;
Packit Service 4a2782
            crc_table[0][n] = c;
Packit Service 4a2782
        }
Packit Service 4a2782
Packit Service 4a2782
#ifdef BYFOUR
Packit Service 4a2782
        /* generate crc for each value followed by one, two, and three zeros,
Packit Service 4a2782
           and then the byte reversal of those as well as the first table */
Packit Service 4a2782
        for (n = 0; n < 256; n++) {
Packit Service 4a2782
            c = crc_table[0][n];
Packit Service 4a2782
            crc_table[4][n] = ZSWAP32(c);
Packit Service 4a2782
            for (k = 1; k < 4; k++) {
Packit Service 4a2782
                c = crc_table[0][c & 0xff] ^ (c >> 8);
Packit Service 4a2782
                crc_table[k][n] = c;
Packit Service 4a2782
                crc_table[k + 4][n] = ZSWAP32(c);
Packit Service 4a2782
            }
Packit Service 4a2782
        }
Packit Service 4a2782
#endif /* BYFOUR */
Packit Service 4a2782
Packit Service 4a2782
        crc_table_empty = 0;
Packit Service 4a2782
    }
Packit Service 4a2782
    else {      /* not first */
Packit Service 4a2782
        /* wait for the other guy to finish (not efficient, but rare) */
Packit Service 4a2782
        while (crc_table_empty)
Packit Service 4a2782
            ;
Packit Service 4a2782
    }
Packit Service 4a2782
Packit Service 4a2782
#ifdef MAKECRCH
Packit Service 4a2782
    /* write out CRC tables to crc32.h */
Packit Service 4a2782
    {
Packit Service 4a2782
        FILE *out;
Packit Service 4a2782
Packit Service 4a2782
        out = fopen("crc32.h", "w");
Packit Service 4a2782
        if (out == NULL) return;
Packit Service 4a2782
        fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
Packit Service 4a2782
        fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
Packit Service 4a2782
        fprintf(out, "local const z_crc_t FAR ");
Packit Service 4a2782
        fprintf(out, "crc_table[TBLS][256] =\n{\n  {\n");
Packit Service 4a2782
        write_table(out, crc_table[0]);
Packit Service 4a2782
#  ifdef BYFOUR
Packit Service 4a2782
        fprintf(out, "#ifdef BYFOUR\n");
Packit Service 4a2782
        for (k = 1; k < 8; k++) {
Packit Service 4a2782
            fprintf(out, "  },\n  {\n");
Packit Service 4a2782
            write_table(out, crc_table[k]);
Packit Service 4a2782
        }
Packit Service 4a2782
        fprintf(out, "#endif\n");
Packit Service 4a2782
#  endif /* BYFOUR */
Packit Service 4a2782
        fprintf(out, "  }\n};\n");
Packit Service 4a2782
        fclose(out);
Packit Service 4a2782
    }
Packit Service 4a2782
#endif /* MAKECRCH */
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
#ifdef MAKECRCH
Packit Service 4a2782
local void write_table(
Packit Service 4a2782
    FILE *out,
Packit Service 4a2782
    const z_crc_t FAR *table)
Packit Service 4a2782
{
Packit Service 4a2782
    int n;
Packit Service 4a2782
Packit Service 4a2782
    for (n = 0; n < 256; n++)
Packit Service 4a2782
        fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : "    ",
Packit Service 4a2782
                (unsigned long)(table[n]),
Packit Service 4a2782
                n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
Packit Service 4a2782
}
Packit Service 4a2782
#endif /* MAKECRCH */
Packit Service 4a2782
Packit Service 4a2782
#else /* !DYNAMIC_CRC_TABLE */
Packit Service 4a2782
/* ========================================================================
Packit Service 4a2782
 * Tables of CRC-32s of all single-byte values, made by make_crc_table().
Packit Service 4a2782
 */
Packit Service 4a2782
#include "crc32.h"
Packit Service 4a2782
#endif /* DYNAMIC_CRC_TABLE */
Packit Service 4a2782
Packit Service 4a2782
/* =========================================================================
Packit Service 4a2782
 * This function can be used by asm versions of crc32()
Packit Service 4a2782
 */
Packit Service 4a2782
const z_crc_t FAR * ZEXPORT get_crc_table()
Packit Service 4a2782
{
Packit Service 4a2782
#ifdef DYNAMIC_CRC_TABLE
Packit Service 4a2782
    if (crc_table_empty)
Packit Service 4a2782
        make_crc_table();
Packit Service 4a2782
#endif /* DYNAMIC_CRC_TABLE */
Packit Service 4a2782
    return (const z_crc_t FAR *)crc_table;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
Packit Service 4a2782
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
unsigned long ZEXPORT crc32_z(
Packit Service 4a2782
    unsigned long crc,
Packit Service 4a2782
    const unsigned char FAR *buf,
Packit Service 4a2782
    z_size_t len)
Packit Service 4a2782
{
Packit Service 4a2782
    if (buf == Z_NULL) return 0UL;
Packit Service 4a2782
Packit Service 4a2782
#ifdef DYNAMIC_CRC_TABLE
Packit Service 4a2782
    if (crc_table_empty)
Packit Service 4a2782
        make_crc_table();
Packit Service 4a2782
#endif /* DYNAMIC_CRC_TABLE */
Packit Service 4a2782
Packit Service 4a2782
#ifdef BYFOUR
Packit Service 4a2782
    if (sizeof(void *) == sizeof(ptrdiff_t)) {
Packit Service 4a2782
        z_crc_t endian;
Packit Service 4a2782
Packit Service 4a2782
        endian = 1;
Packit Service 4a2782
        if (*((unsigned char *)(&endian)))
Packit Service 4a2782
            return crc32_little(crc, buf, len);
Packit Service 4a2782
        else
Packit Service 4a2782
            return crc32_big(crc, buf, len);
Packit Service 4a2782
    }
Packit Service 4a2782
#endif /* BYFOUR */
Packit Service 4a2782
    crc = crc ^ 0xffffffffUL;
Packit Service 4a2782
    while (len >= 8) {
Packit Service 4a2782
        DO8;
Packit Service 4a2782
        len -= 8;
Packit Service 4a2782
    }
Packit Service 4a2782
    if (len) do {
Packit Service 4a2782
        DO1;
Packit Service 4a2782
    } while (--len);
Packit Service 4a2782
    return crc ^ 0xffffffffUL;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
unsigned long ZEXPORT crc32(
Packit Service 4a2782
    unsigned long crc,
Packit Service 4a2782
    const unsigned char FAR *buf,
Packit Service 4a2782
    uInt len)
Packit Service 4a2782
{
Packit Service 4a2782
    return crc32_z(crc, buf, len);
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
#ifdef BYFOUR
Packit Service 4a2782
Packit Service 4a2782
/*
Packit Service 4a2782
   This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
Packit Service 4a2782
   integer pointer type. This violates the strict aliasing rule, where a
Packit Service 4a2782
   compiler can assume, for optimization purposes, that two pointers to
Packit Service 4a2782
   fundamentally different types won't ever point to the same memory. This can
Packit Service 4a2782
   manifest as a problem only if one of the pointers is written to. This code
Packit Service 4a2782
   only reads from those pointers. So long as this code remains isolated in
Packit Service 4a2782
   this compilation unit, there won't be a problem. For this reason, this code
Packit Service 4a2782
   should not be copied and pasted into a compilation unit in which other code
Packit Service 4a2782
   writes to the buffer that is passed to these routines.
Packit Service 4a2782
 */
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
#define DOLIT4 c ^= *buf4++; \
Packit Service 4a2782
        c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
Packit Service 4a2782
            crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
Packit Service 4a2782
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
local unsigned long crc32_little(
Packit Service 4a2782
    unsigned long crc,
Packit Service 4a2782
    const unsigned char FAR *buf,
Packit Service 4a2782
    z_size_t len)
Packit Service 4a2782
{
Packit Service 4a2782
    register z_crc_t c;
Packit Service 4a2782
    register const z_crc_t FAR *buf4;
Packit Service 4a2782
Packit Service 4a2782
    c = (z_crc_t)crc;
Packit Service 4a2782
    c = ~c;
Packit Service 4a2782
    while (len && ((ptrdiff_t)buf & 3)) {
Packit Service 4a2782
        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
Packit Service 4a2782
        len--;
Packit Service 4a2782
    }
Packit Service 4a2782
Packit Service 4a2782
    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
Packit Service 4a2782
    while (len >= 32) {
Packit Service 4a2782
        DOLIT32;
Packit Service 4a2782
        len -= 32;
Packit Service 4a2782
    }
Packit Service 4a2782
    while (len >= 4) {
Packit Service 4a2782
        DOLIT4;
Packit Service 4a2782
        len -= 4;
Packit Service 4a2782
    }
Packit Service 4a2782
    buf = (const unsigned char FAR *)buf4;
Packit Service 4a2782
Packit Service 4a2782
    if (len) do {
Packit Service 4a2782
        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
Packit Service 4a2782
    } while (--len);
Packit Service 4a2782
    c = ~c;
Packit Service 4a2782
    return (unsigned long)c;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
#define DOBIG4 c ^= *buf4++; \
Packit Service 4a2782
        c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
Packit Service 4a2782
            crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
Packit Service 4a2782
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
local unsigned long crc32_big(
Packit Service 4a2782
    unsigned long crc,
Packit Service 4a2782
    const unsigned char FAR *buf,
Packit Service 4a2782
    z_size_t len)
Packit Service 4a2782
{
Packit Service 4a2782
    register z_crc_t c;
Packit Service 4a2782
    register const z_crc_t FAR *buf4;
Packit Service 4a2782
Packit Service 4a2782
    c = ZSWAP32((z_crc_t)crc);
Packit Service 4a2782
    c = ~c;
Packit Service 4a2782
    while (len && ((ptrdiff_t)buf & 3)) {
Packit Service 4a2782
        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
Packit Service 4a2782
        len--;
Packit Service 4a2782
    }
Packit Service 4a2782
Packit Service 4a2782
    buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
Packit Service 4a2782
    while (len >= 32) {
Packit Service 4a2782
        DOBIG32;
Packit Service 4a2782
        len -= 32;
Packit Service 4a2782
    }
Packit Service 4a2782
    while (len >= 4) {
Packit Service 4a2782
        DOBIG4;
Packit Service 4a2782
        len -= 4;
Packit Service 4a2782
    }
Packit Service 4a2782
    buf = (const unsigned char FAR *)buf4;
Packit Service 4a2782
Packit Service 4a2782
    if (len) do {
Packit Service 4a2782
        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
Packit Service 4a2782
    } while (--len);
Packit Service 4a2782
    c = ~c;
Packit Service 4a2782
    return (unsigned long)(ZSWAP32(c));
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
#endif /* BYFOUR */
Packit Service 4a2782
Packit Service 4a2782
#define GF2_DIM 32      /* dimension of GF(2) vectors (length of CRC) */
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
local unsigned long gf2_matrix_times(
Packit Service 4a2782
    unsigned long *mat,
Packit Service 4a2782
    unsigned long vec)
Packit Service 4a2782
{
Packit Service 4a2782
    unsigned long sum;
Packit Service 4a2782
Packit Service 4a2782
    sum = 0;
Packit Service 4a2782
    while (vec) {
Packit Service 4a2782
        if (vec & 1)
Packit Service 4a2782
            sum ^= *mat;
Packit Service 4a2782
        vec >>= 1;
Packit Service 4a2782
        mat++;
Packit Service 4a2782
    }
Packit Service 4a2782
    return sum;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
local void gf2_matrix_square(
Packit Service 4a2782
    unsigned long *square,
Packit Service 4a2782
    unsigned long *mat)
Packit Service 4a2782
{
Packit Service 4a2782
    int n;
Packit Service 4a2782
Packit Service 4a2782
    for (n = 0; n < GF2_DIM; n++)
Packit Service 4a2782
        square[n] = gf2_matrix_times(mat, mat[n]);
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
local uLong crc32_combine_(
Packit Service 4a2782
    uLong crc1,
Packit Service 4a2782
    uLong crc2,
Packit Service 4a2782
    z_off64_t len2)
Packit Service 4a2782
{
Packit Service 4a2782
    int n;
Packit Service 4a2782
    unsigned long row;
Packit Service 4a2782
    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */
Packit Service 4a2782
    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */
Packit Service 4a2782
Packit Service 4a2782
    /* degenerate case (also disallow negative lengths) */
Packit Service 4a2782
    if (len2 <= 0)
Packit Service 4a2782
        return crc1;
Packit Service 4a2782
Packit Service 4a2782
    /* put operator for one zero bit in odd */
Packit Service 4a2782
    odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */
Packit Service 4a2782
    row = 1;
Packit Service 4a2782
    for (n = 1; n < GF2_DIM; n++) {
Packit Service 4a2782
        odd[n] = row;
Packit Service 4a2782
        row <<= 1;
Packit Service 4a2782
    }
Packit Service 4a2782
Packit Service 4a2782
    /* put operator for two zero bits in even */
Packit Service 4a2782
    gf2_matrix_square(even, odd);
Packit Service 4a2782
Packit Service 4a2782
    /* put operator for four zero bits in odd */
Packit Service 4a2782
    gf2_matrix_square(odd, even);
Packit Service 4a2782
Packit Service 4a2782
    /* apply len2 zeros to crc1 (first square will put the operator for one
Packit Service 4a2782
       zero byte, eight zero bits, in even) */
Packit Service 4a2782
    do {
Packit Service 4a2782
        /* apply zeros operator for this bit of len2 */
Packit Service 4a2782
        gf2_matrix_square(even, odd);
Packit Service 4a2782
        if (len2 & 1)
Packit Service 4a2782
            crc1 = gf2_matrix_times(even, crc1);
Packit Service 4a2782
        len2 >>= 1;
Packit Service 4a2782
Packit Service 4a2782
        /* if no more bits set, then done */
Packit Service 4a2782
        if (len2 == 0)
Packit Service 4a2782
            break;
Packit Service 4a2782
Packit Service 4a2782
        /* another iteration of the loop with odd and even swapped */
Packit Service 4a2782
        gf2_matrix_square(odd, even);
Packit Service 4a2782
        if (len2 & 1)
Packit Service 4a2782
            crc1 = gf2_matrix_times(odd, crc1);
Packit Service 4a2782
        len2 >>= 1;
Packit Service 4a2782
Packit Service 4a2782
        /* if no more bits set, then done */
Packit Service 4a2782
    } while (len2 != 0);
Packit Service 4a2782
Packit Service 4a2782
    /* return combined crc */
Packit Service 4a2782
    crc1 ^= crc2;
Packit Service 4a2782
    return crc1;
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
/* ========================================================================= */
Packit Service 4a2782
uLong ZEXPORT crc32_combine(
Packit Service 4a2782
    uLong crc1,
Packit Service 4a2782
    uLong crc2,
Packit Service 4a2782
    z_off_t len2)
Packit Service 4a2782
{
Packit Service 4a2782
    return crc32_combine_(crc1, crc2, len2);
Packit Service 4a2782
}
Packit Service 4a2782
Packit Service 4a2782
uLong ZEXPORT crc32_combine64(
Packit Service 4a2782
    uLong crc1,
Packit Service 4a2782
    uLong crc2,
Packit Service 4a2782
    z_off64_t len2)
Packit Service 4a2782
{
Packit Service 4a2782
    return crc32_combine_(crc1, crc2, len2);
Packit Service 4a2782
}