version 1.1, 2004/10/28 21:08:18
|
version 1.2, 2008/11/12 21:46:44
|
Line 18
|
Line 18
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
*/ |
|
|
#include <sys/types.h> |
#include <stdint.h> |
#include "crc16.h" |
#include "crc16.h" |
|
|
u_int16_t crc_16_table[256]; |
uint16_t crc_16_table[256]; |
|
|
// generate the tables of CRC-16 remainders for all possible bytes |
// generate the tables of CRC-16 remainders for all possible bytes |
void gen_crc16_table() { |
void gen_crc16_table() { |
register int i,j; |
register int i,j; |
register u_int16_t crc16; |
register uint16_t crc16; |
for (i=0; i<256; i++) { |
for (i=0; i<256; i++) { |
crc16=(u_int16_t)i << 8; |
crc16=(uint16_t)i << 8; |
for (j=0; j<8; j++) { |
for (j=0; j<8; j++) { |
crc16 = (crc16 << 1) ^ ((crc16 & (1<<15)) ? POLYNOMIAL_16_MSBF : 0); |
crc16 = (crc16 << 1) ^ ((crc16 & (1<<15)) ? POLYNOMIAL_16_MSBF : 0); |
} |
} |
Line 37 void gen_crc16_table() {
|
Line 37 void gen_crc16_table() {
|
} |
} |
|
|
// update the CRC on the data block one byte at a time |
// update the CRC on the data block one byte at a time |
u_int16_t update_crc_16_block(u_int16_t crc, char *data_block_ptr, int data_block_size) |
uint16_t update_crc_16_block(uint16_t crc, char *data_block_ptr, int data_block_size) |
{ |
{ |
register int i; |
register int i; |
for (i=data_block_size; i>0; i--) |
for (i=data_block_size; i>0; i--) |
Line 49 void crc16_calc (char *data,
|
Line 49 void crc16_calc (char *data,
|
int size, |
int size, |
char *crc) |
char *crc) |
{ |
{ |
u_int16_t c; |
uint16_t c; |
c = CRC_INIT_16; |
c = CRC_INIT_16; |
while (--size >= 0) { |
while (--size >= 0) { |
c = update_crc_16 (c,*data++); |
c = update_crc_16 (c,*data++); |