hash.c 727 B

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