2003-08-21 18:00:22 +00:00
|
|
|
/* adler32.c
|
|
|
|
* Compute the Adler32 checksum (RFC 1950)
|
|
|
|
* 2003 Tomas Kukosa
|
|
|
|
* Based on code from RFC 1950 (Chapter 9. Appendix: Sample code)
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2003-08-21 18:00:22 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2003-08-21 18:00:22 +00:00
|
|
|
*/
|
|
|
|
|
2014-12-28 23:45:56 +00:00
|
|
|
#include <string.h>
|
2003-08-21 18:00:22 +00:00
|
|
|
|
2012-12-26 05:57:06 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2013-11-09 14:04:52 +00:00
|
|
|
#include <wsutil/adler32.h>
|
2003-08-21 18:00:22 +00:00
|
|
|
|
|
|
|
#define BASE 65521 /* largest prime smaller than 65536 */
|
|
|
|
|
|
|
|
/*--- update_adler32 --------------------------------------------------------*/
|
2012-12-26 05:57:06 +00:00
|
|
|
guint32 update_adler32(guint32 adler, const guint8 *buf, size_t len)
|
2003-08-21 18:00:22 +00:00
|
|
|
{
|
2012-12-26 05:57:06 +00:00
|
|
|
guint32 s1 = adler & 0xffff;
|
|
|
|
guint32 s2 = (adler >> 16) & 0xffff;
|
|
|
|
size_t n;
|
2003-08-21 18:00:22 +00:00
|
|
|
|
|
|
|
for (n = 0; n < len; n++) {
|
|
|
|
s1 = (s1 + buf[n]) % BASE;
|
|
|
|
s2 = (s2 + s1) % BASE;
|
|
|
|
}
|
|
|
|
return (s2 << 16) + s1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--- adler32 ---------------------------------------------------------------*/
|
2012-12-26 05:57:06 +00:00
|
|
|
guint32 adler32_bytes(const guint8 *buf, size_t len)
|
2003-08-21 18:00:22 +00:00
|
|
|
{
|
2012-12-26 05:57:06 +00:00
|
|
|
return update_adler32(1, buf, len);
|
2003-08-21 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*--- adler32_str -----------------------------------------------------------*/
|
2012-12-26 05:57:06 +00:00
|
|
|
guint32 adler32_str(const char *buf)
|
2003-08-21 18:00:22 +00:00
|
|
|
{
|
2012-12-26 05:57:06 +00:00
|
|
|
return update_adler32(1, (const guint8*)buf, strlen(buf));
|
2003-08-21 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-10-14 15:12:16 +00:00
|
|
|
|
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-10-14 15:12:16 +00:00
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|