hash.c 730 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * BTRFS filesystem implementation for U-Boot
  3. *
  4. * 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include "btrfs.h"
  9. #include <u-boot/crc.h>
  10. #include <asm/unaligned.h>
  11. static u32 btrfs_crc32c_table[256];
  12. void btrfs_hash_init(void)
  13. {
  14. static int inited = 0;
  15. if (!inited) {
  16. crc32c_init(btrfs_crc32c_table, 0x82F63B78);
  17. inited = 1;
  18. }
  19. }
  20. u32 btrfs_crc32c(u32 crc, const void *data, size_t length)
  21. {
  22. return crc32c_cal(crc, (const char *) data, length,
  23. btrfs_crc32c_table);
  24. }
  25. u32 btrfs_csum_data(char *data, u32 seed, size_t len)
  26. {
  27. return btrfs_crc32c(seed, data, len);
  28. }
  29. void btrfs_csum_final(u32 crc, void *result)
  30. {
  31. put_unaligned(cpu_to_le32(~crc), (u32 *)result);
  32. }