CHROMA
crc48.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief 48-bit CRC
4  */
5 
6 #ifndef __crc48_h__
7 #define __crc48_h__
8 
9 namespace CRC48
10 {
11 
12 /************************************************************************
13  48 bit CRC routines.
14 
15  These routines can be used to calculate a 48 bit CRC over an array of
16  characters. The calculated value can be used to generate data frames
17  that have correct CRC when received by systems which support either
18  CCITT-16 CRCs or CCITT-32 bit CRCs.
19 
20  These routines use a structure to hold the 48 bit CRC. The structure
21  consists of an array of integers (or longs). The number of elements
22  required to hold the CRC is dependent on the base size of an integer
23  in the target system. The MACROs CRCBASE8, CRCBASE16, CRCBASE32 and
24  CRCBASE64 are used to indicate the appropriate size. Any base can be
25  used that is less than or equal to the size of integers (or longs),
26  however, the CRC calculations will be less efficient.
27 
28  Author: Gary Mussar mussar@bnr.ca
29  Dec 1, 1991 These routines are public domain and may be freely use
30  in both academic projects and commercial products.
31 
32  The author would appreciate receiving any improvements
33  (or bug fixes)
34 **************************************************************************/
35 
36 /* Use 8 bit base */
37 #define CRCBASE8
38 
39 /*
40  Make sure only one CRCBASE size is selected
41 */
42 #ifdef CRCBASE8
43 # undef CRCBASE16
44 # undef CRCBASE32
45 # undef CRCBASE64
46 #else
47 # ifdef CRCBASE16
48 # undef CRCBASE32
49 # undef CRCBASE64
50 # else
51 # ifdef CRCBASE32
52 # undef CRCBASE64
53 # else
54 # ifndef CRCBASE64
55 # define CRCBASE32
56 # endif
57 # endif
58 # endif
59 #endif
60 
61 /*
62  Assign appropriate variable types and the number of elements of the
63  array to hold the CRC. The variable type MUST be unsigned.
64 */
65 #ifdef CRCBASE8
66 # define CRCBASETYPE unsigned char
67 # define CRCARRAYSIZE 6
68 #endif
69 #ifdef CRCBASE16
70 # define CRCBASETYPE unsigned int
71 # define CRCARRAYSIZE 3
72 #endif
73 #ifdef CRCBASE32
74 # define CRCBASETYPE unsigned long
75 # define CRCARRAYSIZE 2
76 #endif
77 #ifdef CRCBASE64
78 # define CRCBASETYPE unsigned long
79 # define CRCARRAYSIZE 1
80 #endif
81 
82 /*
83  Define the CRC structure and typedef for easier use.
84 */
85 struct CRC48_t
86 {
88 };
89 
90 /*
91  Reset the CRC at the beginning of a frame.
92 */
93 void initCRC48(CRC48_t& acc);
94 
95 /*
96  Compute the CRC over an array of bytes. This routine can be called
97  multiple times as long as the data is transmitted in the same order.
98 */
99 void calcCRC48(CRC48_t& acc, const void *dataPtr, int count);
100 
101 /*
102  Retrieve part of all of the 48 bit CRC. For machines supporting 32 bit
103  CRCs, only the first two bytes or the 48 bit CRC are required. For
104  machines support 16 bit CRCs, the first 4 bytes are required. The data
105  is retrieved in the order required for transmission (ie. byte[0] is
106  transmitted first, followed by byte[1], etc.).
107 */
108 void getCRC48(const CRC48_t& acc, void *dataPtr, int count);
109 
110 } // namespace CRC48
111 
112 #endif
#define CRCBASETYPE
Definition: crc48.h:66
#define CRCARRAYSIZE
Definition: crc48.h:67
Definition: crc48.cc:8
void getCRC48(const CRC48_t &acc, void *dataPtr, int count)
Definition: crc48.cc:132
void initCRC48(CRC48_t &acc)
Definition: crc48.cc:87
void calcCRC48(CRC48_t &acc, const void *dataPtr, int count)
Definition: crc48.cc:94
int count
Definition: octave.h:14
CRCBASETYPE crc[CRCARRAYSIZE]
Definition: crc48.h:87