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