#include "zutil.h"
-static uint32_t adler32_combine_ (uint32_t adler1, uint32_t adler2, z_off64_t len2);
+static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2);
#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
-#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
-#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
-#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
-#define DO16(buf) DO8(buf,0); DO8(buf,8);
+#define DO1(buf, i) {adler += (buf)[i]; sum2 += adler;}
+#define DO2(buf, i) DO1(buf, i); DO1(buf, i+1);
+#define DO4(buf, i) DO2(buf, i); DO2(buf, i+2);
+#define DO8(buf, i) DO4(buf, i); DO4(buf, i+4);
+#define DO16(buf) DO8(buf, 0); DO8(buf, 8);
/* use NO_DIVIDE if your processor does not do division in hardware --
try it both ways to see which is faster */
#endif
/* ========================================================================= */
-uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len)
-{
+uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len) {
uint32_t sum2;
unsigned n;
DO16(buf); /* 16 sums unrolled */
buf += 16;
#else
- DO8(buf,0); /* 8 sums unrolled */
+ DO8(buf, 0); /* 8 sums unrolled */
buf += 8;
#endif
} while (--n);
}
/* ========================================================================= */
-static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2)
-{
+static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
uint32_t sum1;
uint32_t sum2;
unsigned rem;
}
/* ========================================================================= */
-uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off_t len2)
-{
+uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off_t len2) {
return adler32_combine_(adler1, adler2, len2);
}
-uint32_t ZEXPORT adler32_combine64(uint32_t adler1, uint32_t adler2, z_off64_t len2)
-{
+uint32_t ZEXPORT adler32_combine64(uint32_t adler1, uint32_t adler2, z_off64_t len2) {
return adler32_combine_(adler1, adler2, len2);
}
#include "deflate.h"
#if BYTE_ORDER == LITTLE_ENDIAN
-static uint32_t crc32_little (uint32_t, const unsigned char *, unsigned);
+static uint32_t crc32_little(uint32_t, const unsigned char *, unsigned);
#elif BYTE_ORDER == BIG_ENDIAN
-static uint32_t crc32_big (uint32_t, const unsigned char *, unsigned);
+static uint32_t crc32_big(uint32_t, const unsigned char *, unsigned);
#endif
/* Local functions for crc concatenation */
-static uint32_t gf2_matrix_times (uint32_t *mat, uint32_t vec);
-static void gf2_matrix_square (uint32_t *square, uint32_t *mat);
-static uint32_t crc32_combine_ (uint32_t crc1, uint32_t crc2, z_off64_t len2);
+static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec);
+static void gf2_matrix_square(uint32_t *square, uint32_t *mat);
+static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2);
#ifdef DYNAMIC_CRC_TABLE
-
static volatile int crc_table_empty = 1;
static uint32_t crc_table[8][256];
-static void make_crc_table (void);
+static void make_crc_table(void);
#ifdef MAKECRCH
- static void write_table (FILE *, const uint32_t *);
+static void write_table(FILE *, const uint32_t *);
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
allow for word-at-a-time CRC calculation for both big-endian and little-
endian machines, where a word is four bytes.
*/
-static void make_crc_table()
-{
+static void make_crc_table() {
uint32_t c;
int n, k;
uint32_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
- static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+ static const unsigned char p[] = {0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26};
/* See if another task is already doing this (not thread-safe, but better
than nothing -- significantly reduces duration of vulnerability in
}
crc_table_empty = 0;
- }
- else { /* not first */
+ } else { /* not first */
/* wait for the other guy to finish (not efficient, but rare) */
while (crc_table_empty)
- ;
+ {}
}
#ifdef MAKECRCH
}
#ifdef MAKECRCH
-static void write_table(FILE *out, const uint32_t *table)
-{
+static void write_table(FILE *out, const uint32_t *table) {
int n;
for (n = 0; n < 256; n++)
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
-const uint32_t * ZEXPORT get_crc_table(void)
-{
+const uint32_t * ZEXPORT get_crc_table(void) {
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#define DO4 DO1; DO1; DO1; DO1
/* ========================================================================= */
-uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len)
-{
+uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len) {
if (buf == Z_NULL) return 0;
#ifdef DYNAMIC_CRC_TABLE
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
/* ========================================================================= */
-static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned len)
-{
+static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned len) {
register uint32_t c;
register const uint32_t *buf4;
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
/* ========================================================================= */
-static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len)
-{
+static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len) {
register uint32_t c;
register const uint32_t *buf4;
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
/* ========================================================================= */
-static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec)
-{
+static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) {
uint32_t sum;
sum = 0;
}
/* ========================================================================= */
-static void gf2_matrix_square(uint32_t *square, uint32_t *mat)
-{
+static void gf2_matrix_square(uint32_t *square, uint32_t *mat) {
int n;
for (n = 0; n < GF2_DIM; n++)
}
/* ========================================================================= */
-static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2)
-{
+static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
int n;
uint32_t row;
uint32_t even[GF2_DIM]; /* even-power-of-two zeros operator */
}
/* ========================================================================= */
-uint32_t ZEXPORT crc32_combine(uint32_t crc1, uint32_t crc2, z_off_t len2)
-{
+uint32_t ZEXPORT crc32_combine(uint32_t crc1, uint32_t crc2, z_off_t len2) {
return crc32_combine_(crc1, crc2, len2);
}
-uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2)
-{
+uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
return crc32_combine_(crc1, crc2, len2);
}
#include "arch/x86/x86.h"
extern void ZLIB_INTERNAL crc_fold_init(deflate_state *const s);
extern void ZLIB_INTERNAL crc_fold_copy(deflate_state *const s,
- unsigned char *dst, const unsigned char *src, long len);
+ unsigned char *dst, const unsigned char *src, long len);
extern uint32_t ZLIB_INTERNAL crc_fold_512to32(deflate_state *const s);
#endif
-ZLIB_INTERNAL void crc_reset(deflate_state *const s)
-{
+ZLIB_INTERNAL void crc_reset(deflate_state *const s) {
#ifdef X86_PCLMULQDQ_CRC
if (x86_cpu_has_pclmulqdq) {
crc_fold_init(s);
s->strm->adler = crc32(0L, Z_NULL, 0);
}
-ZLIB_INTERNAL void crc_finalize(deflate_state *const s)
-{
+ZLIB_INTERNAL void crc_finalize(deflate_state *const s) {
#ifdef X86_PCLMULQDQ_CRC
if (x86_cpu_has_pclmulqdq)
s->strm->adler = crc_fold_512to32(s);
#endif
}
-ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, long size)
-{
+ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, long size) {
#ifdef X86_PCLMULQDQ_CRC
if (x86_cpu_has_pclmulqdq) {
crc_fold_copy(strm->state, dst, strm->next_in, size);