1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-11-02 19:36:22 +01:00

fs: btrfs: Add more checksum algorithms

This mostly crossports crypto/hash.[ch] from btrfs-progs.

The differences are:
- No blake2 support
  No blake2 related library in U-Boot yet.

- Use uboot xxhash/sha256 directly
  No need to implement the code as U-Boot has already provided the
  interface.

This adds the support for the following csums:
- SHA256
- XXHASH

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
This commit is contained in:
Qu Wenruo
2020-06-24 18:02:48 +02:00
committed by Tom Rini
parent 3b4b40c0d6
commit 565a4147d1
10 changed files with 130 additions and 62 deletions

22
fs/btrfs/disk-io.c Normal file
View File

@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0+
#include <common.h>
#include <fs_internal.h>
#include "disk-io.h"
#include "crypto/hash.h"
int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
{
memset(out, 0, BTRFS_CSUM_SIZE);
switch (csum_type) {
case BTRFS_CSUM_TYPE_CRC32:
return hash_crc32c(data, len, out);
case BTRFS_CSUM_TYPE_XXHASH:
return hash_xxhash(data, len, out);
case BTRFS_CSUM_TYPE_SHA256:
return hash_sha256(data, len, out);
default:
printf("Unknown csum type %d\n", csum_type);
return -EINVAL;
}
}