xref: /openbmc/u-boot/cmd/sha1sum.c (revision 0edd82e2)
1 /*
2  * (C) Copyright 2011
3  * Joe Hershberger, National Instruments, joe.hershberger@ni.com
4  *
5  * (C) Copyright 2000
6  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7  *
8  * SPDX-License-Identifier:	GPL-2.0+
9  */
10 
11 #include <common.h>
12 #include <command.h>
13 #include <hash.h>
14 #include <u-boot/sha1.h>
15 
16 int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17 {
18 	int flags = HASH_FLAG_ENV;
19 	int ac;
20 	char * const *av;
21 
22 	if (argc < 3)
23 		return CMD_RET_USAGE;
24 
25 	av = argv + 1;
26 	ac = argc - 1;
27 #ifdef CONFIG_SHA1SUM_VERIFY
28 	if (strcmp(*av, "-v") == 0) {
29 		flags |= HASH_FLAG_VERIFY;
30 		av++;
31 		ac--;
32 	}
33 #endif
34 
35 	return hash_command("sha1", flags, cmdtp, flag, ac, av);
36 }
37 
38 #ifdef CONFIG_SHA1SUM_VERIFY
39 U_BOOT_CMD(
40 	sha1sum,	5,	1,	do_sha1sum,
41 	"compute SHA1 message digest",
42 	"address count [[*]sum]\n"
43 		"    - compute SHA1 message digest [save to sum]\n"
44 	"sha1sum -v address count [*]sum\n"
45 		"    - verify sha1sum of memory area"
46 );
47 #else
48 U_BOOT_CMD(
49 	sha1sum,	4,	1,	do_sha1sum,
50 	"compute SHA1 message digest",
51 	"address count [[*]sum]\n"
52 		"    - compute SHA1 message digest [save to sum]"
53 );
54 #endif
55