|
|
1.1 root 1: /* CRC16.C */
2:
3: /* 16-bit CRC routines */
4:
5: #include "smblib.h"
6:
7: /****************************************************************************/
8: /* Updates 16-bit "rcrc" with character 'ch' */
9: /****************************************************************************/
10: void ucrc16(uchar ch, ushort *rcrc) {
11: ushort i, cy;
12: uchar nch=ch;
13:
14: for (i=0; i<8; i++) {
15: cy=*rcrc & 0x8000;
16: *rcrc<<=1;
17: if (nch & 0x80) *rcrc |= 1;
18: nch<<=1;
19: if (cy) *rcrc ^= 0x1021; }
20: }
21:
22: /****************************************************************************/
23: /* Returns 16-crc of string (not counting terminating NULL) */
24: /****************************************************************************/
25: ushort crc16(char *str)
26: {
27: int i=0;
28: ushort crc=0;
29:
30: ucrc16(0,&crc);
31: while(str[i])
32: ucrc16(str[i++],&crc);
33: ucrc16(0,&crc);
34: ucrc16(0,&crc);
35: return(crc);
36: }
37:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.