CRC-8 Checksum Calculation

Medium C Protocols Asked at Bosch
Solve this problem

Implement a CRC-8 checksum over a byte buffer using the SAE J1850 polynomial 0x1D. Automotive and sensor buses use this to catch single-bit corruption on short frames.

Constraints

  • Signature: `uint8_t crc8(const uint8_t *data, size_t len)`.
  • Polynomial 0x1D, initial value 0xFF, no final XOR, MSB-first.
  • Must handle len == 0 by returning the initial value.
  • Bitwise implementation only - no 256-byte table.
  • Must not read past data[len - 1].
Starter codeC
1#include <stdint.h>2#include <stddef.h>3 4uint8_t crc8(const uint8_t *data, size_t len) {5    // TODO: compute CRC-8 with polynomial 0x1D6    return 0;7}