blob: f8a50e532aeeb5edabce60b50fbee1fc8b3b4289 [file] [log] [blame]
Marek BehĂșn29387542017-09-03 17:00:28 +02001/*
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
9#include "btrfs.h"
10#include <u-boot/crc.h>
11
12static u32 btrfs_crc32c_table[256];
13
14void btrfs_hash_init(void)
15{
16 static int inited = 0;
17
18 if (!inited) {
19 crc32c_init(btrfs_crc32c_table, 0x82F63B78);
20 inited = 1;
21 }
22}
23
24u32 btrfs_crc32c(u32 crc, const void *data, size_t length)
25{
26 return crc32c_cal(crc, (const char *) data, length,
27 btrfs_crc32c_table);
28}
29
30u32 btrfs_csum_data(char *data, u32 seed, size_t len)
31{
32 return btrfs_crc32c(seed, data, len);
33}
34
35void btrfs_csum_final(u32 crc, void *result)
36{
37 *((u32 *) result) = cpu_to_le32(~crc);
38}