Skip to contentSkip to conversation

MD5 support

PATCH New Bartlomiej Sieka 1 participant 3 messages Mar 14, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

cover MD5 support

Two patches:
- add MD5 support to U-Boot in general
- enable MD5 protection for new uImage format

Comments are welcome.

Regards,
Bartlomiej

Bartlomiej Sieka (2):
Add MD5 support to the new uImage format
Add the MD5 algorithm

#1 lore raw

PATCH 1/2 Add the MD5 algorithm

MD5 supoprt is turned on by defining CONFIG_MD5, the digest can be then calculated using the md5() function -- see include/md5.h for details.

---

 include/md5.h        |   23 ++++
 lib_generic/Makefile |    1 
 lib_generic/md5.c    |  274 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 298 insertions(+), 0 deletions(-)
 create mode 100644 include/md5.h
 create mode 100644 lib_generic/md5.c
include/md5.h new file +23 -0
new file mode 100644
index 0000000..046d1ee
@@ -0,0 +1,23 @@
+/*
+ * This file was transplanted with slight modifications from Linux sources
+ * (fs/cifs/md5.h) into U-Boot by Bartlomiej Sieka <[email protected]>.
+ */
+
+#ifndef _MD5_H
+#define _MD5_H
+
+#include <linux/types.h>
+
+struct MD5Context {
+	__u32 buf[4];
+	__u32 bits[2];
+	unsigned char in[64];
+};
+
+/*
+ * 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]);
+
+#endif /* _MD5_H */
lib_generic/Makefile +1 -0
index b10793b..abee19a 100644
@@ -36,6 +36,7 @@ COBJS-y += display_options.o
 COBJS-y += div64.o
 COBJS-y += lmb.o
 COBJS-y += ldiv.o
+COBJS-$(CONFIG_MD5) += md5.o
 COBJS-y += sha1.o
 COBJS-y += string.o
 COBJS-y += vsprintf.o
lib_generic/md5.c new file +274 -0

274 lines not on this page · raw message

#2 lore raw

PATCH 2/2 Add MD5 support to the new uImage format

In reply to Bartlomiej Sieka

---

 Makefile         |    2 +-
 common/image.c   |    6 ++++--
 include/image.h  |    1 +
 tools/.gitignore |    1 +
 tools/Makefile   |   11 +++++++++--
 5 files changed, 16 insertions(+), 5 deletions(-)
Makefile +1 -1
index c56518f..3bb8a74 100644
@@ -2873,7 +2873,7 @@ clobber:	clean
 	@rm -f $(OBJS) $(obj)*.bak $(obj)ctags $(obj)etags $(obj)TAGS \
 		$(obj)cscope.* $(obj)*.*~
 	@rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL)
-	@rm -f $(obj)tools/{crc32.c,environment.c,env/crc32.c,sha1.c,inca-swap-bytes}
+	@rm -f $(obj)tools/{crc32.c,environment.c,env/crc32.c,md5.c,sha1.c,inca-swap-bytes}
 	@rm -f $(obj)tools/{image.c,fdt.c,fdt_ro.c,fdt_rw.c,fdt_strerror.c}
 	@rm -f $(obj)tools/{fdt_wip.c,libfdt_internal.h}
 	@rm -f $(obj)cpu/mpc824x/bedbug_603e.c
common/image.c +4 -2
index a2a739e..6508df9 100644
@@ -54,6 +54,7 @@
 #endif
 
 #if defined(CONFIG_FIT)
+#include <md5.h>
 #include <sha1.h>
 
 static int fit_check_ramdisk (const void *fit, int os_noffset,
@@ -70,6 +71,7 @@ static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
 						int verify);
 #else
 #include "mkimage.h"
+#include <md5.h>
 #include <time.h>
 #include <image.h>
 #endif /* !USE_HOSTCC*/
@@ -1940,8 +1942,8 @@ static int calculate_hash (const void *data, int data_len, const char *algo,
 				(unsigned char *) value);
 		*value_len = 20;
 	} else if (strcmp (algo, "md5") == 0 ) {
-		printf ("MD5 not supported\n");
-		*value_len = 0;
+		md5 ((unsigned char *)data, data_len, value);
+		*value_len = 16;
 	} else {
 		debug ("Unsupported hash alogrithm\n");
 		return -1;
include/image.h +1 -0
index fbd8c30..f22dafd 100644
@@ -64,6 +64,7 @@
 #include <fdt.h>
 #include <libfdt.h>
 #include <fdt_support.h>
+#define CONFIG_MD5		/* FIT images need MD5 support */
 #endif
 
 /*
tools/.gitignore +1 -0
index 0ce2e77..979f2da 100644
@@ -4,6 +4,7 @@
 /environment.c
 /gen_eth_addr
 /img2srec
+/md5.c
 /mkimage
 /sha1.c
 /ubsha1
tools/Makefile +9 -2
index aa4af18..9f0dedf 100644
@@ -23,7 +23,7 @@
 
 BIN_FILES	= img2srec$(SFX) mkimage$(SFX) envcrc$(SFX) ubsha1$(SFX) gen_eth_addr$(SFX) bmp_logo$(SFX)
 
-OBJ_LINKS	= environment.o crc32.o sha1.o image.o
+OBJ_LINKS	= environment.o crc32.o md5.o sha1.o image.o
 OBJ_FILES	= img2srec.o mkimage.o envcrc.o ubsha1.o gen_eth_addr.o bmp_logo.o
 
 ifeq ($(ARCH),mips)
@@ -143,7 +143,7 @@ $(obj)img2srec$(SFX):	$(obj)img2srec.o
 		$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 		$(STRIP) $@
 
-$(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)sha1.o $(LIBFDT_OBJ_FILES)
+$(obj)mkimage$(SFX):	$(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)md5.o $(obj)sha1.o $(LIBFDT_OBJ_FILES)
 		$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
 		$(STRIP) $@
 
@@ -176,6 +176,9 @@ $(obj)ubsha1.o:	$(src)ubsha1.c
 $(obj)crc32.o:	$(obj)crc32.c
 		$(CC) -g $(CFLAGS) -c -o $@ $<
 
+$(obj)md5.o:	$(obj)md5.c
+		$(CC) -g $(CFLAGS) -c -o $@ $<
+
 $(obj)sha1.o:	$(obj)sha1.c
 		$(CC) -g $(CFLAGS) -c -o $@ $<
 
@@ -237,6 +240,10 @@ $(obj)crc32.c:
 		@rm -f $(obj)crc32.c
 		ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c
 
+$(obj)md5.c:
+		@rm -f $(obj)md5.c
+		ln -s $(src)../lib_generic/md5.c $(obj)md5.c
+
 $(obj)sha1.c:
 		@rm -f $(obj)sha1.c
 		ln -s $(src)../lib_generic/sha1.c $(obj)sha1.c