Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 2 | /* |
| 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 Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <command.h> |
| 14 | #include <hash.h> |
Simon Glass | 218da0f | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 15 | #include <linux/ctype.h> |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 16 | |
Igor Opaniuk | 348ea87 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 17 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
| 18 | #define HARGS 6 |
| 19 | #else |
| 20 | #define HARGS 5 |
| 21 | #endif |
| 22 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 23 | static int do_hash(struct cmd_tbl *cmdtp, int flag, int argc, |
| 24 | char *const argv[]) |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 25 | { |
Simon Glass | 218da0f | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 26 | char *s; |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 27 | int flags = HASH_FLAG_ENV; |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 28 | |
Igor Opaniuk | 348ea87 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 29 | if (argc < (HARGS - 1)) |
Simon Glass | 6b3ff98 | 2013-02-24 17:33:11 +0000 | [diff] [blame] | 30 | return CMD_RET_USAGE; |
Igor Opaniuk | 348ea87 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 31 | |
| 32 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 33 | if (!strcmp(argv[1], "-v")) { |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 34 | flags |= HASH_FLAG_VERIFY; |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 35 | argc--; |
| 36 | argv++; |
| 37 | } |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 38 | #endif |
| 39 | /* Move forward to 'algorithm' parameter */ |
| 40 | argc--; |
| 41 | argv++; |
Simon Glass | 218da0f | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 42 | for (s = *argv; *s; s++) |
| 43 | *s = tolower(*s); |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 44 | return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); |
Simon Glass | bf36c5d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Nikolay Dimitrov | 3ef46a9 | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 47 | U_BOOT_CMD( |
| 48 | hash, HARGS, 1, do_hash, |
| 49 | "compute hash message digest", |
| 50 | "algorithm address count [[*]hash_dest]\n" |
| 51 | " - compute message digest [save to env var / *address]" |
Igor Opaniuk | 348ea87 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
Nikolay Dimitrov | 3ef46a9 | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 53 | "\nhash -v algorithm address count [*]hash\n" |
| 54 | " - verify message digest of memory area to immediate value, \n" |
| 55 | " env var or *address" |
| 56 | #endif |
| 57 | ); |