hash.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2012 The Chromium OS Authors.
  3. * See file CREDITS for list of people who contributed to this
  4. * project.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #ifndef _HASH_H
  22. #define _HASH_H
  23. #if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
  24. #define CONFIG_HASH_VERIFY
  25. #endif
  26. struct hash_algo {
  27. const char *name; /* Name of algorithm */
  28. int digest_size; /* Length of digest */
  29. /**
  30. * hash_func_ws: Generic hashing function
  31. *
  32. * This is the generic prototype for a hashing function. We only
  33. * have the watchdog version at present.
  34. *
  35. * @input: Input buffer
  36. * @ilen: Input buffer length
  37. * @output: Checksum result (length depends on algorithm)
  38. * @chunk_sz: Trigger watchdog after processing this many bytes
  39. */
  40. void (*hash_func_ws)(const unsigned char *input, unsigned int ilen,
  41. unsigned char *output, unsigned int chunk_sz);
  42. int chunk_size; /* Watchdog chunk size */
  43. };
  44. /*
  45. * Maximum digest size for all algorithms we support. Having this value
  46. * avoids a malloc() or C99 local declaration in common/cmd_hash.c.
  47. */
  48. #define HASH_MAX_DIGEST_SIZE 32
  49. enum {
  50. HASH_FLAG_VERIFY = 1 << 0, /* Enable verify mode */
  51. HASH_FLAG_ENV = 1 << 1, /* Allow env vars */
  52. };
  53. /**
  54. * hash_command: Process a hash command for a particular algorithm
  55. *
  56. * This common function is used to implement specific hash commands.
  57. *
  58. * @algo_name: Hash algorithm being used (lower case!)
  59. * @flags: Flags value (HASH_FLAG_...)
  60. * @cmdtp: Pointer to command table entry
  61. * @flag: Some flags normally 0 (see CMD_FLAG_.. above)
  62. * @argc: Number of arguments (arg 0 must be the command text)
  63. * @argv: Arguments
  64. */
  65. int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
  66. int argc, char * const argv[]);
  67. #endif