1 /* 2 * File: crc.h 3 * 4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. 5 * See included license file for license details. 6 */ 7 #if !defined(_crc_h_) 8 #define CRYPTOPP_CRC32_H 9 10 #include "stdafx.h" 11 12 const uint32_t CRC32_NEGL = 0xffffffffL; 13 14 #ifdef __LITTLE_ENDIAN__ 15 #define CRC32_INDEX(c) (c & 0xff) 16 #define CRC32_SHIFTED(c) (c >> 8) 17 #else 18 #define CRC32_INDEX(c) (c >> 24) 19 #define CRC32_SHIFTED(c) (c << 8) 20 #endif 21 22 //! CRC Checksum Calculation 23 class CRC32 24 { 25 public: 26 enum 27 { 28 DIGESTSIZE = 4 29 }; 30 31 CRC32(); 32 33 void update(const uint8_t * input, unsigned length); 34 35 void truncatedFinal(uint8_t * hash, unsigned size); 36 updateByte(uint8_t b)37 void updateByte(uint8_t b) { m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc); } getCrcByte(unsigned i)38 uint8_t getCrcByte(unsigned i) const { return ((uint8_t *)&(m_crc))[i]; } 39 40 private: reset()41 void reset() { m_crc = CRC32_NEGL; m_count = 0; } 42 43 static const uint32_t m_tab[256]; 44 uint32_t m_crc; 45 unsigned m_count; 46 }; 47 48 #endif // _crc_h_ 49