source: liacs/alg/solitaire/crc/lib_crc.c@ 93

Last change on this file since 93 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[2]1#include "lib_crc.h"
2#define P_32 0xEDB88320L
3
4static int crc_tab32_init = FALSE;
5
6static unsigned long crc_tab32[256];
7
8
9static void init_crc32_tab( void );
10
11
12 /*******************************************************************\
13 * *
14 * unsigned long update_crc_32( unsigned long crc, char c ); *
15 * *
16 * The function update_crc_32 calculates a new CRC-32 value *
17 * based on the previous value of the CRC and the next byte *
18 * of the data to be checked. *
19 * *
20 \*******************************************************************/
21
22unsigned long update_crc_32( unsigned long crc, char c ) {
23
24 unsigned long tmp, long_c;
25
26 long_c = 0x000000ffL & (unsigned long) c;
27
28 if ( ! crc_tab32_init ) init_crc32_tab();
29
30 tmp = crc ^ long_c;
31 crc = (crc >> 8) ^ crc_tab32[ tmp & 0xff ];
32
33 return crc;
34
35} /* update_crc_32 */
36
37
38 /*******************************************************************\
39 * *
40 * static void init_crc32_tab( void ); *
41 * *
42 * The function init_crc32_tab() is used to fill the array *
43 * for calculation of the CRC-32 with values. *
44 * *
45 \*******************************************************************/
46
47static void init_crc32_tab( void ) {
48
49 int i, j;
50 unsigned long crc;
51
52 for (i=0; i<256; i++) {
53
54 crc = (unsigned long) i;
55
56 for (j=0; j<8; j++) {
57
58 if ( crc & 0x00000001L ) crc = ( crc >> 1 ) ^ P_32;
59 else crc = crc >> 1;
60 }
61
62 crc_tab32[i] = crc;
63 }
64
65 crc_tab32_init = TRUE;
66
67} /* init_crc32_tab */
Note: See TracBrowser for help on using the repository browser.