zlib123/adler32.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 06 Sep 2005 06:24:42 +0000
changeset 747 3da194b12f43
parent 718 2e809894a316
permissions -rw-r--r--
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
718
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/* adler32.c -- compute the Adler-32 checksum of a data stream
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Copyright (C) 1995-2004 Mark Adler
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 * For conditions of distribution and use, see copyright notice in zlib.h
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
/* @(#) $Id$ */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#define ZLIB_INTERNAL
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include "zlib.h"
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#define BASE 65521UL    /* largest prime smaller than 65536 */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#define NMAX 5552
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
/* use NO_DIVIDE if your processor does not do division in hardware */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#ifdef NO_DIVIDE
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#  define MOD(a) \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
    do { \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
        if (a >= (BASE << 16)) a -= (BASE << 16); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
        if (a >= (BASE << 15)) a -= (BASE << 15); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
        if (a >= (BASE << 14)) a -= (BASE << 14); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
        if (a >= (BASE << 13)) a -= (BASE << 13); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
        if (a >= (BASE << 12)) a -= (BASE << 12); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
        if (a >= (BASE << 11)) a -= (BASE << 11); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        if (a >= (BASE << 10)) a -= (BASE << 10); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
        if (a >= (BASE << 9)) a -= (BASE << 9); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
        if (a >= (BASE << 8)) a -= (BASE << 8); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
        if (a >= (BASE << 7)) a -= (BASE << 7); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        if (a >= (BASE << 6)) a -= (BASE << 6); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        if (a >= (BASE << 5)) a -= (BASE << 5); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
        if (a >= (BASE << 4)) a -= (BASE << 4); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
        if (a >= (BASE << 3)) a -= (BASE << 3); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        if (a >= (BASE << 2)) a -= (BASE << 2); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        if (a >= (BASE << 1)) a -= (BASE << 1); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        if (a >= BASE) a -= BASE; \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    } while (0)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#  define MOD4(a) \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    do { \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        if (a >= (BASE << 4)) a -= (BASE << 4); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        if (a >= (BASE << 3)) a -= (BASE << 3); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        if (a >= (BASE << 2)) a -= (BASE << 2); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        if (a >= (BASE << 1)) a -= (BASE << 1); \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        if (a >= BASE) a -= BASE; \
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    } while (0)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
#else
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
#  define MOD(a) a %= BASE
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
#  define MOD4(a) a %= BASE
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
#endif
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
/* ========================================================================= */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
uLong ZEXPORT adler32(adler, buf, len)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    uLong adler;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    const Bytef *buf;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    uInt len;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
{
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    unsigned long sum2;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    unsigned n;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    /* split Adler-32 into component sums */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    sum2 = (adler >> 16) & 0xffff;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    adler &= 0xffff;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    /* in case user likes doing a byte at a time, keep it fast */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    if (len == 1) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        adler += buf[0];
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        if (adler >= BASE)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            adler -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        sum2 += adler;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        if (sum2 >= BASE)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            sum2 -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        return adler | (sum2 << 16);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    /* initial Adler-32 value (deferred check for len == 1 speed) */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    if (buf == Z_NULL)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
        return 1L;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    /* in case short lengths are provided, keep it somewhat fast */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
    if (len < 16) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
        while (len--) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
            adler += *buf++;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            sum2 += adler;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
        }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
        if (adler >= BASE)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
            adler -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
        MOD4(sum2);             /* only added so many BASE's */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        return adler | (sum2 << 16);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    /* do length NMAX blocks -- requires just one modulo operation */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    while (len >= NMAX) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
        len -= NMAX;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
        n = NMAX / 16;          /* NMAX is divisible by 16 */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
        do {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
            DO16(buf);          /* 16 sums unrolled */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
            buf += 16;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        } while (--n);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        MOD(adler);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
        MOD(sum2);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    /* do remaining bytes (less than NMAX, still just one modulo) */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    if (len) {                  /* avoid modulos if none remaining */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
        while (len >= 16) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
            len -= 16;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
            DO16(buf);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
            buf += 16;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
        }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        while (len--) {
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
            adler += *buf++;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            sum2 += adler;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
        }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
        MOD(adler);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        MOD(sum2);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    }
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    /* return recombined sums */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    return adler | (sum2 << 16);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
}
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
/* ========================================================================= */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    uLong adler1;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    uLong adler2;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    z_off_t len2;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
{
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    unsigned long sum1;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    unsigned long sum2;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    unsigned rem;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    /* the derivation of this formula is left as an exercise for the reader */
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    rem = (unsigned)(len2 % BASE);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    sum1 = adler1 & 0xffff;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    sum2 = rem * sum1;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    MOD(sum2);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    sum1 += (adler2 & 0xffff) + BASE - 1;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    if (sum1 > BASE) sum1 -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    if (sum1 > BASE) sum1 -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    if (sum2 > BASE) sum2 -= BASE;
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    return sum1 | (sum2 << 16);
2e809894a316 Moved to actual zlib 1.2.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
}