[U-Boot] [PATCH v2 1/3] crypto: add md5 to common hash functions

Ben Whitten ben.whitten at gmail.com
Wed Jun 6 16:03:56 UTC 2018


The md5 function was missing from the common hash functions

Signed-off-by: Ben Whitten <ben.whitten at lairdtech.com>
---
 common/hash.c        | 8 ++++++++
 include/image.h      | 1 +
 include/u-boot/md5.h | 7 ++++---
 lib/Makefile         | 1 +
 lib/md5.c            | 4 ++--
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/common/hash.c b/common/hash.c
index ef14651..d2f4b3f 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -168,6 +168,14 @@ static struct hash_algo hash_algo[] = {
 		.hash_update	= hash_update_crc32,
 		.hash_finish	= hash_finish_crc32,
 	},
+#ifdef CONFIG_MD5
+	{
+		.name		= "md5",
+		.digest_size	= 16,
+		.chunk_size	= CHUNKSZ_MD5,
+		.hash_func_ws 	= md5_wd,
+	},
+#endif
 };
 
 /* Try to minimize code size for boards that don't want much hashing */
diff --git a/include/image.h b/include/image.h
index 9522ee4..a5a5807 100644
--- a/include/image.h
+++ b/include/image.h
@@ -32,6 +32,7 @@ struct fdt_region;
 #define CONFIG_FIT_ENABLE_SHA256_SUPPORT
 #define CONFIG_SHA1
 #define CONFIG_SHA256
+#define CONFIG_MD5
 
 #define IMAGE_ENABLE_IGNORE	0
 #define IMAGE_INDENT_STRING	""
diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h
index e09c16a..365d125 100644
--- a/include/u-boot/md5.h
+++ b/include/u-boot/md5.h
@@ -21,14 +21,15 @@ struct MD5Context {
  * Calculate and store in 'output' the MD5 digest of 'len' bytes at
  * 'input'. 'output' must have enough space to hold 16 bytes.
  */
-void md5 (unsigned char *input, int len, unsigned char output[16]);
+
+void md5 (const unsigned char *input, unsigned int len, unsigned char *output);
 
 /*
  * Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'.
  * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the
  * watchdog every 'chunk_sz' bytes of input processed.
  */
-void md5_wd (unsigned char *input, int len, unsigned char output[16],
-		unsigned int chunk_sz);
+void md5_wd (const unsigned char *input, unsigned int len,
+		unsigned char *output, unsigned int chunk_sz);
 
 #endif /* _MD5_H */
diff --git a/lib/Makefile b/lib/Makefile
index d531ea5..5c4aa73 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -78,6 +78,7 @@ obj-y += div64.o
 obj-y += hang.o
 obj-y += linux_compat.o
 obj-y += linux_string.o
+obj-$(CONFIG_$(SPL_TPL_)MD5_SUPPORT) += md5.o
 obj-y += membuff.o
 obj-$(CONFIG_REGEX) += slre.o
 obj-y += string.o
diff --git a/lib/md5.c b/lib/md5.c
index 2ae4a06..2278001 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -268,7 +268,7 @@ MD5Transform(__u32 buf[4], __u32 const in[16])
  * 'input'. 'output' must have enough space to hold 16 bytes.
  */
 void
-md5 (unsigned char *input, int len, unsigned char output[16])
+md5 (const unsigned char *input, unsigned int len, unsigned char *output)
 {
 	struct MD5Context context;
 
@@ -284,7 +284,7 @@ md5 (unsigned char *input, int len, unsigned char output[16])
  * watchdog every 'chunk_sz' bytes of input processed.
  */
 void
-md5_wd (unsigned char *input, int len, unsigned char output[16],
+md5_wd (const unsigned char *input, unsigned int len, unsigned char *output,
 	unsigned int chunk_sz)
 {
 	struct MD5Context context;
-- 
2.7.4



More information about the U-Boot mailing list