MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / generic_crc

Function generic_crc

lib/core/crc.cc:18–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18uint64_t generic_crc(const struct crcspec& spec, const Bytes& bytes)
19{
20 uint64_t crc = spec.init;
21 uint64_t top = 1LL << (spec.width - 1);
22 uint64_t mask = (top << 1) - 1;
23
24 for (uint8_t b : bytes)
25 {
26 if (spec.refin)
27 b = reflect(b);
28
29 for (uint8_t i = 0x80; i != 0; i >>= 1)
30 {
31 uint64_t bit = crc & top;
32 crc <<= 1;
33 if (b & i)
34 bit ^= top;
35 if (bit)
36 crc ^= spec.poly;
37 }
38 }
39
40 if (spec.refout)
41 crc = reflect(crc, spec.width);
42 crc ^= spec.xorout;
43 return crc & mask;
44}
45
46uint16_t sumBytes(const Bytes& bytes)
47{

Callers

nothing calls this directly

Calls 1

reflectFunction · 0.85

Tested by

no test coverage detected