/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#define ZLIB_INTERNAL
#include "zlib.h"
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
/* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE
# define MOD(a) \
do { \
} while (0)
# define MOD4(a) \
do { \
} while (0)
#else
#endif
/* ========================================================================= */
{
unsigned long sum2;
unsigned n;
/* split Adler-32 into component sums */
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
}
/* initial Adler-32 value (deferred check for len == 1 speed) */
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
}
}
/* do length NMAX blocks -- requires just one modulo operation */
do {
buf += 16;
} while (--n);
}
/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
while (len >= 16) {
len -= 16;
buf += 16;
}
while (len--) {
}
}
/* return recombined sums */
}
/* ========================================================================= */
{
unsigned long sum1;
unsigned long sum2;
unsigned rem;
/* the derivation of this formula is left as an exercise for the reader */
}