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