hash.c 1.2 KB

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