]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/adler32.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* adler32.c -- compute the Adler-32 checksum of a data stream
20 * Copyright (C) 1995-1998 Mark Adler
21 * For conditions of distribution and use, see copyright notice in zlib.h
24 /* @(#) $Id: adler32.c,v 1.1.1.1 2001/05/18 23:14:03 mb Exp $ */
28 #define BASE 65521L /* largest prime smaller than 65536 */
30 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
32 #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
33 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
34 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
35 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
36 #define DO16(buf) DO8(buf,0); DO8(buf,8);
38 /* ========================================================================= */
39 uLong ZEXPORT
adler32(adler
, buf
, len
)
44 unsigned long s1
= adler
& 0xffff;
45 unsigned long s2
= (adler
>> 16) & 0xffff;
48 if (buf
== Z_NULL
) return 1L;
51 k
= len
< NMAX
? len
: NMAX
;
65 return (s2
<< 16) | s1
;