Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: md5 - Implement export_core() and import_core()

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")
Link: https://lore.kernel.org/r/20250906215417.89584-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+39
+39
crypto/md5.c
··· 46 46 return 0; 47 47 } 48 48 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 + 49 61 const u8 md5_zero_message_hash[MD5_DIGEST_SIZE] = { 50 62 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 51 63 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e, ··· 100 88 static int crypto_md5_import(struct shash_desc *desc, const void *in) 101 89 { 102 90 return __crypto_md5_import(MD5_CTX(desc), in); 91 + } 92 + 93 + static int crypto_md5_export_core(struct shash_desc *desc, void *out) 94 + { 95 + return __crypto_md5_export_core(MD5_CTX(desc), out); 96 + } 97 + 98 + static int crypto_md5_import_core(struct shash_desc *desc, const void *in) 99 + { 100 + return __crypto_md5_import_core(MD5_CTX(desc), in); 103 101 } 104 102 105 103 #define HMAC_MD5_KEY(tfm) ((struct hmac_md5_key *)crypto_shash_ctx(tfm)) ··· 161 139 return __crypto_md5_import(&ctx->hash_ctx, in); 162 140 } 163 141 142 + static int crypto_hmac_md5_export_core(struct shash_desc *desc, void *out) 143 + { 144 + return __crypto_md5_export_core(&HMAC_MD5_CTX(desc)->hash_ctx, out); 145 + } 146 + 147 + static int crypto_hmac_md5_import_core(struct shash_desc *desc, const void *in) 148 + { 149 + struct hmac_md5_ctx *ctx = HMAC_MD5_CTX(desc); 150 + 151 + ctx->ostate = HMAC_MD5_KEY(desc->tfm)->ostate; 152 + return __crypto_md5_import_core(&ctx->hash_ctx, in); 153 + } 154 + 164 155 static struct shash_alg algs[] = { 165 156 { 166 157 .base.cra_name = "md5", ··· 188 153 .digest = crypto_md5_digest, 189 154 .export = crypto_md5_export, 190 155 .import = crypto_md5_import, 156 + .export_core = crypto_md5_export_core, 157 + .import_core = crypto_md5_import_core, 191 158 .descsize = sizeof(struct md5_ctx), 192 159 .statesize = MD5_SHASH_STATE_SIZE, 193 160 }, ··· 208 171 .digest = crypto_hmac_md5_digest, 209 172 .export = crypto_hmac_md5_export, 210 173 .import = crypto_hmac_md5_import, 174 + .export_core = crypto_hmac_md5_export_core, 175 + .import_core = crypto_hmac_md5_import_core, 211 176 .descsize = sizeof(struct hmac_md5_ctx), 212 177 .statesize = MD5_SHASH_STATE_SIZE, 213 178 },