ReactOS 0.4.16-dev-240-gdb5fa3b
adler32.c File Reference
#include "zutil.h"
Include dependency graph for adler32.c:

Go to the source code of this file.

Macros

#define BASE   65521U /* largest prime smaller than 65536 */
 
#define NMAX   5552
 
#define DO1(buf, i)   {adler += (buf)[i]; sum2 += adler;}
 
#define DO2(buf, i)   DO1(buf,i); DO1(buf,i+1);
 
#define DO4(buf, i)   DO2(buf,i); DO2(buf,i+2);
 
#define DO8(buf, i)   DO4(buf,i); DO4(buf,i+4);
 
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
 
#define MOD(a)   a %= BASE
 
#define MOD28(a)   a %= BASE
 
#define MOD63(a)   a %= BASE
 

Functions

uLong adler32_combine_ OF ((uLong adler1, uLong adler2, z_off64_t len2))
 
uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, z_size_t len)
 
uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
 
uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2)
 
uLong ZEXPORT adler32_combine (uLong adler1, uLong adler2, z_off_t len2)
 
uLong ZEXPORT adler32_combine64 (uLong adler1, uLong adler2, z_off64_t len2)
 

Macro Definition Documentation

◆ BASE

#define BASE   65521U /* largest prime smaller than 65536 */

Definition at line 12 of file adler32.c.

◆ DO1

#define DO1 (   buf,
  i 
)    {adler += (buf)[i]; sum2 += adler;}

Definition at line 16 of file adler32.c.

◆ DO16

#define DO16 (   buf)    DO8(buf,0); DO8(buf,8);

Definition at line 20 of file adler32.c.

◆ DO2

#define DO2 (   buf,
  i 
)    DO1(buf,i); DO1(buf,i+1);

Definition at line 17 of file adler32.c.

◆ DO4

#define DO4 (   buf,
  i 
)    DO2(buf,i); DO2(buf,i+2);

Definition at line 18 of file adler32.c.

◆ DO8

#define DO8 (   buf,
  i 
)    DO4(buf,i); DO4(buf,i+4);

Definition at line 19 of file adler32.c.

◆ MOD

#define MOD (   a)    a %= BASE

Definition at line 57 of file adler32.c.

◆ MOD28

#define MOD28 (   a)    a %= BASE

Definition at line 58 of file adler32.c.

◆ MOD63

#define MOD63 (   a)    a %= BASE

Definition at line 59 of file adler32.c.

◆ NMAX

#define NMAX   5552

Definition at line 13 of file adler32.c.

Function Documentation

◆ adler32()

uLong ZEXPORT adler32 ( uLong  adler,
const Bytef buf,
uInt  len 
)

Definition at line 134 of file adler32.c.

138{
139 return adler32_z(adler, buf, len);
140}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len)
Definition: adler32.c:63

◆ adler32_combine()

uLong ZEXPORT adler32_combine ( uLong  adler1,
uLong  adler2,
z_off_t  len2 
)

Definition at line 172 of file adler32.c.

176{
177 return adler32_combine_(adler1, adler2, len2);
178}
uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
Definition: adler32.c:143

◆ adler32_combine64()

uLong ZEXPORT adler32_combine64 ( uLong  adler1,
uLong  adler2,
z_off64_t  len2 
)

Definition at line 180 of file adler32.c.

184{
185 return adler32_combine_(adler1, adler2, len2);
186}

◆ adler32_combine_()

uLong adler32_combine_ ( uLong  adler1,
uLong  adler2,
z_off64_t  len2 
)

Definition at line 143 of file adler32.c.

147{
148 unsigned long sum1;
149 unsigned long sum2;
150 unsigned rem;
151
152 /* for negative len, return invalid adler32 as a clue for debugging */
153 if (len2 < 0)
154 return 0xffffffffUL;
155
156 /* the derivation of this formula is left as an exercise for the reader */
157 MOD63(len2); /* assumes len2 >= 0 */
158 rem = (unsigned)len2;
159 sum1 = adler1 & 0xffff;
160 sum2 = rem * sum1;
161 MOD(sum2);
162 sum1 += (adler2 & 0xffff) + BASE - 1;
163 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
164 if (sum1 >= BASE) sum1 -= BASE;
165 if (sum1 >= BASE) sum1 -= BASE;
166 if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
167 if (sum2 >= BASE) sum2 -= BASE;
168 return sum1 | (sum2 << 16);
169}
#define BASE
Definition: adler32.c:10
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define long
Definition: qsort.c:33
#define MOD63(a)
Definition: adler32.c:59
#define MOD(a)
Definition: adler32.c:57

Referenced by adler32_combine(), and adler32_combine64().

◆ adler32_z()

uLong ZEXPORT adler32_z ( uLong  adler,
const Bytef buf,
z_size_t  len 
)

Definition at line 63 of file adler32.c.

67{
68 unsigned long sum2;
69 unsigned n;
70
71 /* split Adler-32 into component sums */
72 sum2 = (adler >> 16) & 0xffff;
73 adler &= 0xffff;
74
75 /* in case user likes doing a byte at a time, keep it fast */
76 if (len == 1) {
77 adler += buf[0];
78 if (adler >= BASE)
79 adler -= BASE;
80 sum2 += adler;
81 if (sum2 >= BASE)
82 sum2 -= BASE;
83 return adler | (sum2 << 16);
84 }
85
86 /* initial Adler-32 value (deferred check for len == 1 speed) */
87 if (buf == Z_NULL)
88 return 1L;
89
90 /* in case short lengths are provided, keep it somewhat fast */
91 if (len < 16) {
92 while (len--) {
93 adler += *buf++;
94 sum2 += adler;
95 }
96 if (adler >= BASE)
97 adler -= BASE;
98 MOD28(sum2); /* only added so many BASE's */
99 return adler | (sum2 << 16);
100 }
101
102 /* do length NMAX blocks -- requires just one modulo operation */
103 while (len >= NMAX) {
104 len -= NMAX;
105 n = NMAX / 16; /* NMAX is divisible by 16 */
106 do {
107 DO16(buf); /* 16 sums unrolled */
108 buf += 16;
109 } while (--n);
110 MOD(adler);
111 MOD(sum2);
112 }
113
114 /* do remaining bytes (less than NMAX, still just one modulo) */
115 if (len) { /* avoid modulos if none remaining */
116 while (len >= 16) {
117 len -= 16;
118 DO16(buf);
119 buf += 16;
120 }
121 while (len--) {
122 adler += *buf++;
123 sum2 += adler;
124 }
125 MOD(adler);
126 MOD(sum2);
127 }
128
129 /* return recombined sums */
130 return adler | (sum2 << 16);
131}
#define Z_NULL
Definition: zlib.h:149
#define NMAX
Definition: adler32.c:11
#define DO16(buf)
Definition: adler32.c:18
GLdouble n
Definition: glext.h:7729
#define MOD28(a)
Definition: adler32.c:58

Referenced by adler32().

◆ OF()

uLong adler32_combine_ OF ( (uLong adler1, uLong adler2, z_off64_t len2)  )