--- libelwix/src/crc.c 2019/12/18 20:00:18 1.5.28.1 +++ libelwix/src/crc.c 2019/12/30 18:11:16 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: crc.c,v 1.5.28.1 2019/12/18 20:00:18 misho Exp $ +* $Id: crc.c,v 1.6 2019/12/30 18:11:16 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -190,14 +190,14 @@ crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha /* - * crc16() - Checksum in X/Y modem communication + * crc16_ext() - Checksum ver.2 calculation in X/Y modem communication * * @buf = Data for calculation * @bufLen = Length of data * return: Checksum */ u_short -crc16(u_char * __restrict buf, int bufLen) +crc16_ext(u_char * __restrict buf, int bufLen) { u_short crc, x; register u_short i; @@ -221,6 +221,31 @@ crc16(u_char * __restrict buf, int bufLen) if (x) crc ^= crc_16poly; + } + + return crc; +} + +/* + * crc16() - Checksum calculation in X/Y modem communication + * + * @buf = Data for calculation + * @bufLen = Length of data + * return: Checksum + */ +u_short +crc16(u_char * __restrict buf, int bufLen) +{ + u_short crc; + register u_char i; + + for (crc = 0; bufLen > 0; bufLen--, buf++) { + crc ^= (u_short) *buf << 8; + for (i = 0x80; i; i >>= 1) + if (crc & 0x8000) + crc = crc << 1 ^ crc_16poly; + else + crc <<= 1; } return crc;