blob: 52aa26c78d2f9b8b81d5390adc771700b1569e6d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mike Frysingera2274902011-04-02 21:40:19 -04002/*
Joe Hershbergerd4483122012-08-17 11:00:45 +00003 * (C) Copyright 2011
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5 *
Mike Frysingera2274902011-04-02 21:40:19 -04006 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Mike Frysingera2274902011-04-02 21:40:19 -04008 */
9
Mike Frysingera2274902011-04-02 21:40:19 -040010#include <command.h>
Simon Glassff436e02012-12-05 14:46:37 +000011#include <hash.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020012#include <u-boot/sha1.h>
Mike Frysingera2274902011-04-02 21:40:19 -040013
Simon Glassed38aef2020-05-10 11:40:03 -060014int do_sha1sum(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Joe Hershbergerd4483122012-08-17 11:00:45 +000015{
Simon Glass80e345a2013-02-24 17:33:26 +000016 int flags = HASH_FLAG_ENV;
Joe Hershbergerd4483122012-08-17 11:00:45 +000017 int ac;
18 char * const *av;
19
20 if (argc < 3)
21 return CMD_RET_USAGE;
22
23 av = argv + 1;
24 ac = argc - 1;
Simon Glassff436e02012-12-05 14:46:37 +000025#ifdef CONFIG_SHA1SUM_VERIFY
Joe Hershbergerd4483122012-08-17 11:00:45 +000026 if (strcmp(*av, "-v") == 0) {
Simon Glass80e345a2013-02-24 17:33:26 +000027 flags |= HASH_FLAG_VERIFY;
Joe Hershbergerd4483122012-08-17 11:00:45 +000028 av++;
29 ac--;
Joe Hershbergerd4483122012-08-17 11:00:45 +000030 }
Simon Glassff436e02012-12-05 14:46:37 +000031#endif
Joe Hershberger95e11082012-08-17 11:00:46 +000032
Simon Glass80e345a2013-02-24 17:33:26 +000033 return hash_command("sha1", flags, cmdtp, flag, ac, av);
Mike Frysingera2274902011-04-02 21:40:19 -040034}
35
Joe Hershbergerd4483122012-08-17 11:00:45 +000036#ifdef CONFIG_SHA1SUM_VERIFY
37U_BOOT_CMD(
38 sha1sum, 5, 1, do_sha1sum,
39 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000040 "address count [[*]sum]\n"
41 " - compute SHA1 message digest [save to sum]\n"
Joe Hershbergerd4483122012-08-17 11:00:45 +000042 "sha1sum -v address count [*]sum\n"
43 " - verify sha1sum of memory area"
44);
45#else
Mike Frysingera2274902011-04-02 21:40:19 -040046U_BOOT_CMD(
Joe Hershberger95e11082012-08-17 11:00:46 +000047 sha1sum, 4, 1, do_sha1sum,
Mike Frysingera2274902011-04-02 21:40:19 -040048 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000049 "address count [[*]sum]\n"
50 " - compute SHA1 message digest [save to sum]"
Mike Frysingera2274902011-04-02 21:40:19 -040051);
Joe Hershbergerd4483122012-08-17 11:00:45 +000052#endif