btrfs-progs: add blake2b support
Add definition, crypto wrappers and support to mkfs for blake2 for checksumming. There are 2 aliases either blake2 or blake2b. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
3778ece7ff
commit
2047b6de3d
|
@ -317,6 +317,7 @@ static bool is_valid_csum_type(u16 csum_type)
|
|||
case BTRFS_CSUM_TYPE_CRC32:
|
||||
case BTRFS_CSUM_TYPE_XXHASH:
|
||||
case BTRFS_CSUM_TYPE_SHA256:
|
||||
case BTRFS_CSUM_TYPE_BLAKE2:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "crypto/crc32c.h"
|
||||
#include "crypto/xxhash.h"
|
||||
#include "crypto/sha.h"
|
||||
#include "crypto/blake2.h"
|
||||
|
||||
int hash_crc32c(const u8* buf, size_t length, u8 *out)
|
||||
{
|
||||
|
@ -37,3 +38,14 @@ int hash_sha256(const u8 *buf, size_t len, u8 *out)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hash_blake2b(const u8 *buf, size_t len, u8 *out)
|
||||
{
|
||||
blake2b_state S;
|
||||
|
||||
blake2b_init(&S, CRYPTO_HASH_SIZE_MAX);
|
||||
blake2b_update(&S, buf, len);
|
||||
blake2b_final(&S, out, CRYPTO_HASH_SIZE_MAX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
int hash_crc32c(const u8 *buf, size_t length, u8 *out);
|
||||
int hash_xxhash(const u8 *buf, size_t length, u8 *out);
|
||||
int hash_sha256(const u8 *buf, size_t length, u8 *out);
|
||||
int hash_blake2b(const u8 *buf, size_t length, u8 *out);
|
||||
|
||||
#endif
|
||||
|
|
1
ctree.c
1
ctree.c
|
@ -45,6 +45,7 @@ static const struct btrfs_csum {
|
|||
[BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" },
|
||||
[BTRFS_CSUM_TYPE_XXHASH] = { 8, "xxhash64" },
|
||||
[BTRFS_CSUM_TYPE_SHA256] = { 32, "sha256" },
|
||||
[BTRFS_CSUM_TYPE_BLAKE2] = { 32, "blake2" },
|
||||
};
|
||||
|
||||
u16 btrfs_super_csum_size(const struct btrfs_super_block *sb)
|
||||
|
|
1
ctree.h
1
ctree.h
|
@ -169,6 +169,7 @@ enum btrfs_csum_type {
|
|||
BTRFS_CSUM_TYPE_CRC32 = 0,
|
||||
BTRFS_CSUM_TYPE_XXHASH = 1,
|
||||
BTRFS_CSUM_TYPE_SHA256 = 2,
|
||||
BTRFS_CSUM_TYPE_BLAKE2 = 3,
|
||||
};
|
||||
|
||||
#define BTRFS_EMPTY_DIR_SIZE 0
|
||||
|
|
|
@ -150,6 +150,8 @@ int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
|
|||
return hash_xxhash(data, len, out);
|
||||
case BTRFS_CSUM_TYPE_SHA256:
|
||||
return hash_sha256(data, len, out);
|
||||
case BTRFS_CSUM_TYPE_BLAKE2:
|
||||
return hash_blake2b(data, len, out);
|
||||
default:
|
||||
fprintf(stderr, "ERROR: unknown csum type: %d\n", csum_type);
|
||||
ASSERT(0);
|
||||
|
|
|
@ -397,6 +397,9 @@ static enum btrfs_csum_type parse_csum_type(const char *s)
|
|||
return BTRFS_CSUM_TYPE_XXHASH;
|
||||
} else if (strcasecmp(s, "sha256") == 0) {
|
||||
return BTRFS_CSUM_TYPE_SHA256;
|
||||
} else if (strcasecmp(s, "blake2b") == 0 ||
|
||||
strcasecmp(s, "blake2") == 0) {
|
||||
return BTRFS_CSUM_TYPE_BLAKE2;
|
||||
} else {
|
||||
error("unknown csum type %s", s);
|
||||
exit(1);
|
||||
|
|
Loading…
Reference in New Issue