ZLIB
Loading...
Searching...
No Matches
crc32.c File Reference

Compute the CRC-32 of a data stream. More...

#include "zutil.h"
#include "crc32.h"

Macros

#define N   5
 
#define W   4
 
#define POLY   0xedb88320 /* p(x) reflected, with x^32 implied */
 

Functions

local z_crc_t multmodp (z_crc_t a, z_crc_t b)
 
local z_crc_t x2nmodp (z_off64_t n, unsigned k)
 
const z_crc_t FAR *ZEXPORT get_crc_table (void)
 
unsigned long ZEXPORT crc32_z (unsigned long crc, const unsigned char FAR *buf, z_size_t len)
 Same as crc32(), but with a size_t length.
 
unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, uInt len)
 Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32.
 
uLong ZEXPORT crc32_combine64 (uLong crc1, uLong crc2, z_off64_t len2)
 
uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
 Combine two CRC-32 check values into one.
 
uLong ZEXPORT crc32_combine_gen64 (z_off64_t len2)
 
uLong ZEXPORT crc32_combine_gen (z_off_t len2)
 
uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op)
 Give the same result as crc32_combine(), using op in place of len2.
 

Detailed Description

Compute the CRC-32 of a data stream.

Copyright (C) 1995-2022 Mark Adler For conditions of distribution and use, see copyright notice in zlib.h

This interleaved implementation of a CRC makes use of pipelined multiple arithmetic-logic units, commonly found in modern CPU cores. It is due to Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.

Function Documentation

◆ crc32()

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

Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32.

A CRC-32 value is in the range of a 32-bit unsigned integer. If buf is Z_NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application.

Usage example:

uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
#define Z_NULL
for initializing zalloc, zfree, opaque
Definition zlib.h:245

◆ crc32_combine()

uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Combine two CRC-32 check values into one.

For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and len2.

◆ crc32_combine_op()

uLong ZEXPORT crc32_combine_op ( uLong  crc1,
uLong  crc2,
uLong  op 
)

Give the same result as crc32_combine(), using op in place of len2.

op is is generated from len2 by crc32_combine_gen(). This will be faster than crc32_combine() if the generated op is used more than once.