Permalink
Browse files

Add code to detect CRC32

  • Loading branch information...
1 parent 32a5700 commit 205380c563a2dc80d10a465d5c7fd84dab26ede8 @fwhacking committed Mar 1, 2011
Showing with 86 additions and 1 deletion.
  1. +1 −1 Makefile
  2. +2 −0 bfcrypt.c
  3. +47 −0 crc32.c
  4. +36 −0 crc32.h
View
@@ -1,5 +1,5 @@
TGT = bfcrypt
-SRC = $(addsuffix .c, $(TGT) blowfish md5 sha256)
+SRC = $(addsuffix .c, $(TGT) blowfish md5 sha256 crc32)
OBJ = $(addsuffix .o, $(TGT))
INC = -I.
CFLAGS = -W -Wall -O2
View
@@ -16,6 +16,7 @@
#include "blowfish.h"
#include "md5.h"
#include "sha256.h"
+#include "crc32.h"
static void print_usage(const char *name)
{
@@ -58,6 +59,7 @@ int main(int argc, char **argv)
find_blowfish(start, offset);
find_md5(start, offset);
find_sha256(start, offset);
+ find_crc32(start, offset);
}
free(start);
View
47 crc32.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011 <fwhacking|gmail:com>
+ *
+ * This is free software, licensed under the GNU General Public License v2.
+ * See /LICENSE for more information.
+ *
+ */
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "bfcrypt.h"
+#include "crc32.h"
+
+int find_crc32(char *base, size_t offset)
+{
+ int found;
+
+ found = find_crc32_poly(base + offset);
+
+ if (found >= 0)
+ {
+ printf("%s (0x%08x) found at 0x%08lx\n", CRC32_TABLE[0].desc, CRC32_TABLE[0].poly, (unsigned long) offset);
+ }
+
+ return 0;
+}
+
+int find_crc32_poly(char *p)
+{
+ int ret = -1;
+ unsigned int i;
+
+ for (i = 0; i < sizeof(CRC32_TABLE) / sizeof(CRC32_TABLE[0]); i++)
+ {
+ if (memcmp(&CRC32_TABLE[i].poly, p, sizeof(CRC32_TABLE[0].poly)) == 0)
+ {
+ ret = i;
+ break;
+ }
+ }
+
+ return ret;
+}
View
36 crc32.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 <fwhacking|gmail:com>
+ *
+ * This is free software, licensed under the GNU General Public License v2.
+ * See /LICENSE for more information.
+ *
+ */
+
+#ifndef _CRC32_H_
+#define _CRC32_H_
+
+/*
+ * http://en.wikipedia.org/wiki/Cyclic_redundancy_check
+ */
+
+int find_crc32(char *base, size_t offset);
+int find_crc32_poly(char *p);
+
+typedef struct _crc32 {
+ char *desc;
+ uint32_t poly;
+} crc32;
+
+static crc32 CRC32_TABLE[8] =
+{
+ { "CRC-32-IEEE 802.3", 0x04c11db7L},
+ { "CRC-32-IEEE 802.3 (reversed)", 0xedb88320L},
+ { "CRC-32C (Castagnoli)", 0x1edc6f41L},
+ { "CRC-32C (Castagnoli) (reversed)", 0x82f63b78L},
+ { "CRC-32K (Koopman)", 0x741b8cd7L},
+ { "CRC-32K (Koopman) (reversed)", 0xeb31d82eL},
+ { "CRC-32Q", 0x814141abL},
+ { "CRC-32Q (reversed)", 0xd5828281L}
+};
+
+#endif // _CRC32_H_

0 comments on commit 205380c

Please sign in to comment.