2 * Compute the Adler32 checksum (RFC 1950)
4 * Based on code from RFC 1950 (Chapter 9. Appendix: Sample code)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <wsutil/adler32.h>
20 #endif /* HAVE_ZLIB */
24 #define BASE 65521 /* largest prime smaller than 65536 */
26 /*--- update_adler32 --------------------------------------------------------*/
27 uint32_t update_adler32(uint32_t adler
, const uint8_t *buf
, size_t len
)
29 #if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG)
31 return (uint32_t)zng_adler32(adler
, buf
, len
);
33 return (uint32_t)adler32(adler
, buf
, len
);
36 uint32_t s1
= adler
& 0xffff;
37 uint32_t s2
= (adler
>> 16) & 0xffff;
40 for (n
= 0; n
< len
; n
++) {
41 s1
= (s1
+ buf
[n
]) % BASE
;
42 s2
= (s2
+ s1
) % BASE
;
44 return (s2
<< 16) + s1
;
48 /*--- adler32 ---------------------------------------------------------------*/
49 uint32_t adler32_bytes(const uint8_t *buf
, size_t len
)
51 return update_adler32(1, buf
, len
);
54 /*--- adler32_str -----------------------------------------------------------*/
55 uint32_t adler32_str(const char *buf
)
57 return update_adler32(1, (const uint8_t*)buf
, strlen(buf
));
60 /*---------------------------------------------------------------------------*/
63 * Editor modelines - https://www.wireshark.org/tools/modelines.html
68 * indent-tabs-mode: nil
71 * ex: set shiftwidth=2 tabstop=8 expandtab:
72 * :indentSize=2:tabSize=8:noTabs=true: