summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-14 13:32:23 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-14 13:32:23 +0100
commit361e321f6c7011040805a7f3d3cbdd8dfae71c3f (patch)
tree9afdc7de2c7a4db305ca30aa2b6eb7891f96a528
parent6a8f0d0a9aab073e2e79a06322e4f83e69409d05 (diff)
parentc18011259423f5d1cea7dfa67093c888c4882c1e (diff)
downloadouroboros-361e321f6c7011040805a7f3d3cbdd8dfae71c3f.tar.gz
ouroboros-361e321f6c7011040805a7f3d3cbdd8dfae71c3f.zip
Merged in dstaesse/ouroboros/be-crc32 (pull request #347)
lib: Move CRC32 implementation to library
-rw-r--r--include/ouroboros/crc32.h33
-rw-r--r--src/ipcpd/normal/CMakeLists.txt1
-rw-r--r--src/ipcpd/normal/crc32.h29
-rw-r--r--src/ipcpd/normal/shm_pci.c2
-rw-r--r--src/lib/CMakeLists.txt1
-rw-r--r--src/lib/crc32.c (renamed from src/ipcpd/normal/crc32.c)30
6 files changed, 51 insertions, 45 deletions
diff --git a/include/ouroboros/crc32.h b/include/ouroboros/crc32.h
new file mode 100644
index 00000000..3c7721de
--- /dev/null
+++ b/include/ouroboros/crc32.h
@@ -0,0 +1,33 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2017
+ *
+ * 32-bit Cyclic Redundancy Check
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef OUROBOROS_CRC32_H
+#define OUROBOROS_CRC32_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+void crc32(uint32_t * crc,
+ const void * buf,
+ size_t len);
+
+#endif /* OUROBOROS_CRC32_H */
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt
index 157baa9e..bae2f69a 100644
--- a/src/ipcpd/normal/CMakeLists.txt
+++ b/src/ipcpd/normal/CMakeLists.txt
@@ -25,7 +25,6 @@ protobuf_generate_c(RO_SRCS RO_HDRS ro.proto)
set(SOURCE_FILES
# Add source files here
addr_auth.c
- crc32.c
dir.c
fmgr.c
frct.c
diff --git a/src/ipcpd/normal/crc32.h b/src/ipcpd/normal/crc32.h
deleted file mode 100644
index 8580e553..00000000
--- a/src/ipcpd/normal/crc32.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * 32-bit Cyclic Redundancy Check
- *
- * Sander Vrijders <sander.vrijders@intec.ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef OUROBOROS_IPCPD_NORMAL_CRC32_H
-#define OUROBOROS_IPCPD_NORMAL_CRC32_H
-
-#include <stdint.h>
-
-void crc32(uint32_t * crc, const uint8_t * buf, size_t len);
-
-#endif /* OUROBOROS_IPCPD_NORMAL_CRC32_H */
diff --git a/src/ipcpd/normal/shm_pci.c b/src/ipcpd/normal/shm_pci.c
index c648618a..4d66bf06 100644
--- a/src/ipcpd/normal/shm_pci.c
+++ b/src/ipcpd/normal/shm_pci.c
@@ -24,13 +24,13 @@
#include <ouroboros/logs.h>
#include <ouroboros/errno.h>
+#include <ouroboros/crc32.h>
#include <stdlib.h>
#include <string.h>
#include "shm_pci.h"
#include "frct.h"
-#include "crc32.h"
#include "ribmgr.h"
#define PDU_TYPE_SIZE 1
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 688cf6f5..44e34139 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -31,6 +31,7 @@ set(SOURCE_FILES
cacep.c
cdap.c
cdap_req.c
+ crc32.c
dev.c
hashtable.c
irm.c
diff --git a/src/ipcpd/normal/crc32.c b/src/lib/crc32.c
index 98c91fb8..8cafe5b5 100644
--- a/src/ipcpd/normal/crc32.c
+++ b/src/lib/crc32.c
@@ -5,23 +5,22 @@
*
* Sander Vrijders <sander.vrijders@intec.ugent.be>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
*
- * This program is distributed in the hope that it will be useful,
+ * This library 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
*/
-#include <stddef.h>
-
-#include "crc32.h"
+#include <ouroboros/crc32.h>
static const uint32_t crc32_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@@ -69,14 +68,17 @@ static const uint32_t crc32_table[256] = {
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
-void crc32(uint32_t * crc, const uint8_t * buf, size_t len)
+void crc32(uint32_t * crc,
+ const void * buf,
+ size_t len)
{
size_t n;
*crc = *crc ^ 0xffffffff;
for (n = 0; n < len; n++)
- *crc = crc32_table[(*crc ^ buf[n]) & 0xff] ^ (*crc >> 8);
+ *crc = crc32_table[(*crc ^ ((uint8_t *) buf)[n]) & 0xff]
+ ^ (*crc >> 8);
*crc = *crc ^ 0xffffffff;
}