blob: dff943ac9fe64c751ec4a2480bf2db1c203f7aab [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassbf36c5d2012-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 Glassbf36c5d2012-12-05 14:46:38 +000010 */
11
12#include <common.h>
13#include <command.h>
14#include <hash.h>
Simon Glass218da0f2013-02-24 17:33:32 +000015#include <linux/ctype.h>
Simon Glassbf36c5d2012-12-05 14:46:38 +000016
17static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
18{
Simon Glass218da0f2013-02-24 17:33:32 +000019 char *s;
Simon Glassd5b76672013-02-24 17:33:26 +000020 int flags = HASH_FLAG_ENV;
Simon Glassbf36c5d2012-12-05 14:46:38 +000021
Nikolay Dimitrov3ef46a92014-12-12 20:01:23 +020022#ifdef CONFIG_HASH_VERIFY
Simon Glass6b3ff982013-02-24 17:33:11 +000023 if (argc < 4)
24 return CMD_RET_USAGE;
Simon Glassbf36c5d2012-12-05 14:46:38 +000025 if (!strcmp(argv[1], "-v")) {
Simon Glassd5b76672013-02-24 17:33:26 +000026 flags |= HASH_FLAG_VERIFY;
Simon Glassbf36c5d2012-12-05 14:46:38 +000027 argc--;
28 argv++;
29 }
Simon Glassbf36c5d2012-12-05 14:46:38 +000030#endif
31 /* Move forward to 'algorithm' parameter */
32 argc--;
33 argv++;
Simon Glass218da0f2013-02-24 17:33:32 +000034 for (s = *argv; *s; s++)
35 *s = tolower(*s);
Simon Glassd5b76672013-02-24 17:33:26 +000036 return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
Simon Glassbf36c5d2012-12-05 14:46:38 +000037}
38
39#ifdef CONFIG_HASH_VERIFY
Nikolay Dimitrov3ef46a92014-12-12 20:01:23 +020040#define HARGS 6
Simon Glassbf36c5d2012-12-05 14:46:38 +000041#else
Nikolay Dimitrov3ef46a92014-12-12 20:01:23 +020042#define HARGS 5
Simon Glassbf36c5d2012-12-05 14:46:38 +000043#endif
Nikolay Dimitrov3ef46a92014-12-12 20:01:23 +020044
45U_BOOT_CMD(
46 hash, HARGS, 1, do_hash,
47 "compute hash message digest",
48 "algorithm address count [[*]hash_dest]\n"
49 " - compute message digest [save to env var / *address]"
50#ifdef CONFIG_HASH_VERIFY
51 "\nhash -v algorithm address count [*]hash\n"
52 " - verify message digest of memory area to immediate value, \n"
53 " env var or *address"
54#endif
55);