lib: Rename rsa-checksum.c to hash-checksum.c
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>
Fri, 19 Feb 2021 18:45:10 +0000 (12:45 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 14 Apr 2021 19:06:08 +0000 (15:06 -0400)
rsa-checksum.c sontains the hash_calculate() implementations. Despite
the "rsa-" file prefix, this function is useful for other algorithms.

To prevent confusion, move this file to lib/, and rename it to
hash-checksum.c, to give it a more "generic" feel.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
12 files changed:
common/image-fit-sig.c
common/image-sig.c
include/image.h
include/u-boot/hash-checksum.h [new file with mode: 0644]
include/u-boot/rsa-checksum.h [deleted file]
lib/Makefile
lib/crypto/pkcs7_verify.c
lib/crypto/x509_public_key.c
lib/hash-checksum.c [new file with mode: 0644]
lib/rsa/Makefile
lib/rsa/rsa-checksum.c [deleted file]
tools/Makefile

index 34ebb8edfe276b2225bf93c939472a8085729ea8..55ddf1879ed7b1d24b42cdd4d73307f65a5b2b7f 100644 (file)
@@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #include <fdt_region.h>
 #include <image.h>
 #include <u-boot/rsa.h>
-#include <u-boot/rsa-checksum.h>
+#include <u-boot/hash-checksum.h>
 
 #define IMAGE_MAX_HASHED_NODES         100
 
index 4abd3c080f78100897b7721e9638cca10222ef65..54f0eb2019acd7acab2eb1a77beebc209887ec5c 100644 (file)
@@ -17,7 +17,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 #include <image.h>
 #include <u-boot/rsa.h>
-#include <u-boot/rsa-checksum.h>
+#include <u-boot/hash-checksum.h>
 
 #define IMAGE_MAX_HASHED_NODES         100
 
index aeb0d37ac0212b752df3534ea38c58e8aaca51d6..375fb46bf927e9a6c13586c7b13eaf3b2bb625a2 100644 (file)
@@ -1283,7 +1283,7 @@ struct image_region {
 };
 
 #if IMAGE_ENABLE_VERIFY
-# include <u-boot/rsa-checksum.h>
+# include <u-boot/hash-checksum.h>
 #endif
 struct checksum_algo {
        const char *name;
diff --git a/include/u-boot/hash-checksum.h b/include/u-boot/hash-checksum.h
new file mode 100644 (file)
index 0000000..54e6a73
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2013, Andreas Oetken.
+ */
+
+#ifndef _RSA_CHECKSUM_H
+#define _RSA_CHECKSUM_H
+
+#include <errno.h>
+#include <image.h>
+#include <u-boot/sha1.h>
+#include <u-boot/sha256.h>
+#include <u-boot/sha512.h>
+
+/**
+ * hash_calculate() - Calculate hash over the data
+ *
+ * @name:  Name of algorithm to be used for hash calculation
+ * @region: Array having info of regions over which hash needs to be calculated
+ * @region_count: Number of regions in the region array
+ * @checksum: Buffer contanining the output hash
+ *
+ * @return 0 if OK, < 0 if error
+ */
+int hash_calculate(const char *name,
+                  const struct image_region region[], int region_count,
+                  uint8_t *checksum);
+
+#endif
diff --git a/include/u-boot/rsa-checksum.h b/include/u-boot/rsa-checksum.h
deleted file mode 100644 (file)
index 54e6a73..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (c) 2013, Andreas Oetken.
- */
-
-#ifndef _RSA_CHECKSUM_H
-#define _RSA_CHECKSUM_H
-
-#include <errno.h>
-#include <image.h>
-#include <u-boot/sha1.h>
-#include <u-boot/sha256.h>
-#include <u-boot/sha512.h>
-
-/**
- * hash_calculate() - Calculate hash over the data
- *
- * @name:  Name of algorithm to be used for hash calculation
- * @region: Array having info of regions over which hash needs to be calculated
- * @region_count: Number of regions in the region array
- * @checksum: Buffer contanining the output hash
- *
- * @return 0 if OK, < 0 if error
- */
-int hash_calculate(const char *name,
-                  const struct image_region region[], int region_count,
-                  uint8_t *checksum);
-
-#endif
index c42d4e12335f3563550c87218288898ffd6d2550..682567195554123574d6f24a63b48a98cf535dd2 100644 (file)
@@ -61,6 +61,7 @@ endif
 obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
 obj-$(CONFIG_$(SPL_)MD5) += md5.o
 obj-$(CONFIG_$(SPL_)RSA) += rsa/
+obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
 obj-$(CONFIG_SHA1) += sha1.o
 obj-$(CONFIG_SHA256) += sha256.o
 obj-$(CONFIG_SHA512_ALGO) += sha512.o
index 58683ef614cbaf72ef3dacd36e39e4e281b85f80..82c5c745d49bdb260874d88656efab43f8208eb3 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/bitops.h>
 #include <linux/compat.h>
 #include <linux/asn1.h>
-#include <u-boot/rsa-checksum.h>
+#include <u-boot/hash-checksum.h>
 #include <crypto/public_key.h>
 #include <crypto/pkcs7_parser.h>
 #else
index 91810a86404902eb9c593a7c8727cfacf8723e8d..d557ab27ae30a3e8e217c424e8d601f5d0fdd1c3 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/kernel.h>
 #ifdef __UBOOT__
 #include <crypto/x509_parser.h>
-#include <u-boot/rsa-checksum.h>
+#include <u-boot/hash-checksum.h>
 #else
 #include <linux/slab.h>
 #include <keys/asymmetric-subtype.h>
diff --git a/lib/hash-checksum.c b/lib/hash-checksum.c
new file mode 100644 (file)
index 0000000..d732ecc
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2013, Andreas Oetken.
+ */
+
+#ifndef USE_HOSTCC
+#include <common.h>
+#include <fdtdec.h>
+#include <asm/byteorder.h>
+#include <linux/errno.h>
+#include <asm/unaligned.h>
+#include <hash.h>
+#else
+#include "fdt_host.h"
+#endif
+#include <hash.h>
+#include <image.h>
+
+int hash_calculate(const char *name,
+                   const struct image_region region[],
+                   int region_count, uint8_t *checksum)
+{
+       struct hash_algo *algo;
+       int ret = 0;
+       void *ctx;
+       uint32_t i;
+       i = 0;
+
+       ret = hash_progressive_lookup_algo(name, &algo);
+       if (ret)
+               return ret;
+
+       ret = algo->hash_init(algo, &ctx);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < region_count - 1; i++) {
+               ret = algo->hash_update(algo, ctx, region[i].data,
+                                       region[i].size, 0);
+               if (ret)
+                       return ret;
+       }
+
+       ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
+       if (ret)
+               return ret;
+       ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
+       if (ret)
+               return ret;
+
+       return 0;
+}
index 8b75d41f04bf4de8771734f667cc81a99188ce31..c9ac72c1e267695f86d11e573ef5f1d64d356170 100644 (file)
@@ -5,6 +5,6 @@
 # (C) Copyright 2000-2007
 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 
-obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY) += rsa-verify.o rsa-checksum.o
+obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY) += rsa-verify.o
 obj-$(CONFIG_$(SPL_TPL_)RSA_VERIFY_WITH_PKEY) += rsa-keyprop.o
 obj-$(CONFIG_RSA_SOFTWARE_EXP) += rsa-mod-exp.o
diff --git a/lib/rsa/rsa-checksum.c b/lib/rsa/rsa-checksum.c
deleted file mode 100644 (file)
index e60debb..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2013, Andreas Oetken.
- */
-
-#ifndef USE_HOSTCC
-#include <common.h>
-#include <fdtdec.h>
-#include <asm/byteorder.h>
-#include <linux/errno.h>
-#include <asm/unaligned.h>
-#include <hash.h>
-#else
-#include "fdt_host.h"
-#endif
-#include <u-boot/rsa.h>
-
-int hash_calculate(const char *name,
-                   const struct image_region region[],
-                   int region_count, uint8_t *checksum)
-{
-       struct hash_algo *algo;
-       int ret = 0;
-       void *ctx;
-       uint32_t i;
-       i = 0;
-
-       ret = hash_progressive_lookup_algo(name, &algo);
-       if (ret)
-               return ret;
-
-       ret = algo->hash_init(algo, &ctx);
-       if (ret)
-               return ret;
-
-       for (i = 0; i < region_count - 1; i++) {
-               ret = algo->hash_update(algo, ctx, region[i].data,
-                                       region[i].size, 0);
-               if (ret)
-                       return ret;
-       }
-
-       ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
-       if (ret)
-               return ret;
-       ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
-       if (ret)
-               return ret;
-
-       return 0;
-}
index 62de7e6fe07de6a0db95d0dbd9a80bc41d76bd77..e968b20fbdee8dadc8a7c242647fae226b76e453 100644 (file)
@@ -67,7 +67,7 @@ LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \
                fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
 
 RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
-                                       rsa-sign.o rsa-verify.o rsa-checksum.o \
+                                       rsa-sign.o rsa-verify.o \
                                        rsa-mod-exp.o)
 
 AES_OBJS-$(CONFIG_FIT_CIPHER) := $(addprefix lib/aes/, \
@@ -106,6 +106,7 @@ dumpimage-mkimage-objs := aisimage.o \
                        socfpgaimage.o \
                        sunxi_egon.o \
                        lib/crc16.o \
+                       lib/hash-checksum.o \
                        lib/sha1.o \
                        lib/sha256.o \
                        lib/sha512.o \