zephyr/lib/os/crc32_sw.c
Anas Nashif db92e5c66e lib: flatten all loose components into one lib
lib/ was starting to get messy and inconsitent. Files being either
dumped in the root or in sub-directories without a clear plan.
Move all library components into one single folder and call it 'os'.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00

27 lines
450 B
C

/*
* Copyright (c) 2018 Workaround GmbH.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <crc.h>
u32_t crc32_ieee(const u8_t *data, size_t len)
{
return crc32_ieee_update(0x0, data, len);
}
u32_t crc32_ieee_update(u32_t crc, const u8_t *data, size_t len)
{
crc = ~crc;
for (size_t i = 0; i < len; i++) {
crc = crc ^ data[i];
for (u8_t j = 0; j < 8; j++) {
crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1));
}
}
return (~crc);
}