hash: Plumb crc8 into the hash functions
authorSimon Glass <sjg@chromium.org>
Thu, 19 Dec 2024 18:29:07 +0000 (11:29 -0700)
committerTom Rini <trini@konsulko.com>
Fri, 27 Dec 2024 21:16:10 +0000 (15:16 -0600)
Add an entry for crc8, with watchdog handling.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
common/Kconfig
common/hash.c
include/u-boot/crc.h
lib/crc8.c

index e8d89bf..0e8c44f 100644 (file)
@@ -845,6 +845,14 @@ config HASH
          and the algorithms it supports are defined in common/hash.c. See
          also CMD_HASH for command-line access.
 
+config HASH_CRC8
+       bool "Make crc8 available via the hash API"
+       depends on HASH && CRC8
+       help
+         Most times, the crc8() function is called directly. To make it also
+         available via the hash API, e.g. in hash_block(), enable this
+         option.
+
 config AVB_VERIFY
        bool "Build Android Verified Boot operations"
        depends on LIBAVB
index db6925d..8dd9da8 100644 (file)
@@ -304,6 +304,14 @@ static struct hash_algo hash_algo[] = {
                .hash_update    = hash_update_crc16_ccitt,
                .hash_finish    = hash_finish_crc16_ccitt,
        },
+#if CONFIG_IS_ENABLED(CRC8) && IS_ENABLED(CONFIG_HASH_CRC8)
+       {
+               .name           = "crc8",
+               .digest_size    = 1,
+               .chunk_size     = CHUNKSZ_CRC32,
+               .hash_func_ws   = crc8_wd_buf,
+       },
+#endif
 #if CONFIG_IS_ENABLED(CRC32)
        {
                .name           = "crc32",
index 5174bd7..b2badaf 100644 (file)
@@ -25,6 +25,9 @@
  */
 unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
 
+void crc8_wd_buf(const unsigned char *input, unsigned int len,
+                unsigned char output[1], unsigned int chunk_sz);
+
 /* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */
 uint16_t crc16(uint16_t crc, const unsigned char *buffer, size_t len);
 
index 20d46d1..811e199 100644 (file)
@@ -32,3 +32,9 @@ unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
 
        return crc;
 }
+
+void crc8_wd_buf(const unsigned char *input, unsigned int len,
+                unsigned char output[1], unsigned int chunk_sz)
+{
+       *output = crc8(0, input, len);
+}