From patchwork Mon Dec 27 06:12:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 1573299 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=NNB2vv2g; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JMnQN0kS6z9sXV for ; Mon, 27 Dec 2021 17:12:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C1BDC837FC; Mon, 27 Dec 2021 07:12:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.b="NNB2vv2g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5193E83809; Mon, 27 Dec 2021 07:12:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2AE0A83800 for ; Mon, 27 Dec 2021 07:12:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=wqu@suse.com Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 01E2521116; Mon, 27 Dec 2021 06:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640585549; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I4DEIv18K1oCYX/XnmR6nLSwjz8erldQglFwlCLTnP8=; b=NNB2vv2gu5H9+NAkoeJao+GXvTupFhogSvF8ynHbSna8Rrc76YculQE1sJbGXNwZ/lWeJy cpPmTSSyTmjfntuALimka4BBD2d2xuH4tQAJBFmvo+fAD8CMOBSLcA9/FUnK15rO0QsmPx h0lrHfn9oBKevOm/aTqSK1XfVKr/IEA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0B2AE13491; Mon, 27 Dec 2021 06:12:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KPNeMEtZyWGfHgAAMHmgww (envelope-from ); Mon, 27 Dec 2021 06:12:27 +0000 From: Qu Wenruo To: u-boot@lists.denx.de Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] fs/btrfs: add dependency on BLAKE2 hash Date: Mon, 27 Dec 2021 14:12:08 +0800 Message-Id: <20211227061208.54497-2-wqu@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211227061208.54497-1-wqu@suse.com> References: <20211227061208.54497-1-wqu@suse.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Now btrfs can utilize the newly intorudced BLAKE2 hash. Signed-off-by: Qu Wenruo --- fs/btrfs/Kconfig | 1 + fs/btrfs/crypto/hash.c | 14 ++++++++++++++ fs/btrfs/crypto/hash.h | 1 + fs/btrfs/disk-io.c | 2 ++ 4 files changed, 18 insertions(+) diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig index a0b48c23b31a..e31afe595f31 100644 --- a/fs/btrfs/Kconfig +++ b/fs/btrfs/Kconfig @@ -6,6 +6,7 @@ config FS_BTRFS select ZSTD select RBTREE select SHA256 + select BLAKE2 help This provides a single-device read-only BTRFS support. BTRFS is a next-generation Linux file system based on the copy-on-write diff --git a/fs/btrfs/crypto/hash.c b/fs/btrfs/crypto/hash.c index fb51f6386cb1..891a2974be05 100644 --- a/fs/btrfs/crypto/hash.c +++ b/fs/btrfs/crypto/hash.c @@ -4,6 +4,7 @@ #include #include #include +#include #include static u32 btrfs_crc32c_table[256]; @@ -39,6 +40,19 @@ int hash_xxhash(const u8 *buf, size_t length, u8 *out) return 0; } +/* We use the full CSUM_SIZE(32) for BLAKE2B */ +#define BTRFS_BLAKE2_HASH_SIZE 32 +int hash_blake2(const u8 *buf, size_t length, u8 *out) +{ + blake2b_state S; + + blake2b_init(&S, BTRFS_BLAKE2_HASH_SIZE); + blake2b_update(&S, buf, length); + blake2b_final(&S, out, BTRFS_BLAKE2_HASH_SIZE); + + return 0; +} + int hash_crc32c(const u8 *buf, size_t length, u8 *out) { u32 crc; diff --git a/fs/btrfs/crypto/hash.h b/fs/btrfs/crypto/hash.h index d1ba1fa374e3..f9846038bfa3 100644 --- a/fs/btrfs/crypto/hash.h +++ b/fs/btrfs/crypto/hash.h @@ -9,6 +9,7 @@ void btrfs_hash_init(void); 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_blake2(const u8 *buf, size_t length, u8 *out); u32 crc32c(u32 seed, const void * data, size_t len); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index eb7736d53e11..8043abc1bd60 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -126,6 +126,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_blake2(data, len, out); default: printf("Unknown csum type %d\n", csum_type); return -EINVAL;