hash-checksum.c 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013, Andreas Oetken.
  4. */
  5. #ifndef USE_HOSTCC
  6. #include <common.h>
  7. #include <fdtdec.h>
  8. #include <asm/byteorder.h>
  9. #include <linux/errno.h>
  10. #include <asm/unaligned.h>
  11. #include <hash.h>
  12. #else
  13. #include "fdt_host.h"
  14. #endif
  15. #include <hash.h>
  16. #include <image.h>
  17. int hash_calculate(const char *name,
  18. const struct image_region region[],
  19. int region_count, uint8_t *checksum)
  20. {
  21. struct hash_algo *algo;
  22. int ret = 0;
  23. void *ctx;
  24. uint32_t i;
  25. i = 0;
  26. ret = hash_progressive_lookup_algo(name, &algo);
  27. if (ret)
  28. return ret;
  29. ret = algo->hash_init(algo, &ctx);
  30. if (ret)
  31. return ret;
  32. for (i = 0; i < region_count - 1; i++) {
  33. ret = algo->hash_update(algo, ctx, region[i].data,
  34. region[i].size, 0);
  35. if (ret)
  36. return ret;
  37. }
  38. ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
  39. if (ret)
  40. return ret;
  41. ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
  42. if (ret)
  43. return ret;
  44. return 0;
  45. }