summaryrefslogtreecommitdiff
path: root/crc32.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2015-05-25 23:03:25 +0200
committerHans Kristian Rosbach <hk-git@circlestorm.org>2015-05-25 23:03:25 +0200
commitd9b63c782f7f7ed44ce1e332a17e137796e8b2d1 (patch)
tree6937c47b52acb60af25dc491a48cce509c3cc58f /crc32.c
parent7e13ce3e3da11a83a893988fc0aa59302866f1e4 (diff)
Style cleanup for adler/crc code
Diffstat (limited to 'crc32.c')
-rw-r--r--crc32.c66
1 files changed, 25 insertions, 41 deletions
diff --git a/crc32.c b/crc32.c
index da7a8df..34343b2 100644
--- a/crc32.c
+++ b/crc32.c
@@ -45,24 +45,23 @@
#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:
@@ -90,14 +89,13 @@ static void make_crc_table (void);
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
@@ -131,11 +129,10 @@ static void make_crc_table()
}
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
@@ -161,8 +158,7 @@ static void make_crc_table()
}
#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++)
@@ -182,8 +178,7 @@ static void write_table(FILE *out, const uint32_t *table)
/* =========================================================================
* 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();
@@ -197,8 +192,7 @@ const uint32_t * ZEXPORT get_crc_table(void)
#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
@@ -242,8 +236,7 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len)
#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;
@@ -285,8 +278,7 @@ static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned le
#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;
@@ -326,8 +318,7 @@ static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len)
#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;
@@ -341,8 +332,7 @@ static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec)
}
/* ========================================================================= */
-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++)
@@ -350,8 +340,7 @@ 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 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 */
@@ -403,13 +392,11 @@ static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2)
}
/* ========================================================================= */
-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);
}
@@ -418,12 +405,11 @@ uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t 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);
@@ -433,16 +419,14 @@ ZLIB_INTERNAL void crc_reset(deflate_state *const 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);