Numworks Epsilon  1.4.1
Graphing Calculator Operating System
crc32.cpp
Go to the documentation of this file.
1 #include <ion.h>
2 
3 constexpr uint32_t polynomial = 0x04C11DB7;
4 
5 static uint32_t crc32(uint32_t crc, uint8_t data) {
6  crc ^= data << 24;
7  for (int i=8; i--;) {
8  crc = crc & 0x80000000 ? ((crc<<1)^polynomial) : (crc << 1);
9  }
10  return crc;
11 }
12 
13 uint32_t Ion::crc32(const uint32_t * data, size_t length) {
14  uint32_t crc = 0xFFFFFFFF;
15  for (size_t i=0; i<length; i++) {
16  // FIXME: Assumes little-endian byte order!
17  crc = ::crc32(crc, (uint8_t)((data[i] >> 24) & 0xFF));
18  crc = ::crc32(crc, (uint8_t)((data[i] >> 16) & 0xFF));
19  crc = ::crc32(crc, (uint8_t)((data[i] >> 8) & 0xFF));
20  crc = ::crc32(crc, (uint8_t)(data[i] & 0xFF));
21  }
22  return crc;
23 }
def data
Definition: i18n.py:176
unsigned char uint8_t
Definition: stdint.h:4
unsigned int uint32_t
Definition: stdint.h:6
constexpr uint32_t polynomial
Definition: crc32.cpp:3
uint32_t crc32(const uint32_t *data, size_t length)
Definition: device.cpp:37