cmd_hash.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <hash.h>
  28. #include <linux/ctype.h>
  29. static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  30. {
  31. char *s;
  32. #ifdef CONFIG_HASH_VERIFY
  33. int flags = HASH_FLAG_ENV;
  34. if (argc < 4)
  35. return CMD_RET_USAGE;
  36. if (!strcmp(argv[1], "-v")) {
  37. flags |= HASH_FLAG_VERIFY;
  38. argc--;
  39. argv++;
  40. }
  41. #else
  42. const int flags = HASH_FLAG_ENV;
  43. #endif
  44. /* Move forward to 'algorithm' parameter */
  45. argc--;
  46. argv++;
  47. for (s = *argv; *s; s++)
  48. *s = tolower(*s);
  49. return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
  50. }
  51. #ifdef CONFIG_HASH_VERIFY
  52. U_BOOT_CMD(
  53. hash, 6, 1, do_hash,
  54. "compute hash message digest",
  55. "algorithm address count [[*]sum_dest]\n"
  56. " - compute message digest [save to env var / *address]\n"
  57. "hash -v algorithm address count [*]sum\n"
  58. " - verify hash of memory area with env var / *address"
  59. );
  60. #else
  61. U_BOOT_CMD(
  62. hash, 5, 1, do_hash,
  63. "compute message digest",
  64. "algorithm address count [[*]sum_dest]\n"
  65. " - compute message digest [save to env var / *address]"
  66. );
  67. #endif