Annotation of multiplexer/crc32.c, revision 1.2

1.1       oskar       1: /*
                      2:  * cyclic redundancy check 32 bit
                      3:  * Copyright (C) 1999 Christian Wolff, 2004 Oskar Schirmer
                      4:  * for Convergence Integrated Media GmbH (http://www.convergence.de)
                      5:  *
                      6:  * This program is free software; you can redistribute it and/or modify
                      7:  * it under the terms of the GNU General Public License as published by
                      8:  * the Free Software Foundation; either version 2 of the License, or
                      9:  * (at your option) any later version.
                     10:  *
                     11:  * This program is distributed in the hope that it will be useful,
                     12:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14:  * GNU General Public License for more details.
                     15:  *
                     16:  * You should have received a copy of the GNU General Public License
                     17:  * along with this program; if not, write to the Free Software
                     18:  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     19:  */
                     20: 
1.2     ! oskar      21: #include <stdint.h>
1.1       oskar      22: #include "crc32.h"
                     23: 
1.2     ! oskar      24: uint32_t crc_32_table[256];
1.1       oskar      25: 
                     26: // generate the tables of CRC-32 remainders for all possible bytes
                     27: void gen_crc32_table() { 
                     28:   register int i,j;  
1.2     ! oskar      29:   register uint32_t crc32;
1.1       oskar      30:   for (i=0; i<256; i++) {
1.2     ! oskar      31:     crc32=(uint32_t)i << 24;
1.1       oskar      32:     for (j=0; j<8; j++) {
                     33:       crc32 = (crc32 << 1) ^ ((crc32 & (1<<31)) ? POLYNOMIAL_32_MSBF : 0);
                     34:     }
                     35:     crc_32_table[i]=crc32; 
                     36:   }
                     37: }
                     38: 
                     39: // update the CRC on the data block one byte at a time
1.2     ! oskar      40: uint32_t update_crc_32_block(uint32_t crc, char *data_block_ptr, int data_block_size)
1.1       oskar      41: {
                     42:   register int i;
                     43:   for (i=data_block_size; i>0; i--)
                     44:     crc=update_crc_32(crc, *data_block_ptr++);
                     45:   return crc;
                     46: }
                     47: 
                     48: void crc32_calc (char *data,
                     49:     int size,
                     50:     char *crc)
                     51: {
1.2     ! oskar      52:   uint32_t c;
1.1       oskar      53:   c = CRC_INIT_32;
                     54:   while (--size >= 0) {
                     55:     c = update_crc_32 (c,*data++);
                     56:   }
                     57:   crc[3] = c; c >>= 8;
                     58:   crc[2] = c; c >>= 8;
                     59:   crc[1] = c; c >>= 8;
                     60:   crc[0] = c;
                     61: }
                     62: 

LinuxTV legacy CVS <linuxtv.org/cvs>