~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to linux/lib/zlib/adler32.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* adler32.c -- compute the Adler-32 checksum of a data stream
2
 
 * Copyright (C) 1995-2002 Mark Adler
3
 
 * For conditions of distribution and use, see copyright notice in zlib.h 
4
 
 */
5
 
 
6
 
/* @(#) $Id: adler32.c,v 1.4 2002/04/24 07:55:32 mcr Exp $ */
7
 
 
8
 
#include <zlib/zlib.h>
9
 
#include "zconf.h"
10
 
 
11
 
#define BASE 65521L /* 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)  {s1 += buf[i]; s2 += s1;}
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);
19
 
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
20
 
 
21
 
/* ========================================================================= */
22
 
uLong ZEXPORT adler32(adler, buf, len)
23
 
    uLong adler;
24
 
    const Bytef *buf;
25
 
    uInt len;
26
 
{
27
 
    unsigned long s1 = adler & 0xffff;
28
 
    unsigned long s2 = (adler >> 16) & 0xffff;
29
 
    int k;
30
 
 
31
 
    if (buf == Z_NULL) return 1L;
32
 
 
33
 
    while (len > 0) {
34
 
        k = len < NMAX ? len : NMAX;
35
 
        len -= k;
36
 
        while (k >= 16) {
37
 
            DO16(buf);
38
 
            buf += 16;
39
 
            k -= 16;
40
 
        }
41
 
        if (k != 0) do {
42
 
            s1 += *buf++;
43
 
            s2 += s1;
44
 
        } while (--k);
45
 
        s1 %= BASE;
46
 
        s2 %= BASE;
47
 
    }
48
 
    return (s2 << 16) | s1;
49
 
}