Commit 3c210e29cd9ae1b70fe89fd1d58574af4b079855
Committed by
Tom Rini
1 parent
e6e77d354f
Exists in
master
and in
54 other branches
Add parameter to sha1sum to save the SHA1 sum
Add a parameter that allows you to store the SHA1 sum to either a memory location or a variable. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Showing 1 changed file with 37 additions and 4 deletions Side-by-side Diff
common/cmd_sha1sum.c
... | ... | @@ -28,6 +28,32 @@ |
28 | 28 | #include <command.h> |
29 | 29 | #include <sha1.h> |
30 | 30 | |
31 | +/* | |
32 | + * Store the resulting sum to an address or variable | |
33 | + */ | |
34 | +static void store_result(const u8 *sum, const char *dest) | |
35 | +{ | |
36 | + unsigned int i; | |
37 | + | |
38 | + if (*dest == '*') { | |
39 | + u8 *ptr; | |
40 | + | |
41 | + ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); | |
42 | + for (i = 0; i < 20; i++) | |
43 | + *ptr++ = sum[i]; | |
44 | + } else { | |
45 | + char str_output[41]; | |
46 | + char *str_ptr = str_output; | |
47 | + | |
48 | + for (i = 0; i < 20; i++) { | |
49 | + sprintf(str_ptr, "%02x", sum[i]); | |
50 | + str_ptr += 2; | |
51 | + } | |
52 | + str_ptr = '\0'; | |
53 | + setenv(dest, str_output); | |
54 | + } | |
55 | +} | |
56 | + | |
31 | 57 | #ifdef CONFIG_SHA1SUM_VERIFY |
32 | 58 | static int parse_verify_sum(char *verify_str, u8 *vsum) |
33 | 59 | { |
... | ... | @@ -94,6 +120,9 @@ |
94 | 120 | for (i = 0; i < 20; i++) |
95 | 121 | printf("%02x", output[i]); |
96 | 122 | printf("\n"); |
123 | + | |
124 | + if (ac > 2) | |
125 | + store_result(output, *av); | |
97 | 126 | } else { |
98 | 127 | char *verify_str = *av++; |
99 | 128 | |
... | ... | @@ -136,6 +165,9 @@ |
136 | 165 | printf("%02x", output[i]); |
137 | 166 | printf("\n"); |
138 | 167 | |
168 | + if (argc > 3) | |
169 | + store_result(output, argv[3]); | |
170 | + | |
139 | 171 | return 0; |
140 | 172 | } |
141 | 173 | #endif |
142 | 174 | |
143 | 175 | |
... | ... | @@ -144,16 +176,17 @@ |
144 | 176 | U_BOOT_CMD( |
145 | 177 | sha1sum, 5, 1, do_sha1sum, |
146 | 178 | "compute SHA1 message digest", |
147 | - "address count\n" | |
148 | - " - compute SHA1 message digest\n" | |
179 | + "address count [[*]sum]\n" | |
180 | + " - compute SHA1 message digest [save to sum]\n" | |
149 | 181 | "sha1sum -v address count [*]sum\n" |
150 | 182 | " - verify sha1sum of memory area" |
151 | 183 | ); |
152 | 184 | #else |
153 | 185 | U_BOOT_CMD( |
154 | - sha1sum, 3, 1, do_sha1sum, | |
186 | + sha1sum, 4, 1, do_sha1sum, | |
155 | 187 | "compute SHA1 message digest", |
156 | - "address count" | |
188 | + "address count [[*]sum]\n" | |
189 | + " - compute SHA1 message digest [save to sum]" | |
157 | 190 | ); |
158 | 191 | #endif |