Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/wsutil/adler32.c
Line
Count
Source (jump to first uncovered line)
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 <wsutil/adler32.h>
14
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>
23
24
8.19k
#define BASE 65521 /* largest prime smaller than 65536 */
25
26
/*--- update_adler32 --------------------------------------------------------*/
27
uint32_t update_adler32(uint32_t adler, const uint8_t *buf, size_t len)
28
21
{
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
21
  uint32_t s1 = adler & 0xffff;
37
21
  uint32_t s2 = (adler >> 16) & 0xffff;
38
21
  size_t n;
39
40
4.11k
  for (n = 0; n < len; n++) {
41
4.09k
    s1 = (s1 + buf[n]) % BASE;
42
4.09k
    s2 = (s2 + s1)     % BASE;
43
4.09k
  }
44
21
  return (s2 << 16) + s1;
45
46
21
}
47
48
/*--- adler32 ---------------------------------------------------------------*/
49
uint32_t adler32_bytes(const uint8_t *buf, size_t len)
50
21
{
51
21
  return update_adler32(1, buf, len);
52
21
}
53
54
/*--- adler32_str -----------------------------------------------------------*/
55
uint32_t adler32_str(const char *buf)
56
0
{
57
0
  return update_adler32(1, (const uint8_t*)buf, strlen(buf));
58
0
}
59
60
/*---------------------------------------------------------------------------*/
61
62
/*
63
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
64
 *
65
 * Local Variables:
66
 * c-basic-offset: 2
67
 * tab-width: 8
68
 * indent-tabs-mode: nil
69
 * End:
70
 *
71
 * ex: set shiftwidth=2 tabstop=8 expandtab:
72
 * :indentSize=2:tabSize=8:noTabs=true:
73
 */