http://depa.usst.edu.cn/chenjq/www2/SDesign/JavaScript/CRCcalculation.htm
The improved CRC function can be found in tinyos:
/**
* The following implementation computes the same polynomial. It should be
* (much) faster on any processor architecture, as it does not involve
* loops. Unfortunately, I can not yet give a reference to a derivation.
*
* @author Andreas Koepke
* @author Paul Curtis (pointed out this implementation on the MSP430 yahoo mailing list)
*/
uint16_t crc_Byte(uint16_t crc, uint8_t b) {
crc = (uint8_t)(crc >> 8) | (crc << 8);
crc ^= b;
crc ^= (uint8_t)(crc & 0xff) >> 4;
crc ^= crc << 12;
crc ^= (crc & 0xff) << 5;
return crc;
}
uint16_t crc_packet(uint8_t *data, int len) {
uint16_t crc = 0;
while (len-- > 0)
crc = crcByte(crc, *data++);
return crc;
}