rsa-checksum.c 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 <u-boot/rsa.h>
  16. int hash_calculate(const char *name,
  17. const struct image_region region[],
  18. int region_count, uint8_t *checksum)
  19. {
  20. struct hash_algo *algo;
  21. int ret = 0;
  22. void *ctx;
  23. uint32_t i;
  24. i = 0;
  25. ret = hash_progressive_lookup_algo(name, &algo);
  26. if (ret)
  27. return ret;
  28. ret = algo->hash_init(algo, &ctx);
  29. if (ret)
  30. return ret;
  31. for (i = 0; i < region_count - 1; i++) {
  32. ret = algo->hash_update(algo, ctx, region[i].data,
  33. region[i].size, 0);
  34. if (ret)
  35. return ret;
  36. }
  37. ret = algo->hash_update(algo, ctx, region[i].data, region[i].size, 1);
  38. if (ret)
  39. return ret;
  40. ret = algo->hash_finish(algo, ctx, checksum, algo->digest_size);
  41. if (ret)
  42. return ret;
  43. return 0;
  44. }