From: Eric Biggers <ebiggers@kernel.org> To: Richard Weinberger <richard@nod.at>, 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 [thread overview] Message-ID: <20231029050355.154989-1-ebiggers@kernel.org> (raw) From: Eric Biggers <ebiggers@google.com> 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 <ebiggers@google.com> --- fs/ubifs/auth.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) 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. */ base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e -- 2.42.0
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org> To: Richard Weinberger <richard@nod.at>, 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 [thread overview] Message-ID: <20231029050355.154989-1-ebiggers@kernel.org> (raw) From: Eric Biggers <ebiggers@google.com> 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 <ebiggers@google.com> --- fs/ubifs/auth.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) 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. */ base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e -- 2.42.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2023-10-29 5:04 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-29 5:03 Eric Biggers [this message] 2023-10-29 5:03 ` [PATCH] ubifs: use crypto_shash_tfm_digest() in ubifs_hmac_wkm() Eric Biggers 2023-10-31 4:11 ` Zhihao Cheng 2023-10-31 4:11 ` Zhihao Cheng
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=20231029050355.154989-1-ebiggers@kernel.org \ --to=ebiggers@kernel.org \ --cc=linux-crypto@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=richard@nod.at \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.