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
17 #include <wsutil/adler32.h>
19 #define BASE 65521 /* largest prime smaller than 65536 */
21 /*--- update_adler32 --------------------------------------------------------*/
22 guint32 update_adler32(guint32 adler, const guint8 *buf, size_t len)
24 guint32 s1 = adler & 0xffff;
25 guint32 s2 = (adler >> 16) & 0xffff;
28 for (n = 0; n < len; n++) {
29 s1 = (s1 + buf[n]) % BASE;
30 s2 = (s2 + s1) % BASE;
32 return (s2 << 16) + s1;
35 /*--- adler32 ---------------------------------------------------------------*/
36 guint32 adler32_bytes(const guint8 *buf, size_t len)
38 return update_adler32(1, buf, len);
41 /*--- adler32_str -----------------------------------------------------------*/
42 guint32 adler32_str(const char *buf)
44 return update_adler32(1, (const guint8*)buf, strlen(buf));
47 /*---------------------------------------------------------------------------*/
50 * Editor modelines - http://www.wireshark.org/tools/modelines.html
55 * indent-tabs-mode: nil
58 * ex: set shiftwidth=2 tabstop=8 expandtab:
59 * :indentSize=2:tabSize=8:noTabs=true: