summaryrefslogtreecommitdiffstats
path: root/src/lib/crc_byte.c
diff options
context:
space:
mode:
authorPatrick Rudolph <siro@das-labor.org>2019-12-15 18:03:36 +0100
committerPatrick Rudolph <siro@das-labor.org>2020-01-07 08:38:58 +0000
commitcc0b6f18cdcce54a92961573b653e5f947d40651 (patch)
tree8128870a1d9b921ea1885ef7ec08dfdcbcb7b5a5 /src/lib/crc_byte.c
parent389c8279432a4e213391ed21ef25707090fde7ef (diff)
downloadcoreboot-cc0b6f18cdcce54a92961573b653e5f947d40651.tar.gz
coreboot-cc0b6f18cdcce54a92961573b653e5f947d40651.tar.bz2
coreboot-cc0b6f18cdcce54a92961573b653e5f947d40651.zip
lib/crc_byte: Add CRC32 implementation
* Add CRC32 using polynomial 0x04C11DB7 + Add macro to caculate CRC of a buffer Change-Id: If98e4e12bb53a6e5123e94e8cdffde1eb3bc4b4b Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/37753 Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib/crc_byte.c')
-rw-r--r--src/lib/crc_byte.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/crc_byte.c b/src/lib/crc_byte.c
index 0ac006363a34..c04449d13f76 100644
--- a/src/lib/crc_byte.c
+++ b/src/lib/crc_byte.c
@@ -36,3 +36,17 @@ uint16_t crc16_byte(uint16_t prev_crc, uint8_t data)
prev_crc ^= ((prev_crc & 0xff) << 4) << 1;
return prev_crc;
}
+
+uint32_t crc32_byte(uint32_t prev_crc, uint8_t data)
+{
+ prev_crc ^= (uint32_t)data << 24;
+
+ for (int i = 0; i < 8; i++) {
+ if ((prev_crc & 0x80000000UL) != 0)
+ prev_crc = ((prev_crc << 1) ^ 0x04C11DB7UL);
+ else
+ prev_crc <<= 1;
+ }
+
+ return prev_crc;
+}