Skip to content

Commit b94bc43

Browse files
author
Eric Biggers
committed
crypto: md5 - Implement export_core() and import_core()
Since commit 9d7a0ab ("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: ba8ee22 ("crypto: md5 - Wrap library and add HMAC support") Link: https://lore.kernel.org/r/20250906215417.89584-1-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 54e7bb6 commit b94bc43

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

crypto/md5.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ static int __crypto_md5_import(struct md5_ctx *ctx, const void *in)
4646
return 0;
4747
}
4848

49+
static int __crypto_md5_export_core(const struct md5_ctx *ctx, void *out)
50+
{
51+
memcpy(out, ctx, offsetof(struct md5_ctx, buf));
52+
return 0;
53+
}
54+
55+
static int __crypto_md5_import_core(struct md5_ctx *ctx, const void *in)
56+
{
57+
memcpy(ctx, in, offsetof(struct md5_ctx, buf));
58+
return 0;
59+
}
60+
4961
const u8 md5_zero_message_hash[MD5_DIGEST_SIZE] = {
5062
0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
5163
0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e,
@@ -90,6 +102,16 @@ static int crypto_md5_import(struct shash_desc *desc, const void *in)
90102
return __crypto_md5_import(MD5_CTX(desc), in);
91103
}
92104

105+
static int crypto_md5_export_core(struct shash_desc *desc, void *out)
106+
{
107+
return __crypto_md5_export_core(MD5_CTX(desc), out);
108+
}
109+
110+
static int crypto_md5_import_core(struct shash_desc *desc, const void *in)
111+
{
112+
return __crypto_md5_import_core(MD5_CTX(desc), in);
113+
}
114+
93115
#define HMAC_MD5_KEY(tfm) ((struct hmac_md5_key *)crypto_shash_ctx(tfm))
94116
#define HMAC_MD5_CTX(desc) ((struct hmac_md5_ctx *)shash_desc_ctx(desc))
95117

@@ -139,6 +161,19 @@ static int crypto_hmac_md5_import(struct shash_desc *desc, const void *in)
139161
return __crypto_md5_import(&ctx->hash_ctx, in);
140162
}
141163

164+
static int crypto_hmac_md5_export_core(struct shash_desc *desc, void *out)
165+
{
166+
return __crypto_md5_export_core(&HMAC_MD5_CTX(desc)->hash_ctx, out);
167+
}
168+
169+
static int crypto_hmac_md5_import_core(struct shash_desc *desc, const void *in)
170+
{
171+
struct hmac_md5_ctx *ctx = HMAC_MD5_CTX(desc);
172+
173+
ctx->ostate = HMAC_MD5_KEY(desc->tfm)->ostate;
174+
return __crypto_md5_import_core(&ctx->hash_ctx, in);
175+
}
176+
142177
static struct shash_alg algs[] = {
143178
{
144179
.base.cra_name = "md5",
@@ -153,6 +188,8 @@ static struct shash_alg algs[] = {
153188
.digest = crypto_md5_digest,
154189
.export = crypto_md5_export,
155190
.import = crypto_md5_import,
191+
.export_core = crypto_md5_export_core,
192+
.import_core = crypto_md5_import_core,
156193
.descsize = sizeof(struct md5_ctx),
157194
.statesize = MD5_SHASH_STATE_SIZE,
158195
},
@@ -171,6 +208,8 @@ static struct shash_alg algs[] = {
171208
.digest = crypto_hmac_md5_digest,
172209
.export = crypto_hmac_md5_export,
173210
.import = crypto_hmac_md5_import,
211+
.export_core = crypto_hmac_md5_export_core,
212+
.import_core = crypto_hmac_md5_import_core,
174213
.descsize = sizeof(struct hmac_md5_ctx),
175214
.statesize = MD5_SHASH_STATE_SIZE,
176215
},

0 commit comments

Comments
 (0)