All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH] crypto: md5 - Implement export_core() and import_core()
Date: Sat,  6 Sep 2025 14:54:17 -0700	[thread overview]
Message-ID: <20250906215417.89584-1-ebiggers@kernel.org> (raw)

Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in
API"), the recently-added export_core() and import_core() methods in
struct shash_alg have effectively become mandatory (even though it is
not tested or enforced), since legacy drivers that need a fallback
depend on them.  Make crypto/md5.c compatible with these legacy drivers
by adding export_core() and import_core() methods to it.

Fixes: ba8ee22a7f92 ("crypto: md5 - Wrap library and add HMAC support")
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---

This patch is targeting libcrypto-next

 crypto/md5.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/crypto/md5.c b/crypto/md5.c
index d05c53e6f3c2c..c167d203c710a 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -44,10 +44,22 @@ static int __crypto_md5_import(struct md5_ctx *ctx, const void *in)
 	p += sizeof(*ctx);
 	ctx->bytecount += *p;
 	return 0;
 }
 
+static int __crypto_md5_export_core(const struct md5_ctx *ctx, void *out)
+{
+	memcpy(out, ctx, offsetof(struct md5_ctx, buf));
+	return 0;
+}
+
+static int __crypto_md5_import_core(struct md5_ctx *ctx, const void *in)
+{
+	memcpy(ctx, in, offsetof(struct md5_ctx, buf));
+	return 0;
+}
+
 const u8 md5_zero_message_hash[MD5_DIGEST_SIZE] = {
 	0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
 	0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e,
 };
 EXPORT_SYMBOL_GPL(md5_zero_message_hash);
@@ -88,10 +100,20 @@ static int crypto_md5_export(struct shash_desc *desc, void *out)
 static int crypto_md5_import(struct shash_desc *desc, const void *in)
 {
 	return __crypto_md5_import(MD5_CTX(desc), in);
 }
 
+static int crypto_md5_export_core(struct shash_desc *desc, void *out)
+{
+	return __crypto_md5_export_core(MD5_CTX(desc), out);
+}
+
+static int crypto_md5_import_core(struct shash_desc *desc, const void *in)
+{
+	return __crypto_md5_import_core(MD5_CTX(desc), in);
+}
+
 #define HMAC_MD5_KEY(tfm) ((struct hmac_md5_key *)crypto_shash_ctx(tfm))
 #define HMAC_MD5_CTX(desc) ((struct hmac_md5_ctx *)shash_desc_ctx(desc))
 
 static int crypto_hmac_md5_setkey(struct crypto_shash *tfm,
 				  const u8 *raw_key, unsigned int keylen)
@@ -137,10 +159,23 @@ static int crypto_hmac_md5_import(struct shash_desc *desc, const void *in)
 
 	ctx->ostate = HMAC_MD5_KEY(desc->tfm)->ostate;
 	return __crypto_md5_import(&ctx->hash_ctx, in);
 }
 
+static int crypto_hmac_md5_export_core(struct shash_desc *desc, void *out)
+{
+	return __crypto_md5_export_core(&HMAC_MD5_CTX(desc)->hash_ctx, out);
+}
+
+static int crypto_hmac_md5_import_core(struct shash_desc *desc, const void *in)
+{
+	struct hmac_md5_ctx *ctx = HMAC_MD5_CTX(desc);
+
+	ctx->ostate = HMAC_MD5_KEY(desc->tfm)->ostate;
+	return __crypto_md5_import_core(&ctx->hash_ctx, in);
+}
+
 static struct shash_alg algs[] = {
 	{
 		.base.cra_name		= "md5",
 		.base.cra_driver_name	= "md5-lib",
 		.base.cra_priority	= 300,
@@ -151,10 +186,12 @@ static struct shash_alg algs[] = {
 		.update			= crypto_md5_update,
 		.final			= crypto_md5_final,
 		.digest			= crypto_md5_digest,
 		.export			= crypto_md5_export,
 		.import			= crypto_md5_import,
+		.export_core		= crypto_md5_export_core,
+		.import_core		= crypto_md5_import_core,
 		.descsize		= sizeof(struct md5_ctx),
 		.statesize		= MD5_SHASH_STATE_SIZE,
 	},
 	{
 		.base.cra_name		= "hmac(md5)",
@@ -169,10 +206,12 @@ static struct shash_alg algs[] = {
 		.update			= crypto_hmac_md5_update,
 		.final			= crypto_hmac_md5_final,
 		.digest			= crypto_hmac_md5_digest,
 		.export			= crypto_hmac_md5_export,
 		.import			= crypto_hmac_md5_import,
+		.export_core		= crypto_hmac_md5_export_core,
+		.import_core		= crypto_hmac_md5_import_core,
 		.descsize		= sizeof(struct hmac_md5_ctx),
 		.statesize		= MD5_SHASH_STATE_SIZE,
 	},
 };
 

base-commit: 8d2702c5dc96bc441879b83becbccedeb2bd4476
-- 
2.50.1


             reply	other threads:[~2025-09-06 21:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-06 21:54 Eric Biggers [this message]
2025-09-15 16:21 ` [PATCH] crypto: md5 - Implement export_core() and import_core() Eric Biggers

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=20250906215417.89584-1-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@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 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.