diff mbox series

[v4,1/6] lib: Rename rsa-checksum.c to hash-checksum.c

Message ID 20210108191737.615022-2-mr.nuke.me@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series Add support for ECDSA image signing (with test) | expand

Commit Message

Alex G. Jan. 8, 2021, 7:17 p.m. UTC
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/crypto, and rename it to
hash-checksum.c, to give it a more "generic" feel.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
 common/image-fit-sig.c                             | 2 +-
 common/image-sig.c                                 | 2 +-
 include/image.h                                    | 2 +-
 include/u-boot/{rsa-checksum.h => hash-checksum.h} | 0
 lib/Makefile                                       | 1 +
 lib/crypto/pkcs7_verify.c                          | 2 +-
 lib/crypto/x509_public_key.c                       | 2 +-
 lib/{rsa/rsa-checksum.c => hash-checksum.c}        | 3 ++-
 lib/rsa/Makefile                                   | 2 +-
 tools/Makefile                                     | 3 ++-
 10 files changed, 11 insertions(+), 8 deletions(-)
 rename include/u-boot/{rsa-checksum.h => hash-checksum.h} (100%)
 rename lib/{rsa/rsa-checksum.c => hash-checksum.c} (96%)

Comments

Patrick DELAUNAY Jan. 27, 2021, 7:02 p.m. UTC | #1
Hi,

On 1/8/21 8:17 PM, Alexandru Gagniuc wrote:
> 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/crypto, and rename it to

Today the file is moved in lib and not in lib/crypto...

change the comment or the file location.

> hash-checksum.c, to give it a more "generic" feel.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---
>   common/image-fit-sig.c                             | 2 +-
>   common/image-sig.c                                 | 2 +-
>   include/image.h                                    | 2 +-
>   include/u-boot/{rsa-checksum.h => hash-checksum.h} | 0
>   lib/Makefile                                       | 1 +
>   lib/crypto/pkcs7_verify.c                          | 2 +-
>   lib/crypto/x509_public_key.c                       | 2 +-
>   lib/{rsa/rsa-checksum.c => hash-checksum.c}        | 3 ++-
>   lib/rsa/Makefile                                   | 2 +-
>   tools/Makefile                                     | 3 ++-
>   10 files changed, 11 insertions(+), 8 deletions(-)
>   rename include/u-boot/{rsa-checksum.h => hash-checksum.h} (100%)
>   rename lib/{rsa/rsa-checksum.c => hash-checksum.c} (96%)
>
> diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
> index 5401d9411b..7fcbb47235 100644
> --- a/common/image-fit-sig.c
> +++ b/common/image-fit-sig.c
> @@ -15,7 +15,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
>   
> diff --git a/common/image-sig.c b/common/image-sig.c
> index f3c209ae8b..21dafe6b91 100644
> --- a/common/image-sig.c
> +++ b/common/image-sig.c
> @@ -16,7 +16,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
>   
> diff --git a/include/image.h b/include/image.h
> index 41473dbb9c..a55b11b3ae 100644
> --- a/include/image.h
> +++ b/include/image.h
> @@ -1258,7 +1258,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/rsa-checksum.h b/include/u-boot/hash-checksum.h
> similarity index 100%
> rename from include/u-boot/rsa-checksum.h
> rename to include/u-boot/hash-checksum.h
> diff --git a/lib/Makefile b/lib/Makefile
> index 851a80ef3b..cf64188ba5 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -60,6 +60,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

compiled if CONFIG_FIT_SIGNATURE = y

but after used in mkimage even if CONFIG_FIT_SIGNATURE is not used...

(see after dumpimage-mkimage-objs)

it could be more simple to have :

obj-y += hash-checksum.o

or add a new config CONFIG_HASH (but we need to managed dependancy in Kconfig / Makefile)
  

(...)
> diff --git a/tools/Makefile b/tools/Makefile
> index 253a6b9706..b1595ad814 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -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/, \
> @@ -105,6 +105,7 @@ dumpimage-mkimage-objs := aisimage.o \
>   			$(ROCKCHIP_OBS) \
>   			socfpgaimage.o \
>   			lib/crc16.o \
> +			lib/hash-checksum.o \
>   			lib/sha1.o \
>   			lib/sha256.o \
>   			lib/sha512.o \

lib/hash-checksum.o is required here...

Regards

Patrick
diff mbox series

Patch

diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index 5401d9411b..7fcbb47235 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -15,7 +15,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
 
diff --git a/common/image-sig.c b/common/image-sig.c
index f3c209ae8b..21dafe6b91 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -16,7 +16,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
 
diff --git a/include/image.h b/include/image.h
index 41473dbb9c..a55b11b3ae 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1258,7 +1258,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/rsa-checksum.h b/include/u-boot/hash-checksum.h
similarity index 100%
rename from include/u-boot/rsa-checksum.h
rename to include/u-boot/hash-checksum.h
diff --git a/lib/Makefile b/lib/Makefile
index 851a80ef3b..cf64188ba5 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -60,6 +60,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
diff --git a/lib/crypto/pkcs7_verify.c b/lib/crypto/pkcs7_verify.c
index 320ba49f79..3c411f651f 100644
--- a/lib/crypto/pkcs7_verify.c
+++ b/lib/crypto/pkcs7_verify.c
@@ -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
diff --git a/lib/crypto/x509_public_key.c b/lib/crypto/x509_public_key.c
index 91810a8640..d557ab27ae 100644
--- a/lib/crypto/x509_public_key.c
+++ b/lib/crypto/x509_public_key.c
@@ -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/rsa/rsa-checksum.c b/lib/hash-checksum.c
similarity index 96%
rename from lib/rsa/rsa-checksum.c
rename to lib/hash-checksum.c
index e60debb7df..d732ecc38f 100644
--- a/lib/rsa/rsa-checksum.c
+++ b/lib/hash-checksum.c
@@ -13,7 +13,8 @@ 
 #else
 #include "fdt_host.h"
 #endif
-#include <u-boot/rsa.h>
+#include <hash.h>
+#include <image.h>
 
 int hash_calculate(const char *name,
 		    const struct image_region region[],
diff --git a/lib/rsa/Makefile b/lib/rsa/Makefile
index 8b75d41f04..c9ac72c1e2 100644
--- a/lib/rsa/Makefile
+++ b/lib/rsa/Makefile
@@ -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/tools/Makefile b/tools/Makefile
index 253a6b9706..b1595ad814 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -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/, \
@@ -105,6 +105,7 @@  dumpimage-mkimage-objs := aisimage.o \
 			$(ROCKCHIP_OBS) \
 			socfpgaimage.o \
 			lib/crc16.o \
+			lib/hash-checksum.o \
 			lib/sha1.o \
 			lib/sha256.o \
 			lib/sha512.o \