summaryrefslogtreecommitdiff
path: root/os/boot/libflate/crc.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
commit74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch)
treec6e220ba61db3a6ea4052e6841296d829654e664 /os/boot/libflate/crc.c
parent46439007cf417cbd9ac8049bb4122c890097a0fa (diff)
20060303
Diffstat (limited to 'os/boot/libflate/crc.c')
-rw-r--r--os/boot/libflate/crc.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/os/boot/libflate/crc.c b/os/boot/libflate/crc.c
new file mode 100644
index 00000000..76709308
--- /dev/null
+++ b/os/boot/libflate/crc.c
@@ -0,0 +1,39 @@
+#include "lib9.h"
+#include <flate.h>
+
+ulong*
+mkcrctab(ulong poly)
+{
+ ulong *crctab;
+ ulong crc;
+ int i, j;
+
+ crctab = malloc(256 * sizeof(ulong));
+ if(crctab == nil)
+ return nil;
+
+ for(i = 0; i < 256; i++){
+ crc = i;
+ for(j = 0; j < 8; j++){
+ if(crc & 1)
+ crc = (crc >> 1) ^ poly;
+ else
+ crc >>= 1;
+ }
+ crctab[i] = crc;
+ }
+ return crctab;
+}
+
+ulong
+blockcrc(ulong *crctab, ulong crc, void *vbuf, int n)
+{
+ uchar *buf, *ebuf;
+
+ crc ^= 0xffffffff;
+ buf = vbuf;
+ ebuf = buf + n;
+ while(buf < ebuf)
+ crc = crctab[(crc & 0xff) ^ *buf++] ^ (crc >> 8);
+ return crc ^ 0xffffffff;
+}