File:
[ELWIX - Embedded LightWeight unIX -] /
libelwix /
inc /
elwix /
acrc.h
Revision
1.7:
download - view:
text,
annotated -
select for diffs -
revision graph
Mon Dec 30 18:11:16 2019 UTC (4 years, 7 months ago) by
misho
Branches:
MAIN
CVS tags:
elwix6_1,
elwix5_9,
elwix5_8,
elwix5_7,
elwix5_6,
elwix5_5,
elwix5_4,
elwix5_3,
elwix5_2,
elwix5_12,
elwix5_11,
elwix5_10,
elwix5_1,
elwix5_0,
elwix4_26,
elwix4_25,
elwix4_24,
elwix4_23,
HEAD,
ELWIX6_0,
ELWIX5_9,
ELWIX5_8,
ELWIX5_7,
ELWIX5_6,
ELWIX5_5,
ELWIX5_4,
ELWIX5_3,
ELWIX5_2,
ELWIX5_11,
ELWIX5_10,
ELWIX5_1,
ELWIX5_0,
ELWIX4_26,
ELWIX4_25,
ELWIX4_24,
ELWIX4_23,
ELWIX4_22
ver 4.22
1: /*************************************************************************
2: * (C) 2013 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
3: * by Michael Pounov <misho@elwix.org>
4: *
5: * $Author: misho $
6: * $Id: acrc.h,v 1.7 2019/12/30 18:11:16 misho Exp $
7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
15: Copyright 2004 - 2019
16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __ACRC_H
47: #define __ACRC_H
48:
49:
50: #define REVOPTS_REVERTBYTE 1
51: #define REVOPTS_REVERTCRC 2
52:
53:
54: struct tagCRCPoly {
55: u_char poly_bits;
56: u_int poly_num;
57: char poly_name[19];
58: }; /* size 24bytes */
59: typedef struct tagCRCPoly crcPoly_t;
60:
61:
62: /*
63: * crcReflect() - Reflect all bits of number
64: *
65: * @crcNum = Number for reflection
66: * @crcBits = Number width bits
67: * return: reflecting number
68: */
69: unsigned int crcReflect(unsigned int crcNum, unsigned char crcBits);
70: /*
71: * crcCalc() - Generic CRC calculation function for many sub variants of CRC algorithms
72: *
73: * @psBuf = Data for calculation
74: * @bufLen = Length of data
75: * @crcBits = CRC algorithm bits (1, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 24, 30, 32)
76: * @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC)
77: * @initCRC = Initial CRC value
78: * @xorCRC = Last xor CRC value
79: * return: CRC checksum
80: */
81: unsigned int crcCalc(unsigned char * __restrict psBuf, unsigned int bufLen,
82: unsigned char crcBits, unsigned char RevOpts,
83: unsigned int initCRC, unsigned int xorCRC);
84:
85: /*
86: * crc16() - Checksum calculation in X/Y modem communication
87: *
88: * @buf = Data for calculation
89: * @bufLen = Length of data
90: * return: Checksum
91: */
92: unsigned short crc16(unsigned char * __restrict buf, int bufLen);
93: /*
94: * crc16_ext() - Checksum ver.2 calculation in X/Y modem communication
95: *
96: * @buf = Data for calculation
97: * @bufLen = Length of data
98: * return: Checksum
99: */
100: unsigned short crc16_ext(unsigned char * __restrict buf, int bufLen);
101: /*
102: * crcIP() - Checksum in IP communication
103: *
104: * @buf = Data for calculation
105: * @bufLen = Length of data
106: * return: Checksum
107: */
108: unsigned short crcIP(unsigned char * __restrict buf, int bufLen);
109: /*
110: * crcTCP() - Checksum for TCP v4 communication
111: *
112: * @buf = Data for calculation
113: * @bufLen = Length of data
114: * @th = TCP header
115: * return: Checksum
116: */
117: unsigned short crcTCP(struct in_addr src, struct in_addr dst,
118: unsigned char * __restrict th);
119: /*
120: * crcUDP() - Checksum for UDP v4 communication
121: *
122: * @buf = Data for calculation
123: * @bufLen = Length of data
124: * @uh = UDP header
125: * return: Checksum
126: */
127: unsigned short crcUDP(struct in_addr src, struct in_addr dst,
128: unsigned char * __restrict uh);
129:
130: /*
131: * crcFletcher16() - Fletcher-16 Checksum computing
132: *
133: * @nBuf = Data for calculation
134: * @bufLen = Length of data
135: * return: Checksum
136: */
137: unsigned short crcFletcher16(unsigned short * __restrict nBuf, int bufLen);
138: /*
139: * crcFletcher() - Fletcher-32 Checksum computing
140: *
141: * @nBuf = Data for calculation
142: * @bufLen = Length of data
143: * return: Checksum
144: */
145: unsigned int crcFletcher(unsigned short * __restrict nBuf, int bufLen);
146: /*
147: * crcAdler() - crcAdler-32 Checksum computing
148: *
149: * @psBuf = Data for calculation
150: * @bufLen = Length of data
151: * return: Checksum
152: */
153: unsigned int crcAdler(unsigned char * __restrict psBuf, int bufLen);
154:
155: /*
156: * crcEther() - Checksum in Ethernet communication
157: *
158: * @psBuf = Data for calculation
159: * @bufLen = Length of data
160: * return: Checksum
161: */
162: #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF)
163:
164: /*
165: * crc_32() - CRC32 calculation from table
166: *
167: * @crc = Initial crc value
168: * @buf = Data for calculation
169: * @len = Length of data
170: * return: calculated CRC32
171: */
172: unsigned int crc_32(unsigned int crc, const unsigned char * __restrict buf, unsigned int len);
173:
174: /*
175: * crcPelco() - Calculate Pelco D/P CRC
176: *
177: * @ver = Pelco protocol version (Dd | Pp)
178: * @pkt = Packet for calculate crc
179: * return: crc for packet, if is 0 check and crc_GetErrno() == 1
180: Pelco protocol not supported
181: */
182: unsigned char crcPelco(unsigned char ver, unsigned char *pkt);
183:
184:
185: /*
186: * hash_varchar() - Compute index hash by variable length string
187: *
188: * @csStr = Input data buffer
189: * @nStrLen = Length of data buffer
190: * @nVer = Version of algorythm; 0 - original, 1 - AITNET variant
191: * return: Hash value
192: */
193: unsigned int hash_varchar(const char *csStr, int nStrLen, int nVer);
194: /*
195: * hash_bernstein() - Compute index hash by Bernstein
196: *
197: * @csStr = Input data buffer
198: * @nStrLen = Length of data buffer
199: * @nVer = Version of algorythm; 0 - Bernstein, 1 - DJBX33A variant
200: * return: Hash value
201: */
202: unsigned int hash_bernstein(const char *csStr, int nStrLen, int nVer);
203: /*
204: * hash_jenkins() - Compute index hash by Jenkins (one-at-a-time)
205: *
206: * @csStr = Input data buffer
207: * @nStrLen = Length of data buffer
208: * return: Hash value
209: */
210: unsigned int hash_jenkins(const char *csStr, int nStrLen);
211: /*
212: * hash_jenkins32() - Fast Jenkins hash function
213: *
214: * @buf = Input buffer
215: * @len = Length of buffer
216: * @prevhash = Previous hash, if participate in continuing hash
217: * return: Hash value
218: */
219: unsigned int hash_jenkins32(const unsigned int *buf, int len, unsigned int prevhash);
220: /*
221: * hash_reddragon() - Compute index hash by Red Dragon
222: *
223: * @csStr = Input data buffer
224: * @nStrLen = Length of data buffer
225: * return: Hash value
226: */
227: unsigned int hash_reddragon(const char *csStr, int nStrLen);
228: /*
229: * hash_fnv1() - Compute index hash by FNV-1
230: *
231: * @csStr = Input data buffer
232: * @nStrLen = Length of data buffer
233: * @nVer = Version of algorythm; 0 - FNV-1, 1 - FNV-1a (best avalanche)
234: * return: Hash value
235: */
236: unsigned int hash_fnv1(const char *csStr, int nStrLen, int nVer);
237:
238: /*
239: * hash_fnv() - Compute index hash by FNV-1a
240: *
241: * @csStr = Input data buffer
242: * @nStrLen = Length of data buffer
243: * return: Hash value
244: */
245: #define hash_fnv(str, len) hash_fnv1((str), (len), 1)
246:
247:
248: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>