blob: bcc665a5a6c692a9176fcc5694eee6ba154f5ae8 [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
10#include <common.h>
11#include <command.h>
Simon Glassff436e02012-12-05 14:46:37 +000012#include <hash.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020013#include <u-boot/sha1.h>
Mike Frysingera2274902011-04-02 21:40:19 -040014
Simon Glassed38aef2020-05-10 11:40:03 -060015int do_sha1sum(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Joe Hershbergerd4483122012-08-17 11:00:45 +000016{
Simon Glass80e345a2013-02-24 17:33:26 +000017 int flags = HASH_FLAG_ENV;
Joe Hershbergerd4483122012-08-17 11:00:45 +000018 int ac;
19 char * const *av;
20
21 if (argc < 3)
22 return CMD_RET_USAGE;
23
24 av = argv + 1;
25 ac = argc - 1;
Simon Glassff436e02012-12-05 14:46:37 +000026#ifdef CONFIG_SHA1SUM_VERIFY
Joe Hershbergerd4483122012-08-17 11:00:45 +000027 if (strcmp(*av, "-v") == 0) {
Simon Glass80e345a2013-02-24 17:33:26 +000028 flags |= HASH_FLAG_VERIFY;
Joe Hershbergerd4483122012-08-17 11:00:45 +000029 av++;
30 ac--;
Joe Hershbergerd4483122012-08-17 11:00:45 +000031 }
Simon Glassff436e02012-12-05 14:46:37 +000032#endif
Joe Hershberger95e11082012-08-17 11:00:46 +000033
Simon Glass80e345a2013-02-24 17:33:26 +000034 return hash_command("sha1", flags, cmdtp, flag, ac, av);
Mike Frysingera2274902011-04-02 21:40:19 -040035}
36
Joe Hershbergerd4483122012-08-17 11:00:45 +000037#ifdef CONFIG_SHA1SUM_VERIFY
38U_BOOT_CMD(
39 sha1sum, 5, 1, do_sha1sum,
40 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000041 "address count [[*]sum]\n"
42 " - compute SHA1 message digest [save to sum]\n"
Joe Hershbergerd4483122012-08-17 11:00:45 +000043 "sha1sum -v address count [*]sum\n"
44 " - verify sha1sum of memory area"
45);
46#else
Mike Frysingera2274902011-04-02 21:40:19 -040047U_BOOT_CMD(
Joe Hershberger95e11082012-08-17 11:00:46 +000048 sha1sum, 4, 1, do_sha1sum,
Mike Frysingera2274902011-04-02 21:40:19 -040049 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000050 "address count [[*]sum]\n"
51 " - compute SHA1 message digest [save to sum]"
Mike Frysingera2274902011-04-02 21:40:19 -040052);
Joe Hershbergerd4483122012-08-17 11:00:45 +000053#endif