]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_md5sum.c
3 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <u-boot/md5.h>
32 * Store the resulting sum to an address or variable
34 static void store_result(const u8
*sum
, const char *dest
)
41 ptr
= (u8
*)simple_strtoul(dest
+ 1, NULL
, 16);
42 for (i
= 0; i
< 16; i
++)
46 char *str_ptr
= str_output
;
48 for (i
= 0; i
< 16; i
++) {
49 sprintf(str_ptr
, "%02x", sum
[i
]);
53 setenv(dest
, str_output
);
57 #ifdef CONFIG_MD5SUM_VERIFY
58 static int parse_verify_sum(char *verify_str
, u8
*vsum
)
60 if (*verify_str
== '*') {
63 ptr
= (u8
*)simple_strtoul(verify_str
+ 1, NULL
, 16);
64 memcpy(vsum
, ptr
, 16);
69 if (strlen(verify_str
) == 32)
70 vsum_str
= verify_str
;
72 vsum_str
= getenv(verify_str
);
73 if (vsum_str
== NULL
|| strlen(vsum_str
) != 32)
77 for (i
= 0; i
< 16; i
++) {
78 char *nullp
= vsum_str
+ (i
+ 1) * 2;
83 simple_strtoul(vsum_str
+ (i
* 2), NULL
, 16);
90 int do_md5sum(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
101 return CMD_RET_USAGE
;
105 if (strcmp(*av
, "-v") == 0) {
110 return CMD_RET_USAGE
;
113 addr
= simple_strtoul(*av
++, NULL
, 16);
114 len
= simple_strtoul(*av
++, NULL
, 16);
116 md5_wd((unsigned char *) addr
, len
, output
, CHUNKSZ_MD5
);
119 printf("md5 for %08lx ... %08lx ==> ", addr
, addr
+ len
- 1);
120 for (i
= 0; i
< 16; i
++)
121 printf("%02x", output
[i
]);
125 store_result(output
, *av
);
127 char *verify_str
= *av
++;
129 if (parse_verify_sum(verify_str
, vsum
)) {
130 printf("ERROR: %s does not contain a valid md5 sum\n",
134 if (memcmp(output
, vsum
, 16) != 0) {
135 printf("md5 for %08lx ... %08lx ==> ", addr
,
137 for (i
= 0; i
< 16; i
++)
138 printf("%02x", output
[i
]);
140 for (i
= 0; i
< 16; i
++)
141 printf("%02x", vsum
[i
]);
142 printf(" ** ERROR **\n");
150 static int do_md5sum(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
152 unsigned long addr
, len
;
157 return CMD_RET_USAGE
;
159 addr
= simple_strtoul(argv
[1], NULL
, 16);
160 len
= simple_strtoul(argv
[2], NULL
, 16);
162 md5_wd((unsigned char *) addr
, len
, output
, CHUNKSZ_MD5
);
163 printf("md5 for %08lx ... %08lx ==> ", addr
, addr
+ len
- 1);
164 for (i
= 0; i
< 16; i
++)
165 printf("%02x", output
[i
]);
169 store_result(output
, argv
[3]);
175 #ifdef CONFIG_MD5SUM_VERIFY
177 md5sum
, 5, 1, do_md5sum
,
178 "compute MD5 message digest",
179 "address count [[*]sum]\n"
180 " - compute MD5 message digest [save to sum]\n"
181 "md5sum -v address count [*]sum\n"
182 " - verify md5sum of memory area"
186 md5sum
, 4, 1, do_md5sum
,
187 "compute MD5 message digest",
188 "address count [[*]sum]\n"
189 " - compute MD5 message digest [save to sum]"