X-Git-Url: https://git.kernelconcepts.de/?p=metawatch.git;a=blobdiff_plain;f=crc16ccitt.c;h=ae0efe375645491829f2f3314169ace239bb5c33;hp=d468c80f5ea40425c23ec82e59c1268ba5876730;hb=a32e1e3a9f9e81bbf05beac619d1feb4941efc46;hpb=8de8db41a66bc0305400d92471596258ab58e9ad diff --git a/crc16ccitt.c b/crc16ccitt.c index d468c80..ae0efe3 100644 --- a/crc16ccitt.c +++ b/crc16ccitt.c @@ -1,5 +1,5 @@ /* - * derived from crctester.c + * derived from crctester.c 2011 by Nils Faerber * original header: * ---------------------------------------------------------------------------- * CRC tester v1.3 written on 4th of February 2003 by Sven Reifegerste (zorc/reflex) @@ -100,12 +100,19 @@ static unsigned long crctablefast (unsigned char* p, unsigned long len) unsigned long crc = crcinit_direct; - if (refin) crc = reflect(crc, order); + if (refin) + crc = reflect(crc, order); + + if (!refin) + while (len--) + crc = (crc << 8) ^ crctab[ ((crc >> (order-8)) & 0xff) ^ *p++]; + else + while (len--) + crc = (crc >> 8) ^ crctab[ (crc & 0xff) ^ *p++]; - if (!refin) while (len--) crc = (crc << 8) ^ crctab[ ((crc >> (order-8)) & 0xff) ^ *p++]; - else while (len--) crc = (crc >> 8) ^ crctab[ (crc & 0xff) ^ *p++]; + if (refout^refin) + crc = reflect(crc, order); - if (refout^refin) crc = reflect(crc, order); crc^= crcxor; crc&= crcmask; @@ -114,8 +121,8 @@ static unsigned long crctablefast (unsigned char* p, unsigned long len) static unsigned long crctable (unsigned char* p, unsigned long len) { - // normal lookup table algorithm with augmented zero bytes. - // only usable with polynom orders of 8, 16, 24 or 32. + /* normal lookup table algorithm with augmented zero bytes. */ + /* only usable with polynom orders of 8, 16, 24 or 32. */ unsigned long crc = crcinit_nondirect; @@ -138,6 +145,7 @@ static unsigned long crctable (unsigned char* p, unsigned long len) if (refout^refin) crc = reflect(crc, order); + crc^= crcxor; crc&= crcmask; @@ -148,8 +156,8 @@ static unsigned long crctable (unsigned char* p, unsigned long len) unsigned long crcbitbybit(unsigned char* p, unsigned long len) { - // bit by bit algorithm with augmented zero bytes. - // does not use lookup table, suited for polynom orders between 1...32. + /* bit by bit algorithm with augmented zero bytes. */ + /* does not use lookup table, suited for polynom orders between 1...32. */ unsigned long i, j, c, bit; unsigned long crc = crcinit_nondirect; @@ -179,6 +187,7 @@ unsigned long crcbitbybit(unsigned char* p, unsigned long len) { if (refout) crc=reflect(crc, order); + crc ^= crcxor; crc &= crcmask; @@ -365,3 +374,4 @@ int main() { return(0); } #endif +