summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crc/mdso_crc32.c32
-rw-r--r--src/crc/mdso_crc64.c32
2 files changed, 64 insertions, 0 deletions
diff --git a/src/crc/mdso_crc32.c b/src/crc/mdso_crc32.c
new file mode 100644
index 0000000..1e3f6f6
--- /dev/null
+++ b/src/crc/mdso_crc32.c
@@ -0,0 +1,32 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <unistd.h>
+
+#include <mdso/mdso.h>
+#include <mdso/mdso_crc32.h>
+
+static const uint32_t crc32_table[256] = MDSO_CRC32_TABLE;
+
+uint32_t mdso_crc32_mbstr(const unsigned char * str, size_t * symlen)
+{
+ const unsigned char * ch;
+ uint32_t crc32;
+
+ crc32 = 0 ^ 0xFFFFFFFF;
+ ch = str;
+
+ while (*ch) {
+ crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF];
+ ch++;
+ }
+
+ if (symlen)
+ *symlen = ch - str;
+
+ return (crc32 ^ 0xFFFFFFFF);
+}
diff --git a/src/crc/mdso_crc64.c b/src/crc/mdso_crc64.c
new file mode 100644
index 0000000..893b87d
--- /dev/null
+++ b/src/crc/mdso_crc64.c
@@ -0,0 +1,32 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <unistd.h>
+
+#include <mdso/mdso.h>
+#include <mdso/mdso_crc64.h>
+
+static const uint64_t crc64_table[256] = MDSO_CRC64_TABLE;
+
+uint64_t mdso_crc64_mbstr(const unsigned char * str, size_t * symlen)
+{
+ const unsigned char * ch;
+ uint64_t crc64;
+
+ crc64 = 0 ^ 0xFFFFFFFFFFFFFFFF;
+ ch = str;
+
+ while (*ch) {
+ crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF];
+ ch++;
+ }
+
+ if (symlen)
+ *symlen = ch - str;
+
+ return (crc64 ^ 0xFFFFFFFFFFFFFFFF);
+}