aboutsummaryrefslogtreecommitdiffstats
path: root/linux/lib/xz/xz_crc64.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2014-03-04 23:23:55 +0000
committerXin LI <delphij@FreeBSD.org>2014-03-04 23:23:55 +0000
commit442b7425c6da3ee6e0a16d65b5458a795dcc47d1 (patch)
tree3349fe96bd5cf94db21a768ba361dc35fefbf7d6 /linux/lib/xz/xz_crc64.c
parent38f44a8c7c3367df45180852ee34d7d0a81b4ed7 (diff)
downloadsrc-442b7425c6da3ee6e0a16d65b5458a795dcc47d1.tar.gz
src-442b7425c6da3ee6e0a16d65b5458a795dcc47d1.zip
This is from commit hash '6a8a2364434763a033781f6b2a605ace9a021013'.
Notes
Notes: svn path=/vendor/xz-embedded/dist/; revision=262756 svn path=/vendor/xz-embedded/6a8a2364434763a033781f6b2a605ace9a021013/; revision=262757; tag=vendor/xz-embedded/6a8a2364434763a033781f6b2a605ace9a021013
Diffstat (limited to 'linux/lib/xz/xz_crc64.c')
-rw-r--r--linux/lib/xz/xz_crc64.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/linux/lib/xz/xz_crc64.c b/linux/lib/xz/xz_crc64.c
new file mode 100644
index 000000000000..ca1caee899ae
--- /dev/null
+++ b/linux/lib/xz/xz_crc64.c
@@ -0,0 +1,50 @@
+/*
+ * CRC64 using the polynomial from ECMA-182
+ *
+ * This file is similar to xz_crc32.c. See the comments there.
+ *
+ * Authors: Lasse Collin <lasse.collin@tukaani.org>
+ * Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include "xz_private.h"
+
+#ifndef STATIC_RW_DATA
+# define STATIC_RW_DATA static
+#endif
+
+STATIC_RW_DATA uint64_t xz_crc64_table[256];
+
+XZ_EXTERN void xz_crc64_init(void)
+{
+ const uint64_t poly = 0xC96C5795D7870F42;
+
+ uint32_t i;
+ uint32_t j;
+ uint64_t r;
+
+ for (i = 0; i < 256; ++i) {
+ r = i;
+ for (j = 0; j < 8; ++j)
+ r = (r >> 1) ^ (poly & ~((r & 1) - 1));
+
+ xz_crc64_table[i] = r;
+ }
+
+ return;
+}
+
+XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
+{
+ crc = ~crc;
+
+ while (size != 0) {
+ crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+ --size;
+ }
+
+ return ~crc;
+}