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: sha1 - 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/sha1.c compatible with these legacy drivers
by adding export_core() and import_core() methods to it.

Reported-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reported-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Closes: https://lore.kernel.org/r/aLSnCc9Ws5L9y+8X@gcabiddu-mobl.ger.corp.intel.com
Fixes: b10a74abcfc5 ("crypto: sha1 - Use same state format as legacy drivers")
Tested-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Tested-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Link: https://lore.kernel.org/r/20250901165013.48649-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+39
+39
crypto/sha1.c
··· 49 49 return 0; 50 50 } 51 51 52 + static int __crypto_sha1_export_core(const struct sha1_ctx *ctx, void *out) 53 + { 54 + memcpy(out, ctx, offsetof(struct sha1_ctx, buf)); 55 + return 0; 56 + } 57 + 58 + static int __crypto_sha1_import_core(struct sha1_ctx *ctx, const void *in) 59 + { 60 + memcpy(ctx, in, offsetof(struct sha1_ctx, buf)); 61 + return 0; 62 + } 63 + 52 64 const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = { 53 65 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 54 66 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, ··· 104 92 static int crypto_sha1_import(struct shash_desc *desc, const void *in) 105 93 { 106 94 return __crypto_sha1_import(SHA1_CTX(desc), in); 95 + } 96 + 97 + static int crypto_sha1_export_core(struct shash_desc *desc, void *out) 98 + { 99 + return __crypto_sha1_export_core(SHA1_CTX(desc), out); 100 + } 101 + 102 + static int crypto_sha1_import_core(struct shash_desc *desc, const void *in) 103 + { 104 + return __crypto_sha1_import_core(SHA1_CTX(desc), in); 107 105 } 108 106 109 107 #define HMAC_SHA1_KEY(tfm) ((struct hmac_sha1_key *)crypto_shash_ctx(tfm)) ··· 165 143 return __crypto_sha1_import(&ctx->sha_ctx, in); 166 144 } 167 145 146 + static int crypto_hmac_sha1_export_core(struct shash_desc *desc, void *out) 147 + { 148 + return __crypto_sha1_export_core(&HMAC_SHA1_CTX(desc)->sha_ctx, out); 149 + } 150 + 151 + static int crypto_hmac_sha1_import_core(struct shash_desc *desc, const void *in) 152 + { 153 + struct hmac_sha1_ctx *ctx = HMAC_SHA1_CTX(desc); 154 + 155 + ctx->ostate = HMAC_SHA1_KEY(desc->tfm)->ostate; 156 + return __crypto_sha1_import_core(&ctx->sha_ctx, in); 157 + } 158 + 168 159 static struct shash_alg algs[] = { 169 160 { 170 161 .base.cra_name = "sha1", ··· 192 157 .digest = crypto_sha1_digest, 193 158 .export = crypto_sha1_export, 194 159 .import = crypto_sha1_import, 160 + .export_core = crypto_sha1_export_core, 161 + .import_core = crypto_sha1_import_core, 195 162 .descsize = sizeof(struct sha1_ctx), 196 163 .statesize = SHA1_SHASH_STATE_SIZE, 197 164 }, ··· 212 175 .digest = crypto_hmac_sha1_digest, 213 176 .export = crypto_hmac_sha1_export, 214 177 .import = crypto_hmac_sha1_import, 178 + .export_core = crypto_hmac_sha1_export_core, 179 + .import_core = crypto_hmac_sha1_import_core, 215 180 .descsize = sizeof(struct hmac_sha1_ctx), 216 181 .statesize = SHA1_SHASH_STATE_SIZE, 217 182 },