1#ifndef CRC_H
2#define CRC_H
3
4/*
5 * Everything in here is taken from PGP
6 */
7
8#define CRCBITS 24      /* may be 16, 24, or 32 */
9#define CRCBYTES 3      /* may be 2, 3, or 4 */
10
11#ifdef __alpha
12#define crcword unsigned int		/* if CRCBITS is 24 or 32 */
13#else
14#define crcword unsigned long		/* if CRCBITS is 24 or 32 */
15#endif
16
17#define CCITTCRC  0x1021   /* CCITT's 16-bit CRC generator polynomial */
18#define PRZCRC  0x864cfbL  /* PRZ's   24-bit CRC generator polynomial */
19#define CRCINIT 0xB704CEL  /* Init value for CRC accumulator          */
20
21#if (CRCBITS == 16) || (CRCBITS == 32)
22#define maskcrc(crc) ((crcword) (crc))     /* if CRCBITS is 16 or 32 */
23#else
24#define maskcrc(crc) ((crc) & 0xffffffL)   /* if CRCBITS is 24 */
25#endif
26
27
28#define CRCHIBIT  ((crcword) (1L<<(CRCBITS-1))) /* 0x8000 if CRCBITS is 16 */
29#define CRCSHIFTS (CRCBITS-8)
30
31/*      Notes on making a good 24-bit CRC--
32	The primitive irreducible polynomial of degree 23 over GF(2),
33	040435651 (octal), comes from Appendix C of "Error Correcting Codes,
34	2nd edition" by Peterson and Weldon, page 490.  This polynomial was
35	chosen for its uniform density of ones and zeros, which has better
36	error detection properties than polynomials with a minimal number of
37	nonzero terms.  Multiplying this primitive degree-23 polynomial by
38	the polynomial x+1 yields the additional property of detecting any
39	odd number of bits in error, which means it adds parity.  This
40	approach was recommended by Neal Glover.
41
42	To multiply the polynomial 040435651 by x+1, shift it left 1 bit and
43	bitwise add (xor) the unshifted version back in.  Dropping the unused
44	upper bit (bit 24) produces a CRC-24 generator bitmask of 041446373
45	octal, or 0x864cfb hex.
46
47	You can detect spurious leading zeros or framing errors in the
48	message by initializing the CRC accumulator to some agreed-upon
49	nonzero "random-like" value, but this is a bit nonstandard.
50*/
51
52#endif /* CRC */
53