cmd_hash.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  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. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <command.h>
  14. #include <hash.h>
  15. #include <linux/ctype.h>
  16. static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  17. {
  18. char *s;
  19. #ifdef CONFIG_HASH_VERIFY
  20. int flags = HASH_FLAG_ENV;
  21. if (argc < 4)
  22. return CMD_RET_USAGE;
  23. if (!strcmp(argv[1], "-v")) {
  24. flags |= HASH_FLAG_VERIFY;
  25. argc--;
  26. argv++;
  27. }
  28. #else
  29. const int flags = HASH_FLAG_ENV;
  30. #endif
  31. /* Move forward to 'algorithm' parameter */
  32. argc--;
  33. argv++;
  34. for (s = *argv; *s; s++)
  35. *s = tolower(*s);
  36. return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
  37. }
  38. #ifdef CONFIG_HASH_VERIFY
  39. U_BOOT_CMD(
  40. hash, 6, 1, do_hash,
  41. "compute hash message digest",
  42. "algorithm address count [[*]sum_dest]\n"
  43. " - compute message digest [save to env var / *address]\n"
  44. "hash -v algorithm address count [*]sum\n"
  45. " - verify hash of memory area with env var / *address"
  46. );
  47. #else
  48. U_BOOT_CMD(
  49. hash, 5, 1, do_hash,
  50. "compute message digest",
  51. "algorithm address count [[*]sum_dest]\n"
  52. " - compute message digest [save to env var / *address]"
  53. );
  54. #endif