00001 /* 00002 * Little-endian CRC32 implementation. 00003 * 00004 * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of the 00009 * License, or any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 FILE_LICENCE ( GPL2_OR_LATER ); 00022 00023 #include <gpxe/crc32.h> 00024 00025 #define CRCPOLY 0xedb88320 00026 00027 /** 00028 * Calculate 32-bit little-endian CRC checksum 00029 * 00030 * @v seed Initial value 00031 * @v data Data to checksum 00032 * @v len Length of data 00033 * 00034 * Usually @a seed is initially zero or all one bits, depending on the 00035 * protocol. To continue a CRC checksum over multiple calls, pass the 00036 * return value from one call as the @a seed parameter to the next. 00037 */ 00038 u32 crc32_le ( u32 seed, const void *data, size_t len ) 00039 { 00040 u32 crc = seed; 00041 const u8 *src = data; 00042 u32 mult; 00043 int i; 00044 00045 while ( len-- ) { 00046 crc ^= *src++; 00047 for ( i = 0; i < 8; i++ ) { 00048 mult = ( crc & 1 ) ? CRCPOLY : 0; 00049 crc = ( crc >> 1 ) ^ mult; 00050 } 00051 } 00052 00053 return crc; 00054 }
1.5.7.1