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,
31 #ifdef CONFIG_SHA1SUM_VERIFY
32 static int parse_verify_sum(char *verify_str, u8 *vsum)
34 if (*verify_str == '*') {
37 ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16);
38 memcpy(vsum, ptr, 20);
43 if (strlen(verify_str) == 40)
44 vsum_str = verify_str;
46 vsum_str = getenv(verify_str);
47 if (vsum_str == NULL || strlen(vsum_str) != 40)
51 for (i = 0; i < 20; i++) {
52 char *nullp = vsum_str + (i + 1) * 2;
57 simple_strtoul(vsum_str + (i * 2), NULL, 16);
64 int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
79 if (strcmp(*av, "-v") == 0) {
87 addr = simple_strtoul(*av++, NULL, 16);
88 len = simple_strtoul(*av++, NULL, 16);
90 sha1_csum_wd((unsigned char *) addr, len, output, CHUNKSZ_SHA1);
93 printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
94 for (i = 0; i < 20; i++)
95 printf("%02x", output[i]);
98 char *verify_str = *av++;
100 if (parse_verify_sum(verify_str, vsum)) {
101 printf("ERROR: %s does not contain a valid SHA1 sum\n",
105 if (memcmp(output, vsum, 20) != 0) {
106 printf("SHA1 for %08lx ... %08lx ==> ", addr,
108 for (i = 0; i < 20; i++)
109 printf("%02x", output[i]);
111 for (i = 0; i < 20; i++)
112 printf("%02x", vsum[i]);
113 printf(" ** ERROR **\n");
121 static int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
123 unsigned long addr, len;
128 return CMD_RET_USAGE;
130 addr = simple_strtoul(argv[1], NULL, 16);
131 len = simple_strtoul(argv[2], NULL, 16);
133 sha1_csum_wd((unsigned char *) addr, len, output, CHUNKSZ_SHA1);
134 printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
135 for (i = 0; i < 20; i++)
136 printf("%02x", output[i]);
143 #ifdef CONFIG_SHA1SUM_VERIFY
145 sha1sum, 5, 1, do_sha1sum,
146 "compute SHA1 message digest",
148 " - compute SHA1 message digest\n"
149 "sha1sum -v address count [*]sum\n"
150 " - verify sha1sum of memory area"
154 sha1sum, 3, 1, do_sha1sum,
155 "compute SHA1 message digest",