blob: 60d482b7f87267418b998e68a02592de1aaa121d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass058bb8d2012-12-05 14:46:38 +00002/*
3 * Copyright (c) 2012 The Chromium OS Authors.
4 *
5 * (C) Copyright 2011
6 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
7 *
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass058bb8d2012-12-05 14:46:38 +000010 */
11
Simon Glass058bb8d2012-12-05 14:46:38 +000012#include <command.h>
13#include <hash.h>
Simon Glasse22a6fc2013-02-24 17:33:32 +000014#include <linux/ctype.h>
Simon Glass058bb8d2012-12-05 14:46:38 +000015
Igor Opaniuk1eb0c622024-02-07 01:01:32 +010016#if IS_ENABLED(CONFIG_HASH_VERIFY)
17#define HARGS 6
18#else
19#define HARGS 5
20#endif
21
Simon Glassed38aef2020-05-10 11:40:03 -060022static int do_hash(struct cmd_tbl *cmdtp, int flag, int argc,
23 char *const argv[])
Simon Glass058bb8d2012-12-05 14:46:38 +000024{
Simon Glasse22a6fc2013-02-24 17:33:32 +000025 char *s;
Simon Glass80e345a2013-02-24 17:33:26 +000026 int flags = HASH_FLAG_ENV;
Simon Glass058bb8d2012-12-05 14:46:38 +000027
Igor Opaniuk1eb0c622024-02-07 01:01:32 +010028 if (argc < (HARGS - 1))
Simon Glass20bc72a2013-02-24 17:33:11 +000029 return CMD_RET_USAGE;
Igor Opaniuk1eb0c622024-02-07 01:01:32 +010030
31#if IS_ENABLED(CONFIG_HASH_VERIFY)
Simon Glass058bb8d2012-12-05 14:46:38 +000032 if (!strcmp(argv[1], "-v")) {
Simon Glass80e345a2013-02-24 17:33:26 +000033 flags |= HASH_FLAG_VERIFY;
Simon Glass058bb8d2012-12-05 14:46:38 +000034 argc--;
35 argv++;
36 }
Simon Glass058bb8d2012-12-05 14:46:38 +000037#endif
38 /* Move forward to 'algorithm' parameter */
39 argc--;
40 argv++;
Simon Glasse22a6fc2013-02-24 17:33:32 +000041 for (s = *argv; *s; s++)
42 *s = tolower(*s);
Simon Glass80e345a2013-02-24 17:33:26 +000043 return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
Simon Glass058bb8d2012-12-05 14:46:38 +000044}
45
Simon Glass058bb8d2012-12-05 14:46:38 +000046U_BOOT_CMD(
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +020047 hash, HARGS, 1, do_hash,
48 "compute hash message digest",
49 "algorithm address count [[*]hash_dest]\n"
Simon Glass058bb8d2012-12-05 14:46:38 +000050 " - compute message digest [save to env var / *address]"
Igor Opaniuk1eb0c622024-02-07 01:01:32 +010051#if IS_ENABLED(CONFIG_HASH_VERIFY)
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +020052 "\nhash -v algorithm address count [*]hash\n"
53 " - verify message digest of memory area to immediate value, \n"
54 " env var or *address"
Simon Glass058bb8d2012-12-05 14:46:38 +000055#endif
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +020056);