epan: use json_dumper for json outputs.
[metze/wireshark/wip.git] / wsutil / adler32.c
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)
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12
13 #include <string.h>
14
15 #include <glib.h>
16
17 #include <wsutil/adler32.h>
18
19 #define BASE 65521 /* largest prime smaller than 65536 */
20
21 /*--- update_adler32 --------------------------------------------------------*/
22 guint32 update_adler32(guint32 adler, const guint8 *buf, size_t len)
23 {
24   guint32 s1 = adler & 0xffff;
25   guint32 s2 = (adler >> 16) & 0xffff;
26   size_t n;
27
28   for (n = 0; n < len; n++) {
29     s1 = (s1 + buf[n]) % BASE;
30     s2 = (s2 + s1)     % BASE;
31   }
32   return (s2 << 16) + s1;
33 }
34
35 /*--- adler32 ---------------------------------------------------------------*/
36 guint32 adler32_bytes(const guint8 *buf, size_t len)
37 {
38   return update_adler32(1, buf, len);
39 }
40
41 /*--- adler32_str -----------------------------------------------------------*/
42 guint32 adler32_str(const char *buf)
43 {
44   return update_adler32(1, (const guint8*)buf, strlen(buf));
45 }
46
47 /*---------------------------------------------------------------------------*/
48
49 /*
50  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
51  *
52  * Local Variables:
53  * c-basic-offset: 2
54  * tab-width: 8
55  * indent-tabs-mode: nil
56  * End:
57  *
58  * ex: set shiftwidth=2 tabstop=8 expandtab:
59  * :indentSize=2:tabSize=8:noTabs=true:
60  */