public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 3/4] btrfs-progs: add blake2b support
Date: Mon, 21 Oct 2019 18:45:23 +0200	[thread overview]
Message-ID: <20191021164523.15210-1-dsterba@suse.com> (raw)
In-Reply-To: <cover.1571674940.git.dsterba@suse.com>

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>
---
 cmds/inspect-dump-super.c |  1 +
 crypto/hash.c             | 12 ++++++++++++
 crypto/hash.h             |  1 +
 ctree.c                   |  1 +
 ctree.h                   |  1 +
 disk-io.c                 |  2 ++
 mkfs/main.c               |  3 +++
 7 files changed, 21 insertions(+)

diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
index 47f56f78934f..fc06488dde32 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 ee4c7f4e7112..48623c798739 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 49d586541af9..fefccbd59a09 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 19052e8ec128..97b44d48dc85 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 f7f7e2963b0e..b99ba11279ad 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 62ec8c1a84bf..a9744af90a43 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 607cfe3e0cf5..1a4578412b41 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);
-- 
2.23.0


      parent reply	other threads:[~2019-10-21 16:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 16:45 [PATCH 0/2 + 0/2] Add BLAKE2 checksumming support David Sterba
2019-10-21 16:45 ` [PATCH 1/2] btrfs: add member for a specific checksum driver David Sterba
2019-10-21 16:45 ` [PATCH 2/2] btrfs: add blake2b to checksumming algorithms David Sterba
2019-10-21 16:45 ` [PATCH 3/4] btrfs-progs: add blake2b reference implementation David Sterba
2019-10-21 16:45 ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191021164523.15210-1-dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox