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

Compute the Adler-32 checksum of a data stream. More...

#include "zutil.h"

Macros

#define BASE   65521U /* largest prime smaller than 65536 */
 
#define NMAX   5552
 
#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 MOD(a)   a %= BASE
 
#define MOD28(a)   a %= BASE
 
#define MOD63(a)   a %= BASE
 

Functions

uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, z_size_t len)
 Same as adler32(), but with a size_t length.
 
uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
 Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum.
 
local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2)
 Combine two Adler-32 checksums into one.
 
uLong ZEXPORT adler32_combine (uLong adler1, uLong adler2, z_off_t len2)
 
uLong ZEXPORT adler32_combine64 (uLong adler1, uLong adler2, z_off64_t len2)
 

Detailed Description

Compute the Adler-32 checksum of a data stream.

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

Function Documentation

◆ adler32()

uLong ZEXPORT adler32 ( uLong  adler,
const Bytef *  buf,
uInt  len 
)

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

An Adler-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 checksum.

An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed much faster.

Usage example:

uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum.
Definition adler32.c:153
#define Z_NULL
for initializing zalloc, zfree, opaque
Definition zlib.h:245

◆ adler32_combine_()

local uLong adler32_combine_ ( uLong  adler1,
uLong  adler2,
z_off64_t  len2 
)

Combine two Adler-32 checksums into one.

For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.

Note that the z_off_t type (like off_t) is a signed integer. If len2 is negative, the result has no meaning or utility.