From patchwork Sun Oct 29 05:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1856664 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xYPQuYna; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Mw1IfVQZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SJ48c0D9Gz1yQ7 for ; Sun, 29 Oct 2023 16:04:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1iUrZYJAN/DzeOXesH51FDTJN7JudTrw7zt3/rY4k/s=; b=xYPQuYna5HeoYN 43cWhxwPtlgBaxOdLSGv/fPeDJGt8hfGHd+10eS46PVW2Bf+WNjtcq1Spft6mdw938OZ+/ewpbpMs kTqrN4CSCpknGY23uuURbgGp57pFkfHZJz9z1KHSW0vmEpbmCspOpfzkpHl2VCtoVUVC52cQRtiax KH64/WMw39s1tl+xFfCPL+Dv/1dIjG1nvZ9h9gwnYJl6LSXeok58UCJP9Go3g6istrXJolvy3VKBk CuXtcA/xzWwg1zX/lWfiOvSD+3nCb/L03FlYvtK0fR1U043AEnIj9M13cX0SepxBX0Kh/LA4R02tT spNWzPfC5BMdVvNFvyHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qwxyA-001CJZ-24; Sun, 29 Oct 2023 05:04:14 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qwxy5-001CJ3-3D for linux-mtd@lists.infradead.org; Sun, 29 Oct 2023 05:04:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 2FA37B8094F; Sun, 29 Oct 2023 05:04:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C751C433C7; Sun, 29 Oct 2023 05:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698555845; bh=Bd85Pl0HxDFyn+Xmq89TAE0x2+xo8OOJv3Wbz88xxEA=; h=From:To:Cc:Subject:Date:From; b=Mw1IfVQZiMp5BpDGgUt/tVQwmrsRmtydrP/mY+CD9xI+TnspAOs6HHsaKEdBaB97W Mzm57m4NaWDKJRdDI0Rh65r96MWyM0gFobkYFXPQfYKefodqAvJW9v8saGakPoAakL oFnyVVCqNetSd5falmLFuPW7gD/04tSmozJvE319Wqono21d9mEXhBC0nI5QdQW29Z q6ddAZvkQIiRDqk5JN6tsoRD1uuBxbbDgiBH/3vHXKCUx3rXjyzAyttUET8QsqfdJw fobRnFp1Qwd7gxrvtbgFwk/9+lq1hqCjrRkzUzt3mzFe+/KKsTa2Y7qR+0D2r6W3Cd 0q67pUFqmu5yQ== From: Eric Biggers To: Richard Weinberger , linux-mtd@lists.infradead.org Cc: linux-crypto@vger.kernel.org Subject: [PATCH] ubifs: use crypto_shash_tfm_digest() in ubifs_hmac_wkm() Date: Sat, 28 Oct 2023 22:03:55 -0700 Message-ID: <20231029050355.154989-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231028_220410_178070_9B5FD936 X-CRM114-Status: GOOD ( 12.43 ) X-Spam-Score: -2.7 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Eric Biggers Simplify ubifs_hmac_wkm() by using crypto_shash_tfm_digest() instead of an alloc+init+update+final sequence. This should also improve performance. Signed-off-by: Eric Biggers --- fs/ubifs/auth.c | 19 ++ 1 file changed, 2 insertions(+), 17 deletions(-) Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [145.40.68.75 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Eric Biggers Simplify ubifs_hmac_wkm() by using crypto_shash_tfm_digest() instead of an alloc+init+update+final sequence. This should also improve performance. Signed-off-by: Eric Biggers Tested-by: Zhihao Cheng --- fs/ubifs/auth.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c index e564d5ff8781..4add4a4f0720 100644 --- a/fs/ubifs/auth.c +++ b/fs/ubifs/auth.c @@ -501,42 +501,27 @@ int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src, * * This function creates a HMAC of a well known message. This is used * to check if the provided key is suitable to authenticate a UBIFS * image. This is only a convenience to the user to provide a better * error message when the wrong key is provided. * * This function returns 0 for success or a negative error code otherwise. */ int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac) { - SHASH_DESC_ON_STACK(shash, c->hmac_tfm); - int err; const char well_known_message[] = "UBIFS"; if (!ubifs_authenticated(c)) return 0; - shash->tfm = c->hmac_tfm; - - err = crypto_shash_init(shash); - if (err) - return err; - - err = crypto_shash_update(shash, well_known_message, - sizeof(well_known_message) - 1); - if (err < 0) - return err; - - err = crypto_shash_final(shash, hmac); - if (err) - return err; - return 0; + return crypto_shash_tfm_digest(c->hmac_tfm, well_known_message, + sizeof(well_known_message) - 1, hmac); } /* * ubifs_hmac_zero - test if a HMAC is zero * @c: UBIFS file-system description object * @hmac: the HMAC to test * * This function tests if a HMAC is zero and returns true if it is * and false otherwise. */