···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ * $Id$
99+ *
1010+ * Copyright (C) 2021 James Buren (adaptations from tinf/zlib)
1111+ *
1212+ * This program is free software; you can redistribute it and/or
1313+ * modify it under the terms of the GNU General Public License
1414+ * as published by the Free Software Foundation; either version 2
1515+ * of the License, or (at your option) any later version.
1616+ *
1717+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818+ * KIND, either express or implied.
1919+ *
2020+ ****************************************************************************/
2121+2222+#include "adler32.h"
2323+#include "system.h"
2424+2525+/* adler_32 (derived from tinf adler32 which was taken from zlib)
2626+ * Adler-32 algorithm taken from the zlib source, which is
2727+ * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
2828+ */
2929+uint32_t adler_32(const void *src, uint32_t len, uint32_t adler32)
3030+{
3131+ const unsigned char *buf = (const unsigned char *)src;
3232+ uint32_t s1 = (adler32 & 0xffff);
3333+ uint32_t s2 = (adler32 >> 16);
3434+3535+ enum {
3636+ A32_BASE = 65521,
3737+ A32_NMAX = 5552,
3838+ };
3939+4040+ while (len > 0) {
4141+ uint32_t k = MIN(len, A32_NMAX);
4242+ uint32_t i;
4343+4444+ for (i = k / 16; i; --i, buf += 16) {
4545+ s2 += s1 += buf[0];
4646+ s2 += s1 += buf[1];
4747+ s2 += s1 += buf[2];
4848+ s2 += s1 += buf[3];
4949+ s2 += s1 += buf[4];
5050+ s2 += s1 += buf[5];
5151+ s2 += s1 += buf[6];
5252+ s2 += s1 += buf[7];
5353+ s2 += s1 += buf[8];
5454+ s2 += s1 += buf[9];
5555+ s2 += s1 += buf[10];
5656+ s2 += s1 += buf[11];
5757+ s2 += s1 += buf[12];
5858+ s2 += s1 += buf[13];
5959+ s2 += s1 += buf[14];
6060+ s2 += s1 += buf[15];
6161+ }
6262+6363+ for (i = k % 16; i; --i) {
6464+ s1 += *buf++;
6565+ s2 += s1;
6666+ }
6767+6868+ s1 %= A32_BASE;
6969+ s2 %= A32_BASE;
7070+7171+ len -= k;
7272+ }
7373+7474+ return (s1 | (s2 << 16));
7575+}
+29
firmware/include/adler32.h
···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ * $Id$
99+ *
1010+ * Copyright (C) 2021 James Buren (adaptations from tinf/zlib)
1111+ *
1212+ * This program is free software; you can redistribute it and/or
1313+ * modify it under the terms of the GNU General Public License
1414+ * as published by the Free Software Foundation; either version 2
1515+ * of the License, or (at your option) any later version.
1616+ *
1717+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818+ * KIND, either express or implied.
1919+ *
2020+ ****************************************************************************/
2121+2222+#include <stdint.h>
2323+2424+#ifndef _ADLER32_H
2525+#define _ADLER32_H
2626+2727+uint32_t adler_32(const void *src, uint32_t len, uint32_t adler32);
2828+2929+#endif