From 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 21:39:35 +0000 Subject: 20060303 --- os/boot/libflate/crc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 os/boot/libflate/crc.c (limited to 'os/boot/libflate/crc.c') 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 + +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; +} -- cgit v1.2.3