hash.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(struct cmd_tbl *cmdtp, int flag, int argc,
  16. char *const argv[])
  17. {
  18. char *s;
  19. int flags = HASH_FLAG_ENV;
  20. #ifdef CONFIG_HASH_VERIFY
  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. #endif
  29. /* Move forward to 'algorithm' parameter */
  30. argc--;
  31. argv++;
  32. for (s = *argv; *s; s++)
  33. *s = tolower(*s);
  34. return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
  35. }
  36. #ifdef CONFIG_HASH_VERIFY
  37. #define HARGS 6
  38. #else
  39. #define HARGS 5
  40. #endif
  41. U_BOOT_CMD(
  42. hash, HARGS, 1, do_hash,
  43. "compute hash message digest",
  44. "algorithm address count [[*]hash_dest]\n"
  45. " - compute message digest [save to env var / *address]"
  46. #ifdef CONFIG_HASH_VERIFY
  47. "\nhash -v algorithm address count [*]hash\n"
  48. " - verify message digest of memory area to immediate value, \n"
  49. " env var or *address"
  50. #endif
  51. );