blob: 90facbbe1ac9d5c5113e92f3c34a8972fe6d1481 [file] [log] [blame]
Simon Glassbf36c5d2012-12-05 14:46:38 +00001/*
2 * Copyright (c) 2012 The Chromium OS Authors.
3 *
4 * (C) Copyright 2011
5 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Simon Glassbf36c5d2012-12-05 14:46:38 +000011 */
12
13#include <common.h>
14#include <command.h>
15#include <hash.h>
Simon Glass218da0f2013-02-24 17:33:32 +000016#include <linux/ctype.h>
Simon Glassbf36c5d2012-12-05 14:46:38 +000017
18static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
19{
Simon Glass218da0f2013-02-24 17:33:32 +000020 char *s;
Simon Glassbf36c5d2012-12-05 14:46:38 +000021#ifdef CONFIG_HASH_VERIFY
Simon Glassd5b76672013-02-24 17:33:26 +000022 int flags = HASH_FLAG_ENV;
Simon Glassbf36c5d2012-12-05 14:46:38 +000023
Simon Glass6b3ff982013-02-24 17:33:11 +000024 if (argc < 4)
25 return CMD_RET_USAGE;
Simon Glassbf36c5d2012-12-05 14:46:38 +000026 if (!strcmp(argv[1], "-v")) {
Simon Glassd5b76672013-02-24 17:33:26 +000027 flags |= HASH_FLAG_VERIFY;
Simon Glassbf36c5d2012-12-05 14:46:38 +000028 argc--;
29 argv++;
30 }
Simon Glass6b3ff982013-02-24 17:33:11 +000031#else
Simon Glassd5b76672013-02-24 17:33:26 +000032 const int flags = HASH_FLAG_ENV;
Simon Glassbf36c5d2012-12-05 14:46:38 +000033#endif
34 /* Move forward to 'algorithm' parameter */
35 argc--;
36 argv++;
Simon Glass218da0f2013-02-24 17:33:32 +000037 for (s = *argv; *s; s++)
38 *s = tolower(*s);
Simon Glassd5b76672013-02-24 17:33:26 +000039 return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
Simon Glassbf36c5d2012-12-05 14:46:38 +000040}
41
42#ifdef CONFIG_HASH_VERIFY
43U_BOOT_CMD(
44 hash, 6, 1, do_hash,
45 "compute hash message digest",
46 "algorithm address count [[*]sum_dest]\n"
47 " - compute message digest [save to env var / *address]\n"
48 "hash -v algorithm address count [*]sum\n"
49 " - verify hash of memory area with env var / *address"
50);
51#else
52U_BOOT_CMD(
53 hash, 5, 1, do_hash,
54 "compute message digest",
55 "algorithm address count [[*]sum_dest]\n"
56 " - compute message digest [save to env var / *address]"
57);
58#endif