Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
apps/elftosb/common/crc.h
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 
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 
37  void updateByte(uint8_t b) { m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc); }
38  uint8_t getCrcByte(unsigned i) const { return ((uint8_t *)&(m_crc))[i]; }
39 private:
40  void reset()
41  {
42  m_crc = CRC32_NEGL;
43  m_count = 0;
44  }
45 
46  static const uint32_t m_tab[256];
47  uint32_t m_crc;
48  unsigned m_count;
49 };
50 
51 #endif // _crc_h_
CRC Checksum Calculation.
Definition: apps/elftosb/common/crc.h:23