File: crc.c

package info (click to toggle)
p3nfs 5.3-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 596 kB
  • ctags: 825
  • sloc: ansic: 7,434; makefile: 126; sh: 40
file content (46 lines) | stat: -rw-r--r-- 545 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int
docrc16_1(crc, c)
  int crc;
  unsigned char c;
{
  int acc, i;

  acc = crc;
  acc ^= c << 8;
  for(i = 0; i < 8; i++)
    if(acc & 0x8000)
      {
	acc <<= 1;
	acc ^= 0x1021;
      }
    else
      {
	acc <<= 1;
      }
  return acc & 0xffff;
}

int
docrc16(ptr, len)
  unsigned char *ptr;
  int len;
{
  int acc, i;

  acc = 0;
  while(len--)
    {
      acc ^= *ptr++ << 8;
      for(i = 0; i < 8; i++)
        if(acc & 0x8000)
	  {
	    acc <<= 1;
	    acc ^= 0x1021;
	  }
	else
	  {
	    acc <<= 1;
	  }
    }
  return acc & 0xffff;
}