Add fletcher-32 checksum algorithm and test.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 11 Jan 2012 14:40:20 +0000 (14:40 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 11 Jan 2012 14:40:20 +0000 (14:40 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5242 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/algo/fletcher32.c [new file with mode: 0644]
bertos/algo/fletcher32.h [new file with mode: 0644]
bertos/algo/fletcher32_test.c [new file with mode: 0644]

diff --git a/bertos/algo/fletcher32.c b/bertos/algo/fletcher32.c
new file mode 100644 (file)
index 0000000..d4f5ac0
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2011 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Fletcher-32 checksum algorithm
+ *
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#include "fletcher32.h"
+#include <cfg/macros.h> //MIN()
+
+void fletcher32_init(Fletcher32 *f)
+{
+       f->sum1 = 0xFFFF;
+       f->sum2 = 0xFFFF;
+       f->carry = -1;
+}
+
+void fletcher32_update(Fletcher32 *f, const void *_buf, size_t len)
+{
+       uint16_t data;
+       const uint8_t *buf = (const uint8_t *)_buf;
+       uint8_t last = buf[len-1];
+
+       if (f->carry != -1 && len)
+       {
+               data = f->carry | *buf++ << 8;
+               f->carry = -1;
+               ++len;
+       }
+       else if (len > 1)
+       {
+               data = buf[0] | buf[1] << 8;
+               buf += 2;
+       }
+
+       if (len & 1)
+               f->carry = last;
+
+       size_t l = len / 2;
+       while (l)
+       {
+               size_t tlen = MIN(l, (size_t)360);
+               l -= tlen;
+               do
+               {
+                       f->sum1 += data;
+                       f->sum2 += f->sum1;
+                       data = buf[0] | buf[1] << 8;
+                       buf += 2;
+               }
+               while (--tlen);
+               f->sum1 = (f->sum1 & 0xffff) + (f->sum1 >> 16);
+               f->sum2 = (f->sum2 & 0xffff) + (f->sum2 >> 16);
+       }
+}
+
+uint32_t fletcher32_final(Fletcher32 *f)
+{
+       uint32_t sum1, sum2;
+       sum1 = f->sum1;
+       sum2 = f->sum2;
+
+       if (f->carry != -1)
+       {
+               sum1 += f->carry;
+               sum2 += sum1;
+               sum1 = (sum1 & 0xffff) + (sum1 >> 16);
+               sum2 = (sum2 & 0xffff) + (sum2 >> 16);
+       }
+
+       /* Second reduction step to reduce sums to 16 bits */
+       sum1 = (sum1 & 0xffff) + (sum1 >> 16);
+       sum2 = (sum2 & 0xffff) + (sum2 >> 16);
+
+       return sum2 << 16 | sum1;
+}
diff --git a/bertos/algo/fletcher32.h b/bertos/algo/fletcher32.h
new file mode 100644 (file)
index 0000000..e5c61f8
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2011 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Fletcher-32 checksum algorithm
+ *
+ * \author Bernie Innocenti <batt@develer.com>
+ */
+
+#ifndef ALGO_FLETCHER32_H
+#define ALGO_FLETCHER32_H
+
+#include <cfg/compiler.h>
+
+typedef struct Fletcher32
+{
+       uint32_t sum1, sum2;
+       int carry;
+} Fletcher32;
+
+void fletcher32_init(Fletcher32 *f);
+void fletcher32_update(Fletcher32 *f, const void *_buf, size_t len);
+uint32_t fletcher32_final(Fletcher32 *f);
+
+#endif /* ALGO_FLETCHER32_H */
diff --git a/bertos/algo/fletcher32_test.c b/bertos/algo/fletcher32_test.c
new file mode 100644 (file)
index 0000000..7f13fdc
--- /dev/null
@@ -0,0 +1,546 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2011 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Fletcher-32 checksum algorithm
+ *
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#include "fletcher32.h"
+
+#include <cfg/test.h>
+#include <cfg/debug.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* Wikipedia reference implementation */
+static uint32_t fletcher32( uint16_t *data, size_t len )
+{
+        uint32_t sum1 = 0xffff, sum2 = 0xffff;
+
+        while (len) {
+                unsigned tlen = len > 360 ? 360 : len;
+                               //kprintf("tlen %d\n", tlen);
+                len -= tlen;
+                do {
+                        sum1 += *data++;
+                        sum2 += sum1;
+                                               //kprintf("sum1 %d sum2 %d\n", sum1, sum2);
+                } while (--tlen);
+                               ///kprintf("b sum1 %d sum2 %d\n", sum1, sum2);
+                sum1 = (sum1 & 0xffff) + (sum1 >> 16);
+                sum2 = (sum2 & 0xffff) + (sum2 >> 16);
+                               //kprintf("a sum1 %d sum2 %d\n", sum1, sum2);
+        }
+        /* Second reduction step to reduce sums to 16 bits */
+        sum1 = (sum1 & 0xffff) + (sum1 >> 16);
+        sum2 = (sum2 & 0xffff) + (sum2 >> 16);
+        return sum2 << 16 | sum1;
+}
+
+static uint32_t fletcher32_b(const void *buf, size_t len)
+{
+       size_t roundl = (len + 1) & 0xFFFFFFFE;
+       uint16_t *b = (uint16_t *)malloc(roundl);
+       ASSERT(b);
+       memset(b, 0, roundl);
+       memcpy(b, buf, len);
+       uint32_t f2 = fletcher32(b, roundl / 2);
+       free(b);
+       return f2;
+}
+
+
+
+int fletcher32_testSetup(void)
+{
+       kdbg_init();
+       return 0;
+}
+
+int fletcher32_testTearDown(void)
+{
+       return 0;
+}
+
+static const char *tstbufs[] =
+{
+       "",
+       "\x01",
+       "\xff",
+       "\x01\xff",
+       "\x01\x01",
+       "1", "2", "3", "4", "5", "6", "7", "8", "9",
+       "11", "22", "33", "44", "55", "66", "77", "88", "99",
+       "111", "222", "333", "444", "555", "666", "777", "888", "999",
+       "123",
+       "asd",
+       "0123456789",
+       "abcdefghijklmnopqrstuvwxyz",
+       "abcdefghijklmnopqrstuvwxyza",
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+       "abcdefghijklmnopqrstuvwxyz0123456789"
+};
+
+
+int fletcher32_testRun(void)
+{
+       Fletcher32 f;
+       Fletcher32 ft;
+       size_t tot = 0;
+       fletcher32_init(&ft);
+       for (unsigned t = 0; t < countof(tstbufs); t++)
+       {
+               fletcher32_init(&f);
+               fletcher32_update(&f, tstbufs[t], strlen(tstbufs[t]));
+               uint32_t f1 = fletcher32_final(&f);
+
+               uint32_t f2 = fletcher32_b(tstbufs[t], strlen(tstbufs[t]));
+
+               fletcher32_update(&ft, tstbufs[t], strlen(tstbufs[t]));
+               tot += strlen(tstbufs[t]);
+
+               //kdump(tstbufs[t], strlen(tstbufs[t]));
+               kprintf("f1 %08X, f2 %08X\n", f1, f2);
+               ASSERT(f1 == f2);
+       }
+
+       uint8_t *b = malloc(tot);
+       uint8_t *start = b;
+       ASSERT(b);
+       for (unsigned t = 0; t < countof(tstbufs); t++)
+       {
+               memcpy(b, tstbufs[t], strlen(tstbufs[t]));
+               b += strlen(tstbufs[t]);
+       }
+       uint32_t ft2 = fletcher32_b(start, tot);
+       uint32_t ft1 = fletcher32_final(&ft);
+       //kdump(start, tot);
+       free(start);
+       kprintf("ft1 %08X, ft2 %08X\n", ft1, ft2);
+       ASSERT(ft1 == ft2);
+       return 0;
+}
+
+TEST_MAIN(fletcher32);
+
+