update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / wsutil / adler32.c
blobbdd99395d7ae4204121ee5138882211ac9bbb336
1 /* adler32.c
2 * Compute the Adler32 checksum (RFC 1950)
3 * 2003 Tomas Kukosa
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>
15 #ifdef HAVE_ZLIBNG
16 #include <zlib-ng.h>
17 #else
18 #ifdef HAVE_ZLIB
19 #include <zlib.h>
20 #endif /* HAVE_ZLIB */
21 #endif
22 #include <string.h>
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)
30 #ifdef HAVE_ZLIBNG
31 return (uint32_t)zng_adler32(adler, buf, len);
32 #else
33 return (uint32_t)adler32(adler, buf, len);
34 #endif
35 #endif
36 uint32_t s1 = adler & 0xffff;
37 uint32_t s2 = (adler >> 16) & 0xffff;
38 size_t n;
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
65 * Local Variables:
66 * c-basic-offset: 2
67 * tab-width: 8
68 * indent-tabs-mode: nil
69 * End:
71 * ex: set shiftwidth=2 tabstop=8 expandtab:
72 * :indentSize=2:tabSize=8:noTabs=true: