Deleted Added
full compact
adler32.c (180208) adler32.c (205471)
1/* adler32.c -- compute the Adler-32 checksum of a data stream
1/* adler32.c -- compute the Adler-32 checksum of a data stream
2 * Copyright (C) 1995-2004 Mark Adler
2 * Copyright (C) 1995-2007 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#define ZLIB_INTERNAL
9#include "zlib.h"
8#include "zutil.h"
10
9
10#define local static
11
12local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
13
11#define BASE 65521UL /* largest prime smaller than 65536 */
12#define NMAX 5552
13/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
14
15#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
16#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
17#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
18#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);

--- 101 unchanged lines hidden (view full) ---

120 MOD(sum2);
121 }
122
123 /* return recombined sums */
124 return adler | (sum2 << 16);
125}
126
127/* ========================================================================= */
14#define BASE 65521UL /* largest prime smaller than 65536 */
15#define NMAX 5552
16/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
17
18#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
19#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
20#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
21#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);

--- 101 unchanged lines hidden (view full) ---

123 MOD(sum2);
124 }
125
126 /* return recombined sums */
127 return adler | (sum2 << 16);
128}
129
130/* ========================================================================= */
128uLong ZEXPORT adler32_combine(adler1, adler2, len2)
131local uLong adler32_combine_(adler1, adler2, len2)
129 uLong adler1;
130 uLong adler2;
132 uLong adler1;
133 uLong adler2;
131 z_off_t len2;
134 z_off64_t len2;
132{
133 unsigned long sum1;
134 unsigned long sum2;
135 unsigned rem;
136
137 /* the derivation of this formula is left as an exercise for the reader */
138 rem = (unsigned)(len2 % BASE);
139 sum1 = adler1 & 0xffff;
140 sum2 = rem * sum1;
141 MOD(sum2);
142 sum1 += (adler2 & 0xffff) + BASE - 1;
143 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
135{
136 unsigned long sum1;
137 unsigned long sum2;
138 unsigned rem;
139
140 /* the derivation of this formula is left as an exercise for the reader */
141 rem = (unsigned)(len2 % BASE);
142 sum1 = adler1 & 0xffff;
143 sum2 = rem * sum1;
144 MOD(sum2);
145 sum1 += (adler2 & 0xffff) + BASE - 1;
146 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
144 if (sum1 > BASE) sum1 -= BASE;
145 if (sum1 > BASE) sum1 -= BASE;
146 if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
147 if (sum2 > BASE) sum2 -= BASE;
147 if (sum1 >= BASE) sum1 -= BASE;
148 if (sum1 >= BASE) sum1 -= BASE;
149 if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
150 if (sum2 >= BASE) sum2 -= BASE;
148 return sum1 | (sum2 << 16);
149}
151 return sum1 | (sum2 << 16);
152}
153
154/* ========================================================================= */
155uLong ZEXPORT adler32_combine(adler1, adler2, len2)
156 uLong adler1;
157 uLong adler2;
158 z_off_t len2;
159{
160 return adler32_combine_(adler1, adler2, len2);
161}
162
163uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
164 uLong adler1;
165 uLong adler2;
166 z_off64_t len2;
167{
168 return adler32_combine_(adler1, adler2, len2);
169}