nux-1.14.0
CRC32.h
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef CRC32_H
00024 #define CRC32_H
00025 
00026 namespace nux
00027 {
00028 // http://www.networkdls.com/Software.Asp?Review=22
00029 
00030 // This is the official polynomial used by CRC-32 in PKZip, WinZip and Ethernet.
00031 
00032 // There are multiple 16-bit CRC polynomials in common use, but this is *the* standard CRC-32 polynomial,
00033 // first popularized by Ethernet. It is used by PKZip, WinZip and Ethernet.
00034 // x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
00035 
00036 // #define CRC32_POLYNOMIAL_LE 0xedb88320  // little Endian
00037 #define CRC32_POLYNOMIAL 0x04c11db7     // big Endian
00038 
00039 // How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. We use CRC_8_BITS
00040 // CRC_xx_BITS must be a power of 2 between 1 and 8. We use CRC_8_BITS.
00041 #define CRC32BUFSZ 1024 // 4 << 8 = 1024
00042 
00043   class CRC32
00044   {
00045   public:
00046     CRC32();
00047     t_u32 FileCRC (const char *sFileName);
00048     t_u32 FullCRC (const char *sData, t_u32 ulLength);
00049     void PartialCRC (t_u32 *ulInCRC, const char *sData, t_u32 ulLength);
00050 
00051   private:
00052     void Initialize (void);
00053     t_u32 Reflect (t_u32 ulReflect, char cChar);
00054     t_u32 CRCTable[256]; // CRC lookup table array.
00055   };
00056 
00057 }
00058 #endif // CRC32_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends