1 /* $Id$
2    A CRC-16 CCITT checksum module
3 
4    Written 1999 by Tobias Ernst
5 
6    This file is part of NLTOOLS, the nodelist processor of the Husky fidonet
7    software project.
8 */
9 
10 #include <stdio.h>
11 #include <errno.h>
12 #include "crc16.h"
13 #include "ccitttab.h"
14 
15 #define unused(x) (x)
16 
crc16_init(unsigned short * crcptr)17 void crc16_init( unsigned short *crcptr )
18 {
19   *crcptr = 0x0UL;
20 }
21 
crc16_process(unsigned short * crcptr,const unsigned char * buffer,size_t length)22 void crc16_process( unsigned short *crcptr, const unsigned char *buffer, size_t length )
23 {
24   const unsigned char *ptr = buffer;
25   size_t ctr;
26 
27   for( ctr = 0; ctr < length; ctr++, ptr++ )
28   {
29     *crcptr = ( ( ( *crcptr ) << 8 ) ^ ccitt_table[( ( *crcptr ) >> 8 ) ^ ( *ptr )] ) & 0xFFFF;
30   }
31 }
32 
crc16_finalize(unsigned short * crcptr)33 void crc16_finalize( unsigned short *crcptr )
34 {
35   unused( crcptr );
36 }
37