summaryrefslogtreecommitdiff
path: root/src/include/crc_byte.h
diff options
context:
space:
mode:
authorXiang Wang <merle@hardenedlinux.org>2019-11-05 12:00:39 +0800
committerPatrick Georgi <pgeorgi@google.com>2019-11-06 13:58:53 +0000
commit4e39c824e07f192c35afa88dcceee863528dbd32 (patch)
tree2cc0c8b444b6ed518077526d65c7b17d6810ba95 /src/include/crc_byte.h
parenta0218958a046e102daabb297c2e9eb83cb244b1c (diff)
downloadcoreboot-4e39c824e07f192c35afa88dcceee863528dbd32.tar.xz
lib: add calculate crc byte by byte
Change-Id: I5cab1f90452b08a464ad7a2d7e75d97187452992 Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/36624 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/include/crc_byte.h')
-rw-r--r--src/include/crc_byte.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/include/crc_byte.h b/src/include/crc_byte.h
new file mode 100644
index 0000000000..9315277d23
--- /dev/null
+++ b/src/include/crc_byte.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2019 HardenedLinux
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef CRC_BYTE_H
+#define CRC_BYTE_H
+
+#include <stdint.h>
+
+/* This function is used to calculate crc7 byte by byte, with polynomial
+ * x^7 + x^3 + 1.
+ *
+ * prev_crc: old crc result (0 for first)
+ * data: new byte
+ * return value: new crc result
+ */
+uint8_t crc7_byte(uint8_t prev_crc, uint8_t data);
+
+/* This function is used to calculate crc16 byte by byte, with polynomial
+ * x^16 + x^12 + x^5 + 1.
+ *
+ * prev_crc: old crc result (0 for first)
+ * data: new byte
+ * return value: new crc result
+ */
+uint16_t crc16_byte(uint16_t prev_crc, uint8_t data);
+
+
+#endif /* CRC_BYTE_H */