zephyr/lib/os/crc32_sw.c
Abramo Bagnara ada9ca4c93 coding guidelines: comply with MISRA C:2012 Rule 7.2
MISRA C:2012 Rule 7.2 (A `u' or `U' suffix shall be applied to all
integer constants that are represented in an unsigned type)

Added missing `U' suffixes in constants that are involved in the
analyzed build, plus a few more not to introduce inconsistencies
with respect to nearby constants that are either unused in the
build (but implicitly unsigned) or are used and are immediately
converted to unsigned.

Signed-off-by: Abramo Bagnara <abramo.bagnara@bugseng.com>
2022-06-14 13:36:14 -04:00

34 lines
821 B
C

/*
* Copyright (c) 2018 Workaround GmbH.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/crc.h>
uint32_t crc32_ieee(const uint8_t *data, size_t len)
{
return crc32_ieee_update(0x0, data, len);
}
uint32_t crc32_ieee_update(uint32_t crc, const uint8_t *data, size_t len)
{
/* crc table generated from polynomial 0xedb88320 */
static const uint32_t table[16] = {
0x00000000U, 0x1db71064U, 0x3b6e20c8U, 0x26d930acU,
0x76dc4190U, 0x6b6b51f4U, 0x4db26158U, 0x5005713cU,
0xedb88320U, 0xf00f9344U, 0xd6d6a3e8U, 0xcb61b38cU,
0x9b64c2b0U, 0x86d3d2d4U, 0xa00ae278U, 0xbdbdf21cU,
};
crc = ~crc;
for (size_t i = 0; i < len; i++) {
uint8_t byte = data[i];
crc = (crc >> 4) ^ table[(crc ^ byte) & 0x0f];
crc = (crc >> 4) ^ table[(crc ^ ((uint32_t)byte >> 4)) & 0x0f];
}
return (~crc);
}