2018-04-24 19:56:45 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Workaround GmbH.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-06-26 00:25:56 +08:00
|
|
|
#include <sys/crc.h>
|
2018-04-24 19:56:45 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t crc32_ieee(const uint8_t *data, size_t len)
|
2018-04-24 19:56:45 +08:00
|
|
|
{
|
|
|
|
return crc32_ieee_update(0x0, data, len);
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t crc32_ieee_update(uint32_t crc, const uint8_t *data, size_t len)
|
2018-04-24 19:56:45 +08:00
|
|
|
{
|
|
|
|
crc = ~crc;
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
crc = crc ^ data[i];
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
for (uint8_t j = 0; j < 8; j++) {
|
2018-04-24 19:56:45 +08:00
|
|
|
crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (~crc);
|
|
|
|
}
|