/[dynamips]/trunk/crc.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/crc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 1203 byte(s)
make working copy

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * CRC functions.
6 */
7
8 #ifndef __CRC_H__
9 #define __CRC_H__
10
11 #include <sys/types.h>
12 #include "utils.h"
13
14 extern m_uint16_t crc12_array[],crc16_array[];
15 extern m_uint32_t crc32_array[];
16
17 /* Compute a CRC-12 hash on a 32-bit integer */
18 static forced_inline m_uint32_t crc12_hash_u32(m_uint32_t val)
19 {
20 register m_uint32_t crc=0;
21 register int i;
22
23 for(i=0;i<4;i++) {
24 crc = (crc >> 8) ^ crc12_array[(crc^val) & 0xff];
25 val >>= 8;
26 }
27
28 return(crc);
29 }
30
31 /* Compute a CRC-16 hash on a 32-bit integer */
32 static forced_inline m_uint32_t crc16_hash_u32(m_uint32_t val)
33 {
34 register m_uint32_t crc=0;
35 register int i;
36
37 for(i=0;i<4;i++) {
38 crc = (crc >> 8) ^ crc16_array[(crc^val) & 0xff];
39 val >>= 8;
40 }
41
42 return(crc);
43 }
44
45 /* Compute a CRC-32 on the specified block */
46 static forced_inline
47 m_uint32_t crc32_compute(m_uint32_t crc_accum,m_uint8_t *ptr,int len)
48 {
49 unsigned long c = crc_accum;
50 int n;
51
52 for (n = 0; n < len; n++) {
53 c = crc32_array[(c ^ ptr[n]) & 0xff] ^ (c >> 8);
54 }
55
56 return(~c);
57 }
58
59
60 /* Initialize CRC algorithms */
61 void crc_init(void);
62
63 #endif

  ViewVC Help
Powered by ViewVC 1.1.26