diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c index 47f56f78..fc06488d 100644 --- a/cmds/inspect-dump-super.c +++ b/cmds/inspect-dump-super.c @@ -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; diff --git a/crypto/hash.c b/crypto/hash.c index ee4c7f4e..48623c79 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -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; +} diff --git a/crypto/hash.h b/crypto/hash.h index 49d58654..fefccbd5 100644 --- a/crypto/hash.h +++ b/crypto/hash.h @@ -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 diff --git a/ctree.c b/ctree.c index 19052e8e..97b44d48 100644 --- a/ctree.c +++ b/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) diff --git a/ctree.h b/ctree.h index f7f7e296..b99ba112 100644 --- a/ctree.h +++ b/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 diff --git a/disk-io.c b/disk-io.c index 62ec8c1a..a9744af9 100644 --- a/disk-io.c +++ b/disk-io.c @@ -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); diff --git a/mkfs/main.c b/mkfs/main.c index 607cfe3e..1a457841 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -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);